本文整理汇总了Java中android.app.ActivityManager.AppTask方法的典型用法代码示例。如果您正苦于以下问题:Java ActivityManager.AppTask方法的具体用法?Java ActivityManager.AppTask怎么用?Java ActivityManager.AppTask使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.app.ActivityManager
的用法示例。
在下文中一共展示了ActivityManager.AppTask方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: IsBaseActivityRunning
import android.app.ActivityManager; //导入方法依赖的package包/类
@TargetApi(Build.VERSION_CODES.M)
public boolean IsBaseActivityRunning() {
ActivityManager activityManager = (ActivityManager) _context.getSystemService(Context.ACTIVITY_SERVICE);
if (activityManager == null) {
Logger.getInstance().Error(TAG, "ActivityManager is null!");
return false;
}
List<ActivityManager.AppTask> tasks = activityManager.getAppTasks();
for (ActivityManager.AppTask task : tasks) {
if (_context.getPackageName().equalsIgnoreCase(task.getTaskInfo().baseActivity.getPackageName())) {
return true;
}
}
return false;
}
示例2: getTasksFromRecents
import android.app.ActivityManager; //导入方法依赖的package包/类
@Override
public List<Entry> getTasksFromRecents(boolean isIncognito) {
Context context = ContextUtils.getApplicationContext();
ActivityManager activityManager =
(ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
List<Entry> entries = new ArrayList<Entry>();
for (ActivityManager.AppTask task : activityManager.getAppTasks()) {
Intent intent = DocumentUtils.getBaseIntentFromTask(task);
if (!isValidActivity(isIncognito, intent)) continue;
int tabId = getTabIdFromIntent(intent);
if (tabId == Tab.INVALID_TAB_ID) continue;
String initialUrl = getInitialUrlForDocument(intent);
entries.add(new Entry(tabId, initialUrl));
}
return entries;
}
示例3: onTaskRemoved
import android.app.ActivityManager; //导入方法依赖的package包/类
@Override
public void onTaskRemoved(Intent rootIntent) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
ActivityManager am = (ActivityManager) mContext.getSystemService(
Context.ACTIVITY_SERVICE);
List<ActivityManager.AppTask> tasks = am.getAppTasks();
// In multi-window case, there could be multiple tasks. Only swiping away the last
// activity should be pause the notification.
if (tasks.size() > 0) return;
}
// This funcion is called when Chrome is swiped away from the recent apps
// drawer. So it doesn't catch all scenarios that chrome can get killed.
// This will only help Android 4.4.2.
onBrowserKilled();
mStopPostingProgressNotifications = true;
}
开发者ID:rkshuai,项目名称:chromium-for-android-56-debug-video,代码行数:17,代码来源:DownloadNotificationService.java
示例4: isParentInAndroidOverview
import android.app.ActivityManager; //导入方法依赖的package包/类
/** If the API allows it, returns whether a Task still exists for the parent Activity. */
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private boolean isParentInAndroidOverview() {
ActivityManager activityManager = (ActivityManager) mTab.getApplicationContext()
.getSystemService(Context.ACTIVITY_SERVICE);
for (ActivityManager.AppTask task : activityManager.getAppTasks()) {
Intent taskIntent = DocumentUtils.getBaseIntentFromTask(task);
if (taskIntent != null && taskIntent.filterEquals(mTab.getParentIntent())) {
return true;
}
}
return false;
}
开发者ID:rkshuai,项目名称:chromium-for-android-56-debug-video,代码行数:14,代码来源:TabWebContentsDelegateAndroid.java
示例5: finishOtherTasksWithData
import android.app.ActivityManager; //导入方法依赖的package包/类
/**
* Finishes tasks other than the one with the given ID that were started with the given data
* in the Intent, removing those tasks from Recents and leaving a unique task with the data.
* @param data Passed in as part of the Intent's data when starting the Activity.
* @param canonicalTaskId ID of the task will be the only one left with the ID.
* @return Intent of one of the tasks that were finished.
*/
public static Intent finishOtherTasksWithData(Uri data, int canonicalTaskId) {
if (data == null || Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) return null;
String dataString = data.toString();
Context context = ContextUtils.getApplicationContext();
ActivityManager manager =
(ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
List<ActivityManager.AppTask> tasksToFinish = new ArrayList<ActivityManager.AppTask>();
for (ActivityManager.AppTask task : manager.getAppTasks()) {
RecentTaskInfo taskInfo = getTaskInfoFromTask(task);
if (taskInfo == null) continue;
int taskId = taskInfo.id;
Intent baseIntent = taskInfo.baseIntent;
String taskData = baseIntent == null ? null : taskInfo.baseIntent.getDataString();
if (TextUtils.equals(dataString, taskData)
&& (taskId == -1 || taskId != canonicalTaskId)) {
tasksToFinish.add(task);
}
}
return finishAndRemoveTasks(tasksToFinish);
}
示例6: getTopActivityByActivityManager
import android.app.ActivityManager; //导入方法依赖的package包/类
/**
* 通过ActivityManager拿到栈顶Activity的ClassName,然后跟列表中的Activity比对,获取栈顶Activity。
* 注意:这种方式有个很严重的缺陷,如果某个Activity在栈里多次出现将导致判断错误,这时候将返回null。
* 可靠性相对一般,不会返回错误结果。
*
* @param application application
* @param activities 所有的Activity列表
* @return 栈顶Activity,获取不到的时候将返回null,不会返回错误结果。
* @throws ReflectUtils.ReflectException 可能会发生异常,强制要求处理异常情况。
*/
public static Activity getTopActivityByActivityManager(Context application
, List<Activity> activities) throws ReflectUtils.ReflectException {
ActivityManager activityManager = (ActivityManager) application
.getSystemService(Context.ACTIVITY_SERVICE);
String topActivity = null;
String packageName = application.getPackageName();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
List<ActivityManager.AppTask> appTasks = activityManager.getAppTasks();
for (int i = 0, size = appTasks.size(); i < size; i++) {
ActivityManager.RecentTaskInfo taskInfo = appTasks.get(size - 1 - i).getTaskInfo();
if (packageName.equals(taskInfo.baseActivity.getPackageName())) {
topActivity = taskInfo.topActivity.getClassName();
}
}
}
if (TextUtils.isEmpty(topActivity)) {
Log.i(TAG, "尝试通过getTopActivityByActivityManager获取Activity失败");
return null;
}
boolean check = false;
Activity result = null;
if (activities != null) {
for (Activity activity : activities) {
if (topActivity.equals(activity.getClass().getName())) {
if (check) {
// 出现重复Activity,返回null
Log.i(TAG, "尝试通过getTopActivityByActivityManager获取Activity失败");
return null;
}
check = true;
result = activity;
}
}
}
if (result == null) {
Log.w(TAG, "尝试通过getTopActivityByActivityManager获取Activity失败");
} else {
Log.i(TAG, "尝试通过getTopActivityByActivityManager获取Activity成功");
}
return result;
}
示例7: finishAndRemoveTaskIfInBackground
import android.app.ActivityManager; //导入方法依赖的package包/类
private void finishAndRemoveTaskIfInBackground() {
if (activitiesInStartedState == 0) {
final ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
if (activityManager == null) {
return;
}
for (ActivityManager.AppTask task : activityManager.getAppTasks()) {
task.finishAndRemoveTask();
}
}
}
示例8: quitApp
import android.app.ActivityManager; //导入方法依赖的package包/类
public static void quitApp(final Context context) {
if (Build.VERSION.SDK_INT >= 21) {
ActivityManager am = (ActivityManager) context.getSystemService("activity");
List appTasks = am.getAppTasks();
Iterator i$ = appTasks.iterator();
while (i$.hasNext()) {
ActivityManager.AppTask appTask = (ActivityManager.AppTask) i$.next();
appTask.finishAndRemoveTask();
}
Process.killProcess(Process.myPid());
am.killBackgroundProcesses(context.getPackageName());
System.exit(0);
} else if (Build.VERSION.SDK_INT >= 11) {
Intent activityManager = context.getPackageManager().getLaunchIntentForPackage(context.getPackageName());
activityManager.addFlags('喜');
activityManager.addFlags(268435456);
activityManager.addFlags(67108864);
activityManager.addFlags(65536);
activityManager.addFlags(8388608);
context.startActivity(activityManager);
(new Handler(Looper.getMainLooper())).postDelayed(new Runnable() {
public void run() {
Process.killProcess(Process.myPid());
System.exit(0);
}
}, 300L);
} else {
Process.killProcess(Process.myPid());
ActivityManager activityManager1 = (ActivityManager) context.getSystemService("activity");
activityManager1.killBackgroundProcesses(context.getPackageName());
System.exit(0);
}
}
示例9: getTask
import android.app.ActivityManager; //导入方法依赖的package包/类
private ActivityManager.AppTask getTask(boolean isIncognito, int tabId) {
Context context = ContextUtils.getApplicationContext();
ActivityManager activityManager =
(ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
for (ActivityManager.AppTask task : activityManager.getAppTasks()) {
Intent intent = DocumentUtils.getBaseIntentFromTask(task);
int taskId = getTabIdFromIntent(intent);
if (taskId == tabId && isValidActivity(isIncognito, intent)) return task;
}
return null;
}
示例10: isIncognitoDocumentAccessibleToUser
import android.app.ActivityManager; //导入方法依赖的package包/类
@Override
public boolean isIncognitoDocumentAccessibleToUser() {
Context context = ContextUtils.getApplicationContext();
ActivityManager activityManager =
(ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
for (ActivityManager.AppTask task : activityManager.getAppTasks()) {
Intent intent = DocumentUtils.getBaseIntentFromTask(task);
if (isValidActivity(true, intent)) return true;
}
return false;
}
示例11: getLargestTaskIdFromRecents
import android.app.ActivityManager; //导入方法依赖的package包/类
private int getLargestTaskIdFromRecents() {
int biggestId = Tab.INVALID_TAB_ID;
Context context = ContextUtils.getApplicationContext();
ActivityManager activityManager =
(ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
for (ActivityManager.AppTask task : activityManager.getAppTasks()) {
RecentTaskInfo info = DocumentUtils.getTaskInfoFromTask(task);
if (info == null) continue;
biggestId = Math.max(biggestId, info.persistentId);
}
return biggestId;
}
示例12: finishAllDocumentActivities
import android.app.ActivityManager; //导入方法依赖的package包/类
/**
* Finishes all DocumentActivities that appear in Android's Recents.
*/
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public void finishAllDocumentActivities() {
Context context = ContextUtils.getApplicationContext();
ActivityManager activityManager =
(ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
for (ActivityManager.AppTask task : activityManager.getAppTasks()) {
Intent intent = DocumentUtils.getBaseIntentFromTask(task);
if (isValidActivity(false, intent) || isValidActivity(true, intent)) {
task.finishAndRemoveTask();
}
}
}
示例13: finishAndRemoveTasks
import android.app.ActivityManager; //导入方法依赖的package包/类
private static Intent finishAndRemoveTasks(List<ActivityManager.AppTask> tasksToFinish) {
Intent removedIntent = null;
for (ActivityManager.AppTask task : tasksToFinish) {
Log.d(TAG, "Removing task with duplicated data: " + task);
removedIntent = getBaseIntentFromTask(task);
task.finishAndRemoveTask();
}
return removedIntent;
}
示例14: moveTaskToFront
import android.app.ActivityManager; //导入方法依赖的package包/类
@Override
public void moveTaskToFront(boolean isIncognito, int tabId) {
ActivityManager.AppTask task = getTask(isIncognito, tabId);
if (task != null) task.moveToFront();
}
示例15: finishAndRemoveTask
import android.app.ActivityManager; //导入方法依赖的package包/类
@Override
public void finishAndRemoveTask(boolean isIncognito, int tabId) {
ActivityManager.AppTask task = getTask(isIncognito, tabId);
if (task != null) task.finishAndRemoveTask();
}