私は3ページあるアプリを持っていますが、そのうちの1つはメインページです。ユーザーは、ユーザーが2つのサブページのいずれかに移動した場合に保存したいいくつかのフィールドに入力できます。私はonPause()とonSaveInstanceState()を調べてきました。2つについて明確な説明が必要なだけだと思います。また、onPause()の方が優れている場合は、コードの例です。これは私がonSaveInstanceState()のために持っているものです。
protected void onSaveInstanceState(Bundle outState) {
// Save away the original text, so we still have it if the activity
// needs to be killed while paused.
outState.putDouble("quizPts",qpts);
outState.putDouble("quizV",qvalue);
outState.putDouble("tPts",tpts);
outState.putDouble("tValue", tvalue);
outState.putDouble("hPts", hpts);
これが、IDと値を指定してバンドルを設定する方法です。
public void onRestoreInstanceState(Bundle outState) {
super.onRestoreInstanceState(outState);
// Restore UI state from the savedInstanceState.
// This bundle has also been passed to onCreate.
qpts = outState.getDouble("quizPts");
qvalue = outState.getDouble("quizV");
tpts = outState.getDouble("tPts");
tvalue = outState.getDouble("tValue");
hpts = outState.getDouble("hPts");
これは私がそれを取り戻すことを計画している方法です、問題は私がそれを復元するためにバンドルを渡す方法を理解していないことです。UIに設定される変数に戻す必要のある変数を設定しています。
どんなアドバイスも素晴らしいでしょう
初心者のandroiderからの感謝