How UI Threading in android works?
If an app is brought to the background what happens to the UI Thread which was running this app?
Will it sleep or get killed?
When the app is back to foreground will the s开发者_开发百科ame thread be notified or a new thread will created and associated with the app instance?
I don't know specifically, but you should always program with the possibility that your Activity may be killed at any time that it is not in the foreground. Whether that involves killing the thread every time it enters the background, or causing the thread to sleep and then killing it if the Activity is killed, I don't know. In any case, you must assume it can and will happen, and program accordingly.
It depends on the memory situation. When your application goes into the background, it generally stays running initially. Android does not sleep your thread. It is up to you to stop updating your UI and performing calculations in on onPause
.
However in low memory situations Android might kill application when it's the background (especially if you haven't been nice and are using up a load of resources). For this reason you should always save any persistant data in onPause
.
精彩评论