Weird “Receiver not registered” exception

前端 未结 5 729
耶瑟儿~
耶瑟儿~ 2021-01-03 19:22

In onResume() I do:

registerReceiver(timeTickReceiver, new IntentFilter(Intent.ACTION_TIME_TICK));

and in onPause():

unregi         


        
5条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-03 19:58

    I guess there may be some states where the receiver is not actually registered before e.g. a user exits the app.

    You might want to try adding a check for the receiver before running unregister, (I've done this in several cases):

    protected void onPause() {
      if(timeTickReceiver != null) {
        unregisterReceiver(timeTickReceiver);
      }
    }
    

提交回复
热议问题