我已经实现了PreferenceFragment,我用它来处理用户首选项。
问题是当我按下设备的后退按钮时应用程序崩溃。 我使用相同的方法来加载我的片段,但onBackPressed使活动崩溃。
FragmentSettings settings = new FragmentSettings();
ft.replace(R.id.container, settings);
ft.addToBackStack("settings");
ft.commit();
以下是崩溃日志:
12-26 09:53:54.351: E/InputEventSender(565): Exception dispatching finished signal.
12-26 09:53:54.351: E/MessageQueue-JNI(565): Exception in MessageQueue callback: handleReceiveCallback
12-26 09:53:54.421: E/MessageQueue-JNI(565): android.util.SuperNotCalledException: Fragment FragmentSettings{421d3d10 #1 id=0x7f0a0000} did not call through to super.onPause()
12-26 09:53:54.421: E/MessageQueue-JNI(565): at android.app.Fragment.performPause(Fragment.java:1861)
12-26 09:53:54.421: E/MessageQueue-JNI(565): at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:935)
12-26 09:53:54.421: E/MessageQueue-JNI(565): at android.app.FragmentManagerImpl.removeFragment(FragmentManager.java:1167)
12-26 09:53:54.421: E/MessageQueue-JNI(565): at android.app.BackStackRecord.popFromBackStack(BackStackRecord.java:717)
12-26 09:53:54.421: E/MessageQueue-JNI(565): at android.app.FragmentManagerImpl.popBackStackState(FragmentManager.java:1502)
12-26 09:53:54.421: E/MessageQueue-JNI(565): at android.app.FragmentManagerImpl.popBackStackImmediate(FragmentManager.java:495)
12-26 09:53:54.421: E/MessageQueue-JNI(565): at android.app.Activity.onBackPressed(Activity.java:2318)
12-26 09:53:54.421: E/MessageQueue-JNI(565): at android.app.Activity.onKeyUp(Activity.java:2295)
12-26 09:53:54.421: E/MessageQueue-JNI(565): at android.view.KeyEvent.dispatch(KeyEvent.java:3197)
12-26 09:53:54.421: E/MessageQueue-JNI(565): at android.app.Activity.dispatchKeyEvent(Activity.java:2529)
12-26 09:53:54.421: E/MessageQueue-JNI(565): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchKeyEvent(PhoneWindow.java:2181)
12-26 09:53:54.421: E/MessageQueue-JNI(565): at android.view.ViewRootImpl$ViewPostImeInputStage.processKeyEvent(ViewRootImpl.java:4670)
12-26 09:53:54.421: E/MessageQueue-JNI(565): at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:4637)
12-26 09:53:54.421: E/MessageQueue-JNI(565): at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4202)
12-26 09:53:54.421: E/MessageQueue-JNI(565): at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4256)
12-26 09:53:54.421: E/MessageQueue-JNI(565): at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4225)
12-26 09:53:54.421: E/MessageQueue-JNI(565): at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:4336)
12-26 09:53:54.421: E/MessageQueue-JNI(565): at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4233)
12-26 09:53:54.421: E/MessageQueue-JNI(565): at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:4393)
12-26 09:53:54.421: E/MessageQueue-JNI(565): at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4202)
12-26 09:53:54.421: E/MessageQueue-JNI(565): at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4256)
12-26 09:53:54.421: E/MessageQueue-JNI(565): at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4225)
12-26 09:53:54.421: E/MessageQueue-JNI(565): at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4233)
12-26 09:53:54.421: E/MessageQueue-JNI(565): at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4202)
12-26 09:53:54.421: E/MessageQueue-JNI(565): at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4256)
12-26 09:53:54.421: E/MessageQueue-JNI(565): at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4225)
12-26 09:53:54.421: E/MessageQueue-JNI(565): at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:4369)
12-26 09:53:54.421: E/MessageQueue-JNI(565): at android.view.ViewRootImpl$ImeInputStage.onFinishedInputEvent(ViewRootImpl.java:4529)
12-26 09:53:54.421: E/MessageQueue-JNI(565): at android.view.inputmethod.InputMethodManager$PendingEvent.run(InputMethodManager.java:2215)
12-26 09:53:54.421: E/MessageQueue-JNI(565): at android.view.inputmethod.InputMethodManager.invokeFinishedInputEventCallback(InputMethodManager.java:1863)
12-26 09:53:54.421: E/MessageQueue-JNI(565): at android.view.inputmethod.InputMethodManager.finishedInputEvent(InputMethodManager.java:1854)
12-26 09:53:54.421: E/MessageQueue-JNI(565): at android.view.inputmethod.InputMethodManager$ImeInputEventSender.onInputEventFinished(InputMethodManager.java:2192)
12-26 09:53:54.421: E/MessageQueue-JNI(565): at android.view.InputEventSender.dispatchInputEventFinished(InputEventSender.java:141)
12-26 09:53:54.421: E/MessageQueue-JNI(565): at android.os.MessageQueue.nativePollOnce(Native Method)
12-26 09:53:54.421: E/MessageQueue-JNI(565): at android.os.MessageQueue.next(MessageQueue.java:138)
12-26 09:53:54.421: E/MessageQueue-JNI(565): at android.os.Looper.loop(Looper.java:131)
12-26 09:53:54.421: E/MessageQueue-JNI(565): at android.app.ActivityThread.main(ActivityThread.java:5602)
12-26 09:53:54.421: E/MessageQueue-JNI(565): at java.lang.reflect.Method.invokeNative(Native Method)
12-26 09:53:54.421: E/MessageQueue-JNI(565): at java.lang.reflect.Method.invoke(Method.java:515)
12-26 09:53:54.421: E/MessageQueue-JNI(565): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
12-26 09:53:54.421: E/MessageQueue-JNI(565): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
12-26 09:53:54.421: E/MessageQueue-JNI(565): at dalvik.system.NativeStart.main(Native Method)
然后:
12-26 09:56:06.561: D/AndroidRuntime(565): Shutting down VM
12-26 09:56:06.561: W/dalvikvm(565): threadid=1: thread exiting with uncaught exception (group=0x4194dc08)
12-26 09:56:06.651: E/AndroidRuntime(565): FATAL EXCEPTION: main
12-26 09:56:06.651: E/AndroidRuntime(565): Process: com.soclip.views, PID: 565
12-26 09:56:06.651: E/AndroidRuntime(565): android.util.SuperNotCalledException: Fragment FragmentSettings{421d3d10 #1 id=0x7f0a0000} did not call through to super.onPause()
12-26 09:56:06.651: E/AndroidRuntime(565): at android.app.Fragment.performPause(Fragment.java:1861)
12-26 09:56:06.651: E/AndroidRuntime(565): at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:935)
12-26 09:56:06.651: E/AndroidRuntime(565): at android.app.FragmentManagerImpl.removeFragment(FragmentManager.java:1167)
12-26 09:56:06.651: E/AndroidRuntime(565): at android.app.BackStackRecord.popFromBackStack(BackStackRecord.java:717)
12-26 09:56:06.651: E/AndroidRuntime(565): at android.app.FragmentManagerImpl.popBackStackState(FragmentManager.java:1502)
12-26 09:56:06.651: E/AndroidRuntime(565): at android.app.FragmentManagerImpl.popBackStackImmediate(FragmentManager.java:495)
12-26 09:56:06.651: E/AndroidRuntime(565): at android.app.Activity.onBackPressed(Activity.java:2318)
12-26 09:56:06.651: E/AndroidRuntime(565): at android.app.Activity.onKeyUp(Activity.java:2295)
12-26 09:56:06.651: E/AndroidRuntime(565): at android.view.KeyEvent.dispatch(KeyEvent.java:3197)
12-26 09:56:06.651: E/AndroidRuntime(565): at android.app.Activity.dispatchKeyEvent(Activity.java:2529)
12-26 09:56:06.651: E/AndroidRuntime(565): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchKeyEvent(PhoneWindow.java:2181)
12-26 09:56:06.651: E/AndroidRuntime(565): at android.view.ViewRootImpl$ViewPostImeInputStage.processKeyEvent(ViewRootImpl.java:4670)
12-26 09:56:06.651: E/AndroidRuntime(565): at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:4637)
12-26 09:56:06.651: E/AndroidRuntime(565): at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4202)
12-26 09:56:06.651: E/AndroidRuntime(565): at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4256)
12-26 09:56:06.651: E/AndroidRuntime(565): at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4225)
12-26 09:56:06.651: E/AndroidRuntime(565): at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:4336)
12-26 09:56:06.651: E/AndroidRuntime(565): at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4233)
12-26 09:56:06.651: E/AndroidRuntime(565): at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:4393)
12-26 09:56:06.651: E/AndroidRuntime(565): at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4202)
12-26 09:56:06.651: E/AndroidRuntime(565): at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4256)
12-26 09:56:06.651: E/AndroidRuntime(565): at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4225)
12-26 09:56:06.651: E/AndroidRuntime(565): at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4233)
12-26 09:56:06.651: E/AndroidRuntime(565): at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4202)
12-26 09:56:06.651: E/AndroidRuntime(565): at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4256)
12-26 09:56:06.651: E/AndroidRuntime(565): at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4225)
12-26 09:56:06.651: E/AndroidRuntime(565): at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:4369)
12-26 09:56:06.651: E/AndroidRuntime(565): at android.view.ViewRootImpl$ImeInputStage.onFinishedInputEvent(ViewRootImpl.java:4529)
12-26 09:56:06.651: E/AndroidRuntime(565): at android.view.inputmethod.InputMethodManager$PendingEvent.run(InputMethodManager.java:2215)
12-26 09:56:06.651: E/AndroidRuntime(565): at android.view.inputmethod.InputMethodManager.invokeFinishedInputEventCallback(InputMethodManager.java:1863)
12-26 09:56:06.651: E/AndroidRuntime(565): at android.view.inputmethod.InputMethodManager.finishedInputEvent(InputMethodManager.java:1854)
12-26 09:56:06.651: E/AndroidRuntime(565): at android.view.inputmethod.InputMethodManager$ImeInputEventSender.onInputEventFinished(InputMethodManager.java:2192)
12-26 09:56:06.651: E/AndroidRuntime(565): at android.view.InputEventSender.dispatchInputEventFinished(InputEventSender.java:141)
12-26 09:56:06.651: E/AndroidRuntime(565): at android.os.MessageQueue.nativePollOnce(Native Method)
12-26 09:56:06.651: E/AndroidRuntime(565): at android.os.MessageQueue.next(MessageQueue.java:138)
12-26 09:56:06.651: E/AndroidRuntime(565): at android.os.Looper.loop(Looper.java:131)
12-26 09:56:06.651: E/AndroidRuntime(565): at android.app.ActivityThread.main(ActivityThread.java:5602)
12-26 09:56:06.651: E/AndroidRuntime(565): at java.lang.reflect.Method.invokeNative(Native Method)
12-26 09:56:06.651: E/AndroidRuntime(565): at java.lang.reflect.Method.invoke(Method.java:515)
12-26 09:56:06.651: E/AndroidRuntime(565): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
12-26 09:56:06.651: E/AndroidRuntime(565): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
12-26 09:56:06.651: E/AndroidRuntime(565): at dalvik.system.NativeStart.main(Native Method)
有任何帮助吗?谢谢。
答案 0 :(得分:0)
这部分日志错误
did not call through to super.onPause()
表示你的一个片段有onPause方法但忘记调用super.onPause();
检查你的片段onPause确实调用了super.onPause();
。这样的事情。
@Override
public void onPause() {
// code run before super
super.onPause(); // <-- the super
// code run after super
}