この文書の現在のバージョンと選択したバージョンの差分を表示します。
| 両方とも前のリビジョン 前のリビジョン 次のリビジョン | 前のリビジョン | ||
| 
                    fragmentメモ [2015/07/06 12:58] sou  | 
                
                    fragmentメモ [2015/07/29 09:51] (現在) sou  | 
            ||
|---|---|---|---|
| ライン 20: | ライン 20: | ||
| http://y-anz-m.blogspot.jp/2012/04/android-fragment-fragmenttransaction.html\\ | http://y-anz-m.blogspot.jp/2012/04/android-fragment-fragmenttransaction.html\\ | ||
| \\ | \\ | ||
| - | === IllegalStateExceptionの回避 === | + | === Fragment切り替え時のIllegalStateException === | 
| + | |||
| + | 下記の「操作NG」の箇所でFragmentを操作しようとすると発生します。\\ | ||
| + | |||
| + | [Fragmentライフサイクル]\\ | ||
| + | ...\\ | ||
| + | ↓\\ | ||
| + | ↓ 操作NG\\ | ||
| + | ↓\\ | ||
| + | onViewCreated(Bundle savedInstanceState) 状態復元\\ | ||
| + | onResume()\\ | ||
| + | ↓\\ | ||
| + | ↓\\ | ||
| + | ↓ 操作OK\\ | ||
| + | ↓\\ | ||
| + | ↓\\ | ||
| + | onPause()\\ | ||
| + | onSaveInstanceState()  状態保存\\ | ||
| + | ↓\\ | ||
| + | ↓ 操作NG\\ | ||
| + | ↓\\ | ||
| + | ...\\ | ||
| + | |||
| + | 「操作OK」の箇所で操作すれば大丈夫なように見えますが、非同期(サブスレッド)でFragmentTransacitonを取り扱ってしまったり、 | ||
| + | そもそもFragmentTransaction#commit()が非同期であるために発生します。 | ||
| + | |||
| + | |||
| + | FragmentのIllegalStateException回避\\ | ||
| http://iti.hatenablog.jp/entry/2015/02/23/121110\\ | http://iti.hatenablog.jp/entry/2015/02/23/121110\\ | ||
| + | Fragment使用時のIllegalStateException回避\\ | ||
| http://qiita.com/nein37/items/32613e9acd9558566c5e\\ | http://qiita.com/nein37/items/32613e9acd9558566c5e\\ | ||
| + | Fragment Transactions & Activity State Loss\\ | ||
| + | http://www.androiddesignpatterns.com/2013/08/fragment-transaction-commit-state-loss.html\\ | ||
| + | How to handle Handler messages when activity/fragment is paused\\ | ||
| + | http://stackoverflow.com/questions/8040280/how-to-handle-handler-messages-when-activity-fragment-is-paused | ||
| \\ | \\ | ||
| + | |||
| + | === FragmentTransaction#commit()はメインスレッドのHandlerにメッセージキューが積まれる === | ||
| + | FragmentManager#beginTransaction→(FragmentManagerImpl#beginTransaction)\\ | ||
| + | (Fragmentをいろいろ操作)\\ | ||
| + | FragmentTransaction#commit→(android.app.BackStackRecord#commit)\\ | ||
| + | (FragmentManagerImpl#enqueueAction)→(Activity#mHandlerに処理委譲)\\ | ||
| + | |||
| + | |||
| === Fragment in Fragment === | === Fragment in Fragment === | ||
| FragmentでFragmentを管理するときはgetChildFragmentManager()\\ | FragmentでFragmentを管理するときはgetChildFragmentManager()\\ | ||