Skip to content

Commit

Permalink
Feature: support the SingleTop launchMode.
Browse files Browse the repository at this point in the history
  • Loading branch information
asLody committed Jul 28, 2016
1 parent 89d4e29 commit bade121
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,16 @@ public boolean isOnTop(ActivityInfo activityInfo) {
return top != null && ComponentUtils.isSameComponent(activityInfo, top.activityInfo);
}

public boolean isInTask(ActivityInfo activityInfo) {
for (ActivityRecord r : activityList) {
if (ComponentUtils.isSameComponent(r.activityInfo, activityInfo)) {
return true;
}
}
return false;
}

public int size() {
return activityList.size();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import com.lody.virtual.client.core.VirtualCore;
import com.lody.virtual.client.env.Constants;
import com.lody.virtual.helper.compat.ActivityManagerCompat;
import com.lody.virtual.helper.proto.AppTaskInfo;
import com.lody.virtual.helper.proto.VActRedirectResult;
import com.lody.virtual.helper.proto.VRedirectActRequest;
Expand All @@ -33,6 +34,7 @@
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
Expand Down Expand Up @@ -179,6 +181,28 @@ public synchronized VActRedirectResult redirectTargetActivity(final VRedirectAct
}
}

if (targetActInfo.launchMode == ActivityInfo.LAUNCH_SINGLE_TASK) {
ActivityTaskRecord topTask = getTopTask();
if (topTask != null && topTask.isInTask(targetActInfo)) {
int size = topTask.size();
ActivityRecord top = null;
ListIterator<ActivityRecord> iterator = topTask.activityList.listIterator(size);
while (iterator.hasPrevious()) {
top = iterator.previous();
if (ComponentUtils.isSameComponent(top.activityInfo, targetActInfo)) {
break;
}
ActivityManagerCompat.finishActivity(top.token, -1, null);
}
if (top != null) {
ProcessRecord processRecord = VProcessService.getService().findProcess(top.pid);
// The top Activity is the target Activity
return new VActRedirectResult(top.token, processRecord.appThread.asBinder());
}
}
}


if (sourceRecord != null && sourceRecord.caller != null) {
if (sourceRecord.activityInfo.launchMode == ActivityInfo.LAUNCH_SINGLE_INSTANCE) {
String comebackTaskAffinity = ComponentUtils.getTaskAffinity(sourceRecord.caller);
Expand Down

0 comments on commit bade121

Please sign in to comment.