Search code examples
androidandroid-activityactivity-finishhome-button

How to bring activity to front using finish from another activity


i have two activities: A and B.

from A to B:

onCreate

Context context = this;

onClick

Intent i = new Intent(context,B.class);
startActivity(i);

from B to A: (if B has a button to return to A)

button.setOnClickListener(new View.OnClickListener(){
   public void onClick(View v){
      finish();
   }
});

But if the flow is like:

A call B, the user that is watching B clicks Home button and click again B from launched activities and clicks the button to call finish(), it goes to Home and not to my first activity A. How can i do it?

EDIT:

flow

  1. A->B // with startActivity(Intent);
  2. B->Home // clicking home button on device
  3. Home->B // clicking my app from launched activities
  4. B.finish() -> Home and not A // finish or onBackPressed do the same

Solution

  • can you try this :-

    WHY ARE YOUR USING getApplicationContext() instead of use this or Activity A name.

    A ->B

     Intent i = new Intent(yourcurrentActivity,B.class);
     startActivty(i);
    

    B ->A

    call finish()

    update if you are using this:- remove it

    android:noHistory="true";