3

In my activity A I am calling activity B using Intent. In Activity B I have override onBackPressed() and from that I am calling Activity A, but not use finish(). So again from A when we call activity B, does same instance of activity B is used or new instance is created? And Is it bad idea to call again n again without finishing activity? If it is, how to prevent creating new instance of activity B every time? Does android:launchMode="singleTask" in manifest will help or not in this case?

4

1 に答える 1

2

アクティビティを呼び出す前に、インテントでFLAG_ACTIVITY_REORDER_TO_FRONTフラグを設定できます。このフラグにより​​、起動されたアクティビティが既に実行されている場合は、そのアクティビティの新しいインスタンスが作成されないように、タスクの履歴スタックの先頭に移動されます。例えば

Intent settingIntent = new Intent(ActivityA.this, ActivityB.class);                         
settingIntent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
ActivityA.this.startActivity(settingIntent);
于 2012-09-12T06:09:35.987 に答える