Background thread state when activity is stopped or destroyed

安稳与你 提交于 2019-12-23 02:36:46

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!