こんにちは、アプリに 3 つのアクティビティがあり、インテントを使用してそれらの間でデータを転送します。私が遭遇した問題は、3 つのアクティビティからメイン アクティビティに戻ったときに、メイン アクティビティにある共有設定が変更されることです。問題は私の意図が再起動することだと思いますが、よくわかりません。3 アクティビティに移動したときと同じデータを取得しようとしています。私のアプリはアクティビティ1で開始し、メインアクティビティに移動し、最後にボタンをクリックすると3番目のアクティビティに移動し、データを取得してメインアクティビティに戻ります私が抱えている問題は、最初のアクティビティから取得したデータです3番目のアクティビティから戻ったときに再起動します。アクティビティ間でデータを移動するときは、インテントを使用します。
インテントアクティビティ1を転送するための私のコード:
Bundle CIW = new Bundle();
CIW.putInt("one", int1);
CIW.putInt("two", int2);
CIW.putDouble("double", double);
Intent a = new Intent(Must.this, Main.class);
a.putExtras(CIW);
startActivity(a);
私のメインアクティビティでバンドルを取得するための私のコード(作成メソッドの私のものです):
Intent must = getIntent();
Intent name = getIntent();
Bundle CIW = must.getExtras();
Bundle card = name.getExtras();
int1 = CIW.getInt("one");
int2 = CIW.getInt("two");
double= CIW.getDouble("double");
int3 = card.getInt("three");
私の共有設定コード(一時停止中):
SharedPreferences settings = PreferenceManager
.getDefaultSharedPreferences(getApplicationContext());
SharedPreferences.Editor editor = settings.edit();
editor.putInt("one", Int1); //the rest of the variable
editor.commit();
私の共有設定コード(再開時):
SharedPreferences settings = PreferenceManager
.getDefaultSharedPreferences(getApplicationContext());
int1 = settings.getInt("one", int1); //the rest of the variable
インテントアクティビティを転送するための私のコード 3:
Bundle number = new Bundle();
number.putInt("three", int3);
Intent a = new Intent(Card.this, Main.class);
a.putExtras(number);