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?
Asked
Active
Viewed 250 times
2
-
you mean if its sleeping? the ui thread is the main thread that your application starts in. – L7ColWinters Jan 27 '12 at 06:00
-
no i need to know whether that activity is still running or not – Jram Jan 27 '12 at 06:07
-
i think if you will access through runOnUIThread,it will work anytime. – Android Killer Jan 27 '12 at 06:10
2 Answers
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.
-
how do you use the second method , meaning get running tasks and check if the activity is running? – android developer Jun 12 '12 at 21:27
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