-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,827
  • 11
  • 39
  • 52
androidTag
  • 5,053
  • 7
  • 19
  • 28
  • Check [here](http://stackoverflow.com/a/4038637/3843476) You may find your answer. – Gagan Nov 02 '15 at 06:34
  • Please enter the correct flow which you desire. Or enter the whole code. – DroidAks Nov 02 '15 at 06:36
  • @DroidAks : I have Activity 1 , 2, 3, 4 i can go 1 -> 2 and 1 <-2 , And when i want to go 3 -> 4 and return back to 3 <- 4 here is the issue . 4 is always return to 1 means 1 <- 4 this is the issue. – androidTag Nov 02 '15 at 06:40

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
  • 867
  • 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
  • 3,184
  • 3
  • 41
  • 71
0

Do check if ItemDetailsActivity is NOT calling finish()

jily
  • 344
  • 2
  • 11