4

次のようなブロードキャストの受信時にフラグメントをコミットしています

 BroadcastReceiver br = new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {
            // Log.e(TAG,"inside onReceive");
            if (intent.getAction().equalsIgnoreCase(
                    DATA_AVAILABLE))
                initFragments.run();
                }
     }

InitFragment はコードで実行可能です

dataBrowse = new SongListFragment();
                getSupportFragmentManager().beginTransaction()
                        ./*replace*/ add (R.id.container, dataBrowse ).commit();

電話がロックされている場合を除いて、常に完璧に機能します。なぜこれが起こるのですか?この原因の解決策は何ですか?

ログ:

06-23 03:56:38.210: E/AndroidRuntime(11174): FATAL EXCEPTION: main
06-23 03:56:38.210: E/AndroidRuntime(11174): java.lang.RuntimeException: Error receiving broadcast Intent { act=dat_avail flg=0x10 } in com.example.MainActivity$1@41b98e90
06-23 03:56:38.210: E/AndroidRuntime(11174):    at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:765)
06-23 03:56:38.210: E/AndroidRuntime(11174):    at android.os.Handler.handleCallback(Handler.java:615)
06-23 03:56:38.210: E/AndroidRuntime(11174):    at android.os.Handler.dispatchMessage(Handler.java:92)
06-23 03:56:38.210: E/AndroidRuntime(11174):    at android.os.Looper.loop(Looper.java:137)
06-23 03:56:38.210: E/AndroidRuntime(11174):    at android.app.ActivityThread.main(ActivityThread.java:4898)
06-23 03:56:38.210: E/AndroidRuntime(11174):    at java.lang.reflect.Method.invokeNative(Native Method)
06-23 03:56:38.210: E/AndroidRuntime(11174):    at java.lang.reflect.Method.invoke(Method.java:511)
06-23 03:56:38.210: E/AndroidRuntime(11174):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006)
06-23 03:56:38.210: E/AndroidRuntime(11174):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
06-23 03:56:38.210: E/AndroidRuntime(11174):    at dalvik.system.NativeStart.main(Native Method)
06-23 03:56:38.210: E/AndroidRuntime(11174): Caused by: java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState
06-23 03:56:38.210: E/AndroidRuntime(11174):    at android.support.v4.app.FragmentManagerImpl.checkStateLoss(FragmentManager.java:1343)
06-23 03:56:38.210: E/AndroidRuntime(11174):    at android.support.v4.app.FragmentManagerImpl.enqueueAction(FragmentManager.java:1361)
06-23 03:56:38.210: E/AndroidRuntime(11174):    at android.support.v4.app.BackStackRecord.commitInternal(BackStackRecord.java:595)
06-23 03:56:38.210: E/AndroidRuntime(11174):    at android.support.v4.app.BackStackRecord.commit(BackStackRecord.java:574)
06-23 03:56:38.210: E/AndroidRuntime(11174):    at com.example.MainActivity$3.run(MainActivity.java:228)
06-23 03:56:38.210: E/AndroidRuntime(11174):    at com.example.MainActivity$1.onReceive(MainActivity.java:101)
06-23 03:56:38.210: E/AndroidRuntime(11174):    at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:755)
06-23 03:56:38.210: E/AndroidRuntime(11174):    ... 9 more
06-23 03:56:38.245: I/Process(11174): Sending signal. PID: 11174 SIG: 9
4