当与广播接收器关闭活动时强制关闭

时间:2014-08-12 08:07:36

标签: android service broadcastreceiver

我尝试关闭服务中的活动,它可以工作但是在那个力量关闭之后 这是我的活动代码:

onCreate{
registerReceiver(abcd, new IntentFilter("xyz"));
}

和这个

 private final BroadcastReceiver abcd = new BroadcastReceiver() {
         @Override
         public void onReceive(Context context, Intent intent) {
               finish();                                   
         }
 };

public void onDestroy() {

    unregisterReceiver(abcd);

}

这将关闭服务中的活动

sendBroadcast(new Intent("xyz"));

logcat的:

08-12 15:05:01.032: E/AndroidRuntime(6975): FATAL EXCEPTION: main 08-12 15:05:01.032: E/AndroidRuntime(6975): android.app.SuperNotCalledException: Activity {com.example.sservice/com.example.sservice.run_service} did not call through to super.onDestroy() 08-12 15:05:01.032: E/AndroidRuntime(6975): at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:3330) 08-12 15:05:01.032: E/AndroidRuntime(6975): at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:3359) 08-12 15:05:01.032: E/AndroidRuntime(6975): at android.app.ActivityThread.access$1300(ActivityThread.java:143) 08-12 15:05:01.032: E/AndroidRuntime(6975): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1294) 08-12 15:05:01.032: E/AndroidRuntime(6975): at android.os.Handler.dispatchMessage(Handler.java:99) 08-12 15:05:01.032: E/AndroidRuntime(6975): at android.os.Looper.loop(Looper.java:137) 08-12 15:05:01.032: E/AndroidRuntime(6975): at android.app.ActivityThread.main(ActivityThread.java:4963) 08-12 15:05:01.032: E/AndroidRuntime(6975): at java.lang.reflect.Method.invokeNative(Native Method) 08-12 15:05:01.032: E/AndroidRuntime(6975): at java.lang.reflect.Method.invoke(Method.java:511) 08-12 15:05:01.032: E/AndroidRuntime(6975): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038) 08-12 15:05:01.032: E/AndroidRuntime(6975): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805) 08-12 15:05:01.032: E/AndroidRuntime(6975): at dalvik.system.NativeStart.main(Native Method)

出了什么问题?请帮忙

1 个答案:

答案 0 :(得分:1)

覆盖onDestroy方法时需要调用super.onDestroy();