Android: Skip some fragments onBackPressed

Android 28 มี.ค. 2017

There is many way can do.

—===================================—
Very simple!! When you are starting the activity C, from B, use B.finish(). Something like this.

Intent i = new Intent(B.this, C.class);
B.this.finish();
startActivity(i);

This will remove B from the stack!

—===================================—

Intent i = new Intent(B.this, C.class);
i.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
startActivity(i);

—===================================—
Set a flag for B activity like this

private boolean mDestroyActivity = false;

set that flag true when you call startActivity C.

for activity B onStop method add checking like this:

if (mDestroyActivity) finish();

Then when you press back button in C you will jump back to A.

แท็ก

Onyx

Just a middle-aged programmer, Can do many things but not the most.