在我的应用程序中,我得到java.lang.IllegalStateException:onSaveInstanceState后无法执行此操作。在Activity的onBackPress()之后。java.lang.IllegalStateException:无法在onSaveInstanceState之后执行此操作On Activity Backpress(未使用任何片段)
Fatal Exception: java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState
at android.support.v4.app.FragmentManagerImpl.checkStateLoss(MyApplication:1533)
at android.support.v4.app.FragmentManagerImpl.popBackStackImmediate(MyApplication:603)
at android.support.v4.app.FragmentActivity.onBackPressed(MyApplication:179)
at com.app.mobile.views.NewsActivity.onBackPressed(MyApplication:301)
at com.app.mobile.views.NewsActivity.onOptionsItemSelected(MyApplication:293)
at android.app.Activity.onMenuItemSelected(Activity.java:2625)
at android.support.v4.app.FragmentActivity.onMenuItemSelected(MyApplication:406)
at android.support.v7.app.AppCompatActivity.onMenuItemSelected(MyApplication:195)
at android.support.v7.view.WindowCallbackWrapper.onMenuItemSelected(MyApplication:103)
at android.support.v7.view.WindowCallbackWrapper.onMenuItemSelected(MyApplication:103)
at android.support.v7.widget.ToolbarWidgetWrapper$1.onClick(MyApplication:183)
at android.view.View.performClick(View.java:4446)
at android.view.View$PerformClick.run(View.java:18437)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5447)
at java.lang.reflect.Method.invokeNative(Method.java)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:970)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:786)
at dalvik.system.NativeStart.main(NativeStart.java)
在我的活动中,我没有使用任何片段。我寻找解决方案,但只发现碎片。
在我的代码中。
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
onBackPressed();
return true;
}
return super.onOptionsItemSelected(item);
}
和
@Override
public void onBackPressed() {
super.onBackPressed();
if (screen_Name != 0 && screen_Name == Constants.TAG_WIDGET_SCREEN) {
int tagID = getIntent().getIntExtra(Constants.TAG_ID, -1);
int tagcount = getIntent().getIntExtra(Constants.TAG_COUNT, 0);
if (tagcount > 0) {
mDBAdapter.updateTagCountToZero(tagID);
}
PreferenceUtils.getInstance(NewsActivity.this).remove(Constants.NEWS + type);
PreferenceUtils.getInstance(NewsActivity.this).remove(Constants.CARD_PREF + cardPref);
}
}
在onSavedInstance
@Override
protected void onSaveInstanceState(Bundle outState) {
if (feedList != null && feedList.size() > 0) {
outState.putSerializable(FEED_DATA, feedList);
}
stopProgressBar(); // stopping progress dialog
super.onSaveInstanceState(outState);
}
请帮忙如何处理这种情况。
我只是随机猜测,但是你尝试在方法的末尾放置'''super.onBackPressed();'''也许这triggeres已经像onSaveInstanceState – Maximosaic
但这不是转载。这是实时apk。所以我不知道确切的原因。 –