如何销毁处理屏幕方向更改和键盘可用性更改的活动?

时间:2011-11-23 07:31:00

标签: android android-activity configuration

我正在处理后台线程和方向更改。我已经完成了这里给出的代码 https://stackoverflow.com/q/1512263以及其他一些帖子。

我使用“android:configChanges =”keyboardHidden | orientation“来处理屏幕方向更改。它工作正常但是当我想完成此活动时,它会被强制关闭,运行时异常并显示消息”无法销毁活动..” 有没有想过安全地完成我的活动?

日志输出为:

11-23 12:47:32.025: E/AndroidRuntime(438): Uncaught handler: thread main exiting due to uncaught exception
11-23 12:47:32.125: E/AndroidRuntime(438): java.lang.RuntimeException: Unable to destroy activity {com.FileBrowser/com.FileBrowser.mainScreenwithtab}: java.lang.IllegalArgumentException: Receiver not registered: com.FileBrowser.ScrollableTabActivity$ChangeTabBroadcastReceiver@44df87d8
11-23 12:47:32.125: E/AndroidRuntime(438):  at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:3469)
11-23 12:47:32.125: E/AndroidRuntime(438):  at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:3487)
11-23 12:47:32.125: E/AndroidRuntime(438):  at android.app.ActivityThread.access$2800(ActivityThread.java:119)
11-23 12:47:32.125: E/AndroidRuntime(438):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1896)
11-23 12:47:32.125: E/AndroidRuntime(438):  at android.os.Handler.dispatchMessage(Handler.java:99)
11-23 12:47:32.125: E/AndroidRuntime(438):  at android.os.Looper.loop(Looper.java:123)
11-23 12:47:32.125: E/AndroidRuntime(438):  at android.app.ActivityThread.main(ActivityThread.java:4363)
11-23 12:47:32.125: E/AndroidRuntime(438):  at java.lang.reflect.Method.invokeNative(Native Method)
11-23 12:47:32.125: E/AndroidRuntime(438):  at java.lang.reflect.Method.invoke(Method.java:521)
11-23 12:47:32.125: E/AndroidRuntime(438):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
11-23 12:47:32.125: E/AndroidRuntime(438):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
11-23 12:47:32.125: E/AndroidRuntime(438):  at dalvik.system.NativeStart.main(Native Method)
11-23 12:47:32.125: E/AndroidRuntime(438): Caused by: java.lang.IllegalArgumentException: Receiver not registered: com.FileBrowser.ScrollableTabActivity$ChangeTabBroadcastReceiver@44df87d8
11-23 12:47:32.125: E/AndroidRuntime(438):  at android.app.ActivityThread$PackageInfo.forgetReceiverDispatcher(ActivityThread.java:667)
11-23 12:47:32.125: E/AndroidRuntime(438):  at android.app.ApplicationContext.unregisterReceiver(ApplicationContext.java:747)
11-23 12:47:32.125: E/AndroidRuntime(438):  at android.content.ContextWrapper.unregisterReceiver(ContextWrapper.java:321)
11-23 12:47:32.125: E/AndroidRuntime(438):  at com.FileBrowser.ScrollableTabActivity.onDestroy(ScrollableTabActivity.java:120)
11-23 12:47:32.125: E/AndroidRuntime(438):  at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:3456)
11-23 12:47:32.125: E/AndroidRuntime(438):  ... 11 more

1 个答案:

答案 0 :(得分:1)

你不应该真正使用你正在使用的技术。我写了两篇关于此的博文:

Actvity and background threads (part 1)
Actvity and background threads (part 2)

但是由于引入了片段,现在处理后台线程的方法要简单得多:所谓的retained片段(参见示例here)。