0

I want to execute setContentView(R.layout.activity_main);

Android allows this to be done only from the main thread.

Drake
  • 13
  • 3
  • [runOnUIThread](https://developer.android.com/training/multiple-threads/communicate-ui) – tomerpacific Jun 28 '20 at 14:29
  • 3
    Can you show your code, the best way to add tasks for the main thread queue may depend on what the code is doing – Joni Jun 28 '20 at 14:31
  • 2
    Does this answer your question? [Run Callback On Main Thread](https://stackoverflow.com/questions/19366301/run-callback-on-main-thread) – Ryan M Jun 30 '20 at 01:54

1 Answers1

1

Yes, any UI rendering and actions would run only on MainThread as per Android official doc and other business logic can be done using worker threads.

  1. runOnUiThread to invoke UI stuff on MainThread.
  2. Use Handler to get the UI command to execute on MainThread
  • This is too trivial to be an answer. – 10 Rep Jun 28 '20 at 17:30
  • @10Rep: Thanks for the comment. True, it's because didn't get the question right. edited again after looking at it. – Seshadri Pera Jun 28 '20 at 17:42
  • Undid my downvote because it's not trivial. I am happy to see that some new users know how to be nice. Thank you. – 10 Rep Jun 28 '20 at 19:42
  • @10Rep: Thank you so much for the feedback and encouragement. New to this forum even though account has been created long back. Looking forward to answer and help on Android related questions as I have good experience on this topic. – Seshadri Pera Jun 29 '20 at 03:07