I'm making an app that updates the UI through the runOnUiThread(Runnable) method. It is very important that this UI thread continues to run as long as the user has this app running, even when onPause(). However, I've realized that when the screen is locked, Android stops the UI thread; and I don't blame them, it's probably to save battery life. But I want to know if there is a way to override this and tell the activity or the system to keep running the UI thread.
Asked
Active
Viewed 5,838 times
1 Answers
5
I would rather run your code as a Service, and hook it to the Activity having the UI through bindService.
The other option you have, is to create a WakeLock and maintain the phone on all the time. It may be very hard to the battery, though.
Check the dev guide entry for bound services and see if it fits your design: http://developer.android.com/guide/topics/fundamentals/bound-services.html
There are many very good tutorials out there for running services, with varying degrees of complexity. Take a look at some of them here:

Aleadam
- 40,203
- 9
- 86
- 108
-
Could you briefly describe to me what I should be doing with this Bind Service thing? I've read the documentation but I don't know where to begin. Thanks for posting this by the way. – Brian May 15 '11 at 07:04
-
@AeroDroid you basically run the code you had in your run method on a different service class instead, separating the ui from the code behind it. Check the examples I added above, they are much better than me at explaining how it works. – Aleadam May 15 '11 at 17:26