Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Switching between activities in android?

In my android application, I have following requirement.

Activity A --> Activity B(Go to A Option) --> Activity C(Go To A Option,Go To B Option)

1) To Go To Activity A from Activity B i have used onBackPressed() method.

2) To Go To Activity B from Activity C i have used onBackPressed()method again.

those are working fine.

3) Now i want to go to Activity A from Activity C (without Intent calling).

How can i do this?

Edited 1:

Activity A is my Main activity i don't want restart the activity by using Intent.i want to resume Activity A from activity c.(like i did from activity B by using onBackPressed).

Edited 2(With Answer):

Ok guys. Thanks everyone for giving me your help on my question.finally i found a simple answer similar to @Paresh Mayani's answer.

Answer:

        Intent a = new Intent(getApplicationContext(),ActivityA.class);
        a.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
        startActivity(a);

i got this nice solution by using this link that solved my problem. thanks to everyone again and i really appreciate that.

like image 549
Dinesh Anuruddha Avatar asked Mar 30 '12 04:03

Dinesh Anuruddha


1 Answers

I assume that you don't want to use Intent because whenever you use Intent for moving to activity A pressing Back key will move to the previous activity (activity C). In this case I would suggest you to include FLAG_ACTIVITY_CLEAR_TOP flag. It will destroy all the previous activity and let you to move to Activity A.

 Intent a = new Intent(this,A.class);
 a.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
 startActivity(a);

Alternatively, you can try the FLAG_ACTIVITY_REORDER_TO_FRONT flag instead, which will move to activity A without clearing any activity.

For more, check this.

like image 185
Paresh Mayani Avatar answered Sep 25 '22 16:09

Paresh Mayani