Should I manually close HandlerThreads created by my application when destroying the activity?

后端 未结 5 1929
独厮守ぢ
独厮守ぢ 2021-02-20 02:49

My app is composed of a single Activity. In this activity, I\'m creating multiple HandlerThreads which run in a loop to do socket blocking operations.<

5条回答
  •  悲&欢浪女
    2021-02-20 03:09

    Yes, it would be a good idea to close it. Also make sure to remove your callbacks.

    @Override
    public void onDestroy() {
        super.onDestroy();
        handler.removeCallbacksAndMessages(null);
        handler.getLooper().quit();
    }
    

提交回复
热议问题