Finish old activity and start a new one or vice versa

后端 未结 7 2142
轮回少年
轮回少年 2020-12-02 15:16

I know, that I get the same result with both code snippets

finish();
startActivity(newActivity);

and

startActivity(newActiv         


        
7条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-02 15:38

    I had the similar issue:

    Activity A: singleInstance
    Activity B: singleInstance
    Activity C: singleInstance
    
    A starts B 
    B starts C
    C wants to start A:
    

    here if I use:

    finish();
    startActivity(A);
    

    something wired happens: Activity B comes to foreground instead of A! but if I change the code like this:

    startActivity(A);
    finish();
    

    everything seems ok and Activity A comes visible.

    I don't know what's the problem, but it seems that in the first case, C is finished before executing the startActivity command so that the back stack handles the situation and shows its top activity which is B! but in the second case, everything happens normally.

提交回复
热议问题