破坏android之后接收器仍然无法工作

时间:2015-08-17 13:53:27

标签: android

当我销毁我的应用程序时,logcat向我显示了这个错误:

java.lang.RuntimeException: Unable to start receiver com.examples.android.calendar.AlarmReceiver: java.lang.NullPointerException

Caused by: java.lang.NullPointerException
        at com.examples.android.calendar.AlarmReceiver.onReceive(AlarmReceiver.java:20)

我按照这样注册我的接收器:

 @Override
protected void onDestroy() {
    super.onDestroy();
    try{
        unregisterReceiver(mReceiver);
    }catch(Exception e){
        Log.v("hhhhhhhhhhhhhhhhhhhhh", e.getMessage());
    }
}

 @Override
protected void onResume() {
    super.onResume();
    mReceiver = new AlarmReceiver();
    registerReceiver(
            this.mReceiver,
            new IntentFilter(
                    ConnectivityManager.CONNECTIVITY_ACTION));
}

0 个答案:

没有答案