-1

I have four activities

  • ListActivity
  • Itemdetail_Activity
  • record1_Act
  • record2_act.

I can go from ListActivity -> record1_Act and from ListActivity <-record1_Act properly but when I want to go from Itemdetail_Activity -> record2_act and return back from Itemdetail_Activity <- record2_act it always goes record2_act to ListActivity.

I even used i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK); but it does not work. How to solve this issues?

Here is my code

Intent i = new Intent(record2_act.this, Itemdetail_Activity.class);
i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(i);

Intent i = new Intent(record1_Act.this, ListActivity.class);
i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(i);
finish();
Bowdzone
  • 3,747
  • 11
  • 40
  • 50
androidTag
  • 4,833
  • 7
  • 16
  • 27

4 Answers4

1

After starting activity remove finish() call because it will clear that activity from stack and i see you have used finish in your code. also you do not need to set these flags.

Arslan Ashraf
  • 855
  • 7
  • 12
0

In activity 4, implement onBackPressed() as,

@Override
public void onBackPressed()
{
 Intent i = new Intent(4.this, 3.class);
 startActivity(i);
}

call this method if you have any back button. And if you want to link the backpress for every activity you need to implement onBackPressed() method in every activity.

DroidAks
  • 327
  • 2
  • 9
0

you can call onBackPressed() if previous activity not finished also you can use :

this.finish();
// Or
Activity currentActivity = this;
currentActivity.finish();

and if previous you finished activity you have to track user in activities and make list of activities, then move to :

activitiList.get(activityList.size() - 2);
// activityList.size() - 1 is last activity and activityList.size() - 2 is previous activity
Hossein Kurd
  • 2,426
  • 2
  • 39
  • 64
0

Do check if ItemDetailsActivity is NOT calling finish()

jily
  • 344
  • 2
  • 11