Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/313.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 异步任务问题_Java_Android_Bluetooth - Fatal编程技术网

Java 异步任务问题

Java 异步任务问题,java,android,bluetooth,Java,Android,Bluetooth,异步任务实现在基于蓝牙的android应用程序中出现以下异常 异步任务的代码 例外情况 12-18 15:41:18.634: E/ActivityThread(23724): Activity com.example.vedangbluetoothlock.Bluetooth has leaked IntentReceiver com.example.vedangbluetoothlock.Bluetooth$1@42649300 that was originally registered

异步任务实现在基于蓝牙的android应用程序中出现以下异常

异步任务的代码

例外情况

12-18 15:41:18.634: E/ActivityThread(23724): Activity com.example.vedangbluetoothlock.Bluetooth has leaked IntentReceiver com.example.vedangbluetoothlock.Bluetooth$1@42649300 that was originally registered here. Are you missing a call to unregisterReceiver()?
12-18 15:41:18.634: E/ActivityThread(23724): android.app.IntentReceiverLeaked: Activity com.example.vedangbluetoothlock.Bluetooth has leaked IntentReceiver com.example.vedangbluetoothlock.Bluetooth$1@42649300 that was originally registered here. Are you missing a call to unregisterReceiver()?
12-18 15:41:18.634: E/ActivityThread(23724):       at android.app.LoadedApk$ReceiverDispatcher.<init>(LoadedApk.java:803)
12-18 15:41:18.634: E/ActivityThread(23724):       at android.app.LoadedApk.getReceiverDispatcher(LoadedApk.java:604)
12-18 15:41:18.634: E/ActivityThread(23724):       at android.app.ContextImpl.registerReceiverInternal(ContextImpl.java:1494)
12-18 15:41:18.634: E/ActivityThread(23724):       at android.app.ContextImpl.registerReceiver(ContextImpl.java:1474)
12-18 15:41:18.634: E/ActivityThread(23724):       at android.app.ContextImpl.registerReceiver(ContextImpl.java:1468)
12-18 15:41:18.634: E/ActivityThread(23724):       at android.content.ContextWrapper.registerReceiver(ContextWrapper.java:467)
12-18 15:41:18.634: E/ActivityThread(23724):       at com.example.vedangbluetoothlock.Bluetooth.onCreate(Bluetooth.java:90)
12-18 15:41:18.634: E/ActivityThread(23724):       at android.app.Activity.performCreate(Activity.java:5231)
12-18 15:41:18.634: E/ActivityThread(23724):       at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
12-18 15:41:18.634: E/ActivityThread(23724):       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2169)
12-18 15:41:18.634: E/ActivityThread(23724):       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2271)
12-18 15:41:18.634: E/ActivityThread(23724):       at android.app.ActivityThread.access$800(ActivityThread.java:144)
12-18 15:41:18.634: E/ActivityThread(23724):       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1205)
12-18 15:41:18.634: E/ActivityThread(23724):       at android.os.Handler.dispatchMessage(Handler.java:102)
12-18 15:41:18.634: E/ActivityThread(23724):       at android.os.Looper.loop(Looper.java:136)
12-18 15:41:18.634: E/ActivityThread(23724):       at android.app.ActivityThread.main(ActivityThread.java:5146)
12-18 15:41:18.634: E/ActivityThread(23724):       at java.lang.reflect.Method.invokeNative(Native Method)
12-18 15:41:18.634: E/ActivityThread(23724):       at java.lang.reflect.Method.invoke(Method.java:515)
12-18 15:41:18.634: E/ActivityThread(23724):       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:796)
12-18 15:41:18.634: E/ActivityThread(23724):       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:612)
12-18 15:41:18.634: E/ActivityThread(23724):       at dalvik.system.NativeStart.main(Native Method)

您需要在活动停止时注销收件人:

@Override
protected void onDestroy() {
   super.onDestroy();
   unregisterReceiver(yourReceiver);

}

问题在于异步任务。我应该在哪里调用它?将其更改为onDestroy,您应该可以将此方法放在主活动中,无需自己调用它。我已经有一个onDestroy函数@Override protected void onDestroy{//TODO自动生成的方法存根super.onDestroy;请尝试{unregisterReceiverbReceiver;//取消注册BroadcastReceiver,}捕获异常io{}
@Override
protected void onDestroy() {
   super.onDestroy();
   unregisterReceiver(yourReceiver);