1

I want to go from Activity A to Activity B onClick and back to Activity A if a condition have not been on Activity B.

Activity A:

    onClick() {
       Intent intent = new Intent(this, Activity_B.class);
       intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
       startActivity(intent);
    }

Activity B:

if (condition) {
   //code for return back to Activity A
}
Developer
  • 133
  • 1
  • 10
  • 3
    Possible duplicate of [How to manage \`startActivityForResult\` on Android?](https://stackoverflow.com/questions/10407159/how-to-manage-startactivityforresult-on-android) – ADM Apr 22 '18 at 02:07
  • You only need `if (condition) { finish(); }` In this case – ADM Apr 22 '18 at 02:08

1 Answers1

0

Since you are going directly from Activity A to Activity B and want to get back to Activity A. I am assumimg that no other Activities are being called from Activity B then you just finish the Activity B inside your condition. It will automatically be returned to Activity A

Naman Mehta
  • 26
  • 10