Now, please modify the AndroidManifest.xml of activity - android:launchMode(1) as
<activity android:name=".A2" android:label="@string/app_name" android:launchMode="singleTop"/>
And run the Activity in sequence:
A1->A2->A2->A3->A2
A1 to A2 |
When you tapped "Intent to A2", it was the original A2 and wouldn't create a new A2 |
A2 to A3 |
A3 to A2, it created a new A2 |
It wouldn't create a new A2 when A2 on the top of activity stack since the A2 was setted for singleTop。In other hand, A3 startActivity A2 would create a new A2 since what on the top of activity stack was A3 but not A2. That is, you can see there are 2 hashcode of A2 as follows:
com.testintent.A2@43e4a2a0
com.testintent.A2@43e5b138
You can find out the activities disappeared in order when you tap Back Key since A2.
A2 -> A3 -> A2 -> A1
Please note, A2 only appeared once between A3 -> A2 -> A1,
沒有留言:
張貼留言