问题
Lets us say, we start some threads from the main UI thread. Now suppose the activity gets stopped or destroyed.
onClick () { /* Activity onClickListener for some button */
new Thread (new MyThread (new Handler ())).start ();
}
private class MyThread implements Runnable {
Handler mUIHandler;
MyThread (Handler h) {
mUIHandler = h;
}
public void run () {
/* Long operation */
/* Post status update to UI */
Message msg = mUIHandler.obtainMessage ();
msg.obj = String.valueOf (statusCode);
mUIHandler.sendMessage (msg);
}
1) What would happen to those threads ?
2) From those threads, suppose I would br posting some messages to the UI thread using the UI thread Handler object, What would happen to those UI updates then?
来源:https://stackoverflow.com/questions/31134861/background-thread-state-when-activity-is-stopped-or-destroyed