简体   繁体   中英

Finishing activity doesn't show previous

I have four Activities, call them A, B, C, D. From A, you can start B, and from B you can start C and from C D.

Using Intent I'm starting new Activities:

Intent intent = new Intent(this, B.class);
intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT | Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK); 
startActivity(intent);

Activity D extends Activity A:

public class D extends A 
{
    ...
}

When I try to close Activity D, Activity C should be displayed, but instead of that, Activity B is displayed. Finishing other Activities, like B,C works fine (always previous Activity is displayed). I tried to finish D with finish(), super.onBackPressed(), also tried calling new Intent and starting C from it, but always Activity B is shown. I have no idea why.

Why is not C displayed, when I'm finishing D?

Edit: I found out that onResume() of Activity C is called, but then on next line of log is: Application terminated. , and Activity B is shown. There is no code in onResume() in C, so still no clue what's wrong there.

Why do create a new Task everytime? and CLEAR_TOP?

Just create a plain intent

Intent intent = new Intent(this, B.class);
startActivity(intent);

wouldn't that exactly be what you want?

Oh, and I hope you exchange B.class in each intent with the Activity you actually want to show? Or is this the reason why "always activity B is shown"?

See more information about Activities and the Task Back Stack here Tasks and Back Stack

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM