这是我编写的代码。我无法找到此功能何时崩溃,但有时它可以工作。
public class ListFragmentActivity extends FragmentActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
main();
IntentFilter filter1 = new IntentFilter("com.venkat.listfragment");
registerReceiver(myReceiver, filter1);
// register reciever intent filter.
}
public void main(){
IntentFilter filter1 = new IntentFilter("com.venkat.listfragment");
registerReceiver(myReceiver, filter1);
List_Fragment ls_fragment = new List_Fragment();
getSupportFragmentManager().popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE);
getSupportFragmentManager().beginTransaction()
.replace(android.R.id.content, ls_fragment).addToBackStack(null).commitAllowingStateLoss();
}
@Override
protected void onSaveInstanceState(Bundle outState) {
}
private BroadcastReceiver myReceiver = new BroadcastReceiver()
{
@Override
public void onReceive(Context context, Intent intent) {
main();
}
};}
我有四个选项卡,当我单击一个选项卡时,它会显示相应的屏幕,并且从该屏幕我正在使用同一选项卡中导航另一个屏幕。但是当我单击同一选项卡时要返回上一个屏幕,我已经编写了一个广播接收器。
我收到此错误:
08-19 10:13:51.436: E/AndroidRuntime(2830): FATAL EXCEPTION: main
08-19 10:13:51.436: E/AndroidRuntime(2830): java.lang.RuntimeException: Error receiving broadcast Intent { act=com.venkat.listfragment } in com.iheartsalesevent.main.ListFragmentActivity$1@44a89218
08-19 10:13:51.436: E/AndroidRuntime(2830): at android.app.ActivityThread$PackageInfo$ReceiverDispatcher$Args.run(ActivityThread.java:905)
08-19 10:13:51.436: E/AndroidRuntime(2830): at android.os.Handler.handleCallback(Handler.java:587)
08-19 10:13:51.436: E/AndroidRuntime(2830): at android.os.Handler.dispatchMessage(Handler.java:92)
08-19 10:13:51.436: E/AndroidRuntime(2830): at android.os.Looper.loop(Looper.java:123)
08-19 10:13:51.436: E/AndroidRuntime(2830): at android.app.ActivityThread.main(ActivityThread.java:4627)
08-19 10:13:51.436: E/AndroidRuntime(2830): at java.lang.reflect.Method.invokeNative(Native Method)
08-19 10:13:51.436: E/AndroidRuntime(2830): at java.lang.reflect.Method.invoke(Method.java:521)
08-19 10:13:51.436: E/AndroidRuntime(2830): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
08-19 10:13:51.436: E/AndroidRuntime(2830): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
08-19 10:13:51.436: E/AndroidRuntime(2830): at dalvik.system.NativeStart.main(Native Method)
08-19 10:13:51.436: E/AndroidRuntime(2830): Caused by: java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState
08-19 10:13:51.436: E/AndroidRuntime(2830): at android.support.v4.app.FragmentManagerImpl.checkStateLoss(FragmentManager.java:1343)
08-19 10:13:51.436: E/AndroidRuntime(2830): at android.support.v4.app.FragmentManagerImpl.enqueueAction(FragmentManager.java:1354)
08-19 10:13:51.436: E/AndroidRuntime(2830): at android.support.v4.app.FragmentManagerImpl.popBackStack(FragmentManager.java:493)
08-19 10:13:51.436: E/AndroidRuntime(2830): at com.venkat.main.ListFragmentActivity.main(ListFragmentActivity.java:65)
08-19 10:13:51.436: E/AndroidRuntime(2830): at com.venkat.main.ListFragmentActivity$1.onReceive(ListFragmentActivity.java:89)
08-19 10:13:51.436: E/AndroidRuntime(2830): at android.app.ActivityThread$PackageInfo$ReceiverDispatcher$Args.run(ActivityThread.java:892)
08-19 10:13:51.436: E/AndroidRuntime(2830): ... 9 more
我提到了很多与此问题相关的链接,但这些链接并不能解决我的问题。