@@ -3,38 +3,40 @@ package me.ycdev.android.lib.common.activity
3
3
import android.content.ComponentName
4
4
import java.util.Stack
5
5
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 >()
8
8
9
- internal fun addActivity (activity : ActivityInfo ) {
9
+ internal fun addActivity (activity : ActivityRunningState ) {
10
10
if (activity.taskId != taskId) {
11
11
throw RuntimeException (" Activity taskId[${activity.taskId} ] != AppTask[$taskId ]" )
12
12
}
13
13
activities.add(activity)
14
14
}
15
15
16
- internal fun popActivity (componentName : ComponentName ): ActivityInfo {
16
+ internal fun popActivity (componentName : ComponentName , hashCode : Int ): ActivityRunningState {
17
17
val it = activities.asReversed().iterator()
18
18
while (it.hasNext()) {
19
19
val activity = it.next()
20
- if (activity.componentName == componentName) {
20
+ if (activity.componentName == componentName && activity.hashCode == hashCode ) {
21
21
it.remove()
22
22
return activity
23
23
}
24
24
}
25
- throw RuntimeException (" Cannot find $componentName " )
25
+ val hashHex = Integer .toHexString(hashCode)
26
+ throw RuntimeException (" Cannot find $componentName @$hashHex " )
26
27
}
27
28
28
- fun lastActivity (componentName : ComponentName ): ActivityInfo {
29
+ fun lastActivity (componentName : ComponentName , hashCode : Int ): ActivityRunningState {
29
30
activities.asReversed().forEach {
30
- if (it.componentName == componentName) {
31
+ if (it.componentName == componentName && it.hashCode == hashCode ) {
31
32
return it
32
33
}
33
34
}
34
- throw RuntimeException (" Cannot find $componentName " )
35
+ val hashHex = Integer .toHexString(hashCode)
36
+ throw RuntimeException (" Cannot find $componentName @$hashHex " )
35
37
}
36
38
37
- fun topActivity (): ActivityInfo {
39
+ fun topActivity (): ActivityRunningState {
38
40
if (activities.isEmpty()) {
39
41
throw RuntimeException (" The task is empty. Cannot get the top Activity." )
40
42
}
@@ -44,8 +46,8 @@ class ActivityTask(val taskId: Int) {
44
46
/* *
45
47
* @return The last Activity in returned list is the top Activity
46
48
*/
47
- fun getActivityStack (): Stack <ActivityInfo > {
48
- val stack = Stack <ActivityInfo >()
49
+ fun getActivityStack (): Stack <ActivityRunningState > {
50
+ val stack = Stack <ActivityRunningState >()
49
51
activities.forEach {
50
52
stack.push(it)
51
53
}
@@ -55,14 +57,14 @@ class ActivityTask(val taskId: Int) {
55
57
fun isEmpty () = activities.isEmpty()
56
58
57
59
fun makeCopy (): ActivityTask {
58
- val task = ActivityTask (taskId)
60
+ val task = ActivityTask (taskId, taskAffinity )
59
61
activities.forEach {
60
62
task.activities.add(it.makeCopy())
61
63
}
62
64
return task
63
65
}
64
66
65
67
override fun toString (): String {
66
- return " AppTask[taskId=$taskId , activities=$activities ]"
68
+ return " AppTask[taskId=$taskId , taskAffinity= $taskAffinity , activities=$activities ]"
67
69
}
68
70
}
0 commit comments