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

后端 未结 5 1930
独厮守ぢ
独厮守ぢ 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:23

    The HandlerThread is stopped when the Looper is quitted. HandlerThread.getLooper().quit() when you stop your activity. (see http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/2.2_r1.1/android/app/IntentService.java#IntentService.ServiceHandler.%3Cinit%3E%28android.os.Looper%29 for a good example of a proper HandlerThread use)

提交回复
热议问题