本文整理匯總了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();
}