Question

I want to call a activty but when I call actviy I want to finish my caller activty , How can I do this?

  A:caller
  B:calling

 startActivity(new Intent(A.this, B.class));
  finish();

I write this code but everything is closing.

Was it helpful?

Solution

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

This launch mode can also be used to good effect in conjunction with FLAG_ACTIVITY_NEW_TASK: if used to start the root activity of a task, it will bring any currently running instance of that task to the foreground, and then clear it to its root state. This is especially useful, for example, when launching an activity from the notification manager.

OTHER TIPS

Try to do this:

              startActivity(new Intent(A.this, B.class));
              A.this.finish();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top