本文介绍了获取例外,因为失败节能状态:活性片段已被清除指数:-1当我pressing家Android设备按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我面临着一些奇怪的问题,而我的机器人pressing Home键且在启动新的活动。
我的堆栈跟踪如下:
05-13 18:06:21.182:E / FragmentManager(5674):失败节能状态:活性片段{411d96d8}已清除指数:-1
05-13 18:06:21.182:E / FragmentManager(5674):活动状态:
05-13 18:06:22.032:E / ACRA(5674):ACRA抓到一个IllegalStateException异常例外com.itgurussoftware.android.dineback。大厦的报告。
05-13 18:06:27.732:E / ACRA(5674):com.itgurussoftware.android.dineback致命错误:失败节能状态:活性片段{411d96d8}已清除指数:-1
05-13 18:06:27.732:E / ACRA(5674):java.lang.IllegalStateException:失败节能状态:活性片段{411d96d8}已清除指数:-1
05-13 18:06:27.732:E / ACRA(5674):在android.support.v4.app.FragmentManagerImpl.saveAllState(FragmentManager.java:1723)
05-13 18:06:27.732:E / ACRA(5674):在android.support.v4.app.FragmentActivity.onSaveInstanceState(FragmentActivity.java:546)
05-13 18:06:27.732:E / ACRA(5674):在android.app.Activity.performSaveInstanceState(Activity.java:1113)
05-13 18:06:27.732:E / ACRA(5674):在android.app.Instrumentation.callActivityOnSaveInstanceState(Instrumentation.java:1185)
05-13 18:06:27.732:E / ACRA(5674):在android.app.ActivityThread.performStopActivityInner(ActivityThread.java:2793)
05-13 18:06:27.732:E / ACRA(5674):在android.app.ActivityThread.handleStopActivity(ActivityThread.java:2851)
05-13 18:06:27.732:E / ACRA(5674):在android.app.ActivityThread.access $ 900(ActivityThread.java:123)
05-13 18:06:27.732:E / ACRA(5674):在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1164)
05-13 18:06:27.732:E / ACRA(5674):在android.os.Handler.dispatchMessage(Handler.java:99)
05-13 18:06:27.732:E / ACRA(5674):在android.os.Looper.loop(Looper.java:137)
05-13 18:06:27.732:E / ACRA(5674):在android.app.ActivityThread.main(ActivityThread.java:4424)
05-13 18:06:27.732:E / ACRA(5674):在java.lang.reflect.Method.invokeNative(本机方法)
05-13 18:06:27.732:E / ACRA(5674):在java.lang.reflect.Method.invoke(Method.java:511)
05-13 18:06:27.732:E / ACRA(5674):在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:784)
05-13 18:06:27.732:E / ACRA(5674):在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
05-13 18:06:27.732:E / ACRA(5674):在dalvik.system.NativeStart.main(本机方法)
和我的code添加和删除片段如下:
FragmentContainer fragContainer = container.get(container.size() - 1);
片段片段= fragContainer.getFragment();
字符串变量= fragContainer.getTabName();
FragmentManager经理= getSupportFragmentManager();
FragmentTransaction英尺= manager.beginTransaction();
mTabHost.setCurrentTabByTag(标签);
如果(!fragment.isAdded()){
ft.remove(片段);
}
如果(container.size()大于0)
container.remove(container.size() - 1);
ft.replace(R.id.realtabcontent,片段);
ft.commitAllowingStateLoss();
尝试
- 更新支持库
-
试了重写的onSaveInstanceState为
@覆盖 保护无效的onSaveInstanceState(包outState){ // TODO自动生成方法存根 如果(outState!= NULL){ super.onSaveInstanceState(outState); } }
解决方案
@覆盖
公共无效的onCreate(包savedInstanceState){
super.onCreate(savedInstanceState,这一点,TAG_TAFFER_TIME);
mFragmentHolder =(RelativeLayout的)findViewById(R.id.fragment);
mFragmentTransaction = getSupportFragmentManager()的BeginTransaction()。
mFragmentTransaction.add(mFragmentHolder.getId(),mFragmentTafferTime,TAG);
mFragmentTransaction.addToBackStack(TAG);
mFragmentTransaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
mFragmentTransaction.commit();
}
//在片段的变化尝试使用此功能
私人无效changeFragment(SherlockFragment片段,字符串变量){
尝试 {
mFragmentTransaction.replace(mFragmentHolder.getId(),片段,标记);
mFragmentTransaction.addToBackStack(标签);
mFragmentTransaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
mFragmentTransaction.commit();
}赶上(例外的例外){
}
}
I am facing some weird issue while I am pressing home button of android and while starting new activity.
My stacktrace is as follows
05-13 18:06:21.182: E/FragmentManager(5674): Failure saving state: active Fragment{411d96d8} has cleared index: -1
05-13 18:06:21.182: E/FragmentManager(5674): Activity state:
05-13 18:06:22.032: E/ACRA(5674): ACRA caught a IllegalStateException exception for com.itgurussoftware.android.dineback. Building report.
05-13 18:06:27.732: E/ACRA(5674): com.itgurussoftware.android.dineback fatal error : Failure saving state: active Fragment{411d96d8} has cleared index: -1
05-13 18:06:27.732: E/ACRA(5674): java.lang.IllegalStateException: Failure saving state: active Fragment{411d96d8} has cleared index: -1
05-13 18:06:27.732: E/ACRA(5674): at android.support.v4.app.FragmentManagerImpl.saveAllState(FragmentManager.java:1723)
05-13 18:06:27.732: E/ACRA(5674): at android.support.v4.app.FragmentActivity.onSaveInstanceState(FragmentActivity.java:546)
05-13 18:06:27.732: E/ACRA(5674): at android.app.Activity.performSaveInstanceState(Activity.java:1113)
05-13 18:06:27.732: E/ACRA(5674): at android.app.Instrumentation.callActivityOnSaveInstanceState(Instrumentation.java:1185)
05-13 18:06:27.732: E/ACRA(5674): at android.app.ActivityThread.performStopActivityInner(ActivityThread.java:2793)
05-13 18:06:27.732: E/ACRA(5674): at android.app.ActivityThread.handleStopActivity(ActivityThread.java:2851)
05-13 18:06:27.732: E/ACRA(5674): at android.app.ActivityThread.access$900(ActivityThread.java:123)
05-13 18:06:27.732: E/ACRA(5674): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1164)
05-13 18:06:27.732: E/ACRA(5674): at android.os.Handler.dispatchMessage(Handler.java:99)
05-13 18:06:27.732: E/ACRA(5674): at android.os.Looper.loop(Looper.java:137)
05-13 18:06:27.732: E/ACRA(5674): at android.app.ActivityThread.main(ActivityThread.java:4424)
05-13 18:06:27.732: E/ACRA(5674): at java.lang.reflect.Method.invokeNative(Native Method)
05-13 18:06:27.732: E/ACRA(5674): at java.lang.reflect.Method.invoke(Method.java:511)
05-13 18:06:27.732: E/ACRA(5674): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
05-13 18:06:27.732: E/ACRA(5674): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
05-13 18:06:27.732: E/ACRA(5674): at dalvik.system.NativeStart.main(Native Method)
and my code to add and remove the fragment is as follows
FragmentContainer fragContainer = container.get(container.size() - 1);
Fragment fragment = fragContainer.getFragment();
String tag = fragContainer.getTabName();
FragmentManager manager = getSupportFragmentManager();
FragmentTransaction ft = manager.beginTransaction();
mTabHost.setCurrentTabByTag(tag);
if (!fragment.isAdded()) {
ft.remove(fragment);
}
if(container.size()>0)
container.remove(container.size() - 1);
ft.replace(R.id.realtabcontent, fragment);
ft.commitAllowingStateLoss();
Tried
- Updating support library
Tried overriding onSaveInstanceState as
@Override protected void onSaveInstanceState(Bundle outState) { // TODO Auto-generated method stub if (outState != null) { super.onSaveInstanceState(outState); } }
解决方案
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState, this, TAG_TAFFER_TIME);
mFragmentHolder = (RelativeLayout) findViewById(R.id.fragment);
mFragmentTransaction = getSupportFragmentManager().beginTransaction();
mFragmentTransaction.add(mFragmentHolder.getId(), mFragmentTafferTime, TAG);
mFragmentTransaction.addToBackStack(TAG);
mFragmentTransaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
mFragmentTransaction.commit();
}
// On fragment change try to use this function
private void changeFragment(SherlockFragment fragment, String tag) {
try {
mFragmentTransaction.replace(mFragmentHolder.getId(), fragment, tag);
mFragmentTransaction.addToBackStack(tag);
mFragmentTransaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
mFragmentTransaction.commit();
} catch (Exception exception) {
}
}
这篇关于获取例外,因为失败节能状态:活性片段已被清除指数:-1当我pressing家Android设备按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!