2

i am using threads to do few tasks. and after that i want to access the main thread via runOnUiThread(). but how to determine whether that ui thread still running or not?

Jram
  • 1,588
  • 1
  • 10
  • 7

2 Answers2

1

Two options are there one use a static boolean variable and see whether the activity is running or not, or you can check all the running tasks and determine whether your activity is running or not.

Community
  • 1
  • 1
manjusg
  • 2,275
  • 1
  • 22
  • 31
0

The only instance when your UI thread is not running is when your main thread has spawned a thread which needs to communicate with the UI thread and the non-UI thread has not been killed when the life of the context ends.

You must avoid a situation like this by interrupt()ing your threads in onStop() or onDestory() (whatever is appropriate).

After you've taken care of this, you can always safely assume that a runOnUiThread() call is appropriate.

Vikram Bodicherla
  • 7,133
  • 4
  • 28
  • 34
  • thank you for your input. due to the nature of the task which i am performing inside the thread, i need to complete it safely ,instead of breaking in the middle. – Jram Jan 27 '12 at 07:05