Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Go back to 2nd Previous Activity

The question might be dumb but I'll ask it, for example I have 3 Activities, Activity 1,2,3.

Activity 1, I click a button, goes to Activity 2 Activity 2, I click a button, goes to Activity 3. Activity 3, I click the back button, I want it to go back to Activity 1. Any idea how to do it? Sorry Android Newbie. Thanks!

like image 895
Jeongbebs Avatar asked Nov 27 '13 06:11

Jeongbebs


2 Answers

override onbackpressed method and just do like this:-

 @Override
 public void onBackPressed() {
        Intent intent = new Intent(Activity3.this,
                Activity1.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
                | Intent.FLAG_ACTIVITY_SINGLE_TOP);
        startActivity(intent);

  }

Enjoy....!

like image 152
Kailash Dabhi Avatar answered Sep 29 '22 08:09

Kailash Dabhi


In the android.manifest file make your second Activity..

android:excludeFromRecents="true"
android:launchMode="singleTask"

Hope this does the trick. if this does not work then you can try by setting Intent.setFlags while you start the activity 2

like image 23
Srikanth Pai Avatar answered Sep 29 '22 08:09

Srikanth Pai