Android onRestart呼び出しタイミング

1150 ワード

onRestart呼び出しタイミング
公式の説明:
onRestart
void onRestart ()
Called after onStop() when the current activity is being re-displayed to the user (the user has navigated back to it). It will be followed by onStart() and then onResume(). For activities that are using raw Cursor objects (instead of creating them through managedQuery(android.net.Uri, String[], String, String[], String), this is usually the place where the cursor should be requeried (because you had deactivated it in onStop(). Derived classes must call through to the super class's implementation of this method. If they do not, an exception will be thrown. If you override this method you must call through to the superclass implementation.
個人解読
公式解釈ではactiviyの再表示を強調するとonRestartが呼び出されます.2つの状況が再表示されます.
  • activity非可視から可視に変更
  • にはactivityインスタンスが既に存在し、activityを再起動すると、メソッドを複写する場合は、メソッド内で親メソッドを呼び出すべきだと公式に強調されています.そうしないと、例外が放出されます.正しいコードの作成は
  • です
    @Override
    protected void onRestart() {
        // If you override this method you must call through to the superclass implementation
        super.onRestart();
    }