@@ -3,38 +3,40 @@ package me.ycdev.android.lib.common.activity
33import android.content.ComponentName
44import java.util.Stack
55
6- class ActivityTask (val taskId : Int ) {
7- private val activities = arrayListOf<ActivityInfo >()
6+ class ActivityTask (val taskId : Int , val taskAffinity : String ) {
7+ private val activities = arrayListOf<ActivityRunningState >()
88
9- internal fun addActivity (activity : ActivityInfo ) {
9+ internal fun addActivity (activity : ActivityRunningState ) {
1010 if (activity.taskId != taskId) {
1111 throw RuntimeException (" Activity taskId[${activity.taskId} ] != AppTask[$taskId ]" )
1212 }
1313 activities.add(activity)
1414 }
1515
16- internal fun popActivity (componentName : ComponentName ): ActivityInfo {
16+ internal fun popActivity (componentName : ComponentName , hashCode : Int ): ActivityRunningState {
1717 val it = activities.asReversed().iterator()
1818 while (it.hasNext()) {
1919 val activity = it.next()
20- if (activity.componentName == componentName) {
20+ if (activity.componentName == componentName && activity.hashCode == hashCode ) {
2121 it.remove()
2222 return activity
2323 }
2424 }
25- throw RuntimeException (" Cannot find $componentName " )
25+ val hashHex = Integer .toHexString(hashCode)
26+ throw RuntimeException (" Cannot find $componentName @$hashHex " )
2627 }
2728
28- fun lastActivity (componentName : ComponentName ): ActivityInfo {
29+ fun lastActivity (componentName : ComponentName , hashCode : Int ): ActivityRunningState {
2930 activities.asReversed().forEach {
30- if (it.componentName == componentName) {
31+ if (it.componentName == componentName && it.hashCode == hashCode ) {
3132 return it
3233 }
3334 }
34- throw RuntimeException (" Cannot find $componentName " )
35+ val hashHex = Integer .toHexString(hashCode)
36+ throw RuntimeException (" Cannot find $componentName @$hashHex " )
3537 }
3638
37- fun topActivity (): ActivityInfo {
39+ fun topActivity (): ActivityRunningState {
3840 if (activities.isEmpty()) {
3941 throw RuntimeException (" The task is empty. Cannot get the top Activity." )
4042 }
@@ -44,8 +46,8 @@ class ActivityTask(val taskId: Int) {
4446 /* *
4547 * @return The last Activity in returned list is the top Activity
4648 */
47- fun getActivityStack (): Stack <ActivityInfo > {
48- val stack = Stack <ActivityInfo >()
49+ fun getActivityStack (): Stack <ActivityRunningState > {
50+ val stack = Stack <ActivityRunningState >()
4951 activities.forEach {
5052 stack.push(it)
5153 }
@@ -55,14 +57,14 @@ class ActivityTask(val taskId: Int) {
5557 fun isEmpty () = activities.isEmpty()
5658
5759 fun makeCopy (): ActivityTask {
58- val task = ActivityTask (taskId)
60+ val task = ActivityTask (taskId, taskAffinity )
5961 activities.forEach {
6062 task.activities.add(it.makeCopy())
6163 }
6264 return task
6365 }
6466
6567 override fun toString (): String {
66- return " AppTask[taskId=$taskId , activities=$activities ]"
68+ return " AppTask[taskId=$taskId , taskAffinity= $taskAffinity , activities=$activities ]"
6769 }
6870}
0 commit comments