Java Code Examples for android.app.ActivityManager#moveTaskToFront()
The following examples show how to use
android.app.ActivityManager#moveTaskToFront() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BringToFrontReceiver.java From SweetMusicPlayer with Apache License 2.0 | 8 votes |
@Override public void onReceive(Context context, Intent intent) { Log.i(TAG, "#######################recieved###########################"); //获取ActivityManager ActivityManager mAm = (ActivityManager) context.getSystemService(context.ACTIVITY_SERVICE); //获得当前运行的task List<ActivityManager.RunningTaskInfo> taskList = mAm.getRunningTasks(100); for (ActivityManager.RunningTaskInfo rti : taskList) { //找到当前应用的task,并启动task的栈顶activity,达到程序切换到前台 if (rti.topActivity.getPackageName().equals(context.getPackageName())) { Log.i(TAG, "#######################front###########################"); mAm.moveTaskToFront(rti.id, ActivityManager.MOVE_TASK_WITH_HOME); return; } } //若没有找到运行的task,用户结束了task或被系统释放,则重新启动mainactivity Intent resultIntent = new Intent(context, MainActivity.class); resultIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP); context.startActivity(resultIntent); Log.i(TAG, "#######################end###########################"); }
Example 2
Source File: SystemUtils.java From shinny-futures-android with GNU General Public License v3.0 | 7 votes |
/** * 将本应用置顶到最前端 * 当本应用位于后台时,则将它切换到最前端 * * @param context */ public static void setTopApp(Context context) { /**获取ActivityManager*/ ActivityManager activityManager = (ActivityManager) context.getSystemService(ACTIVITY_SERVICE); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { List<ActivityManager.AppTask> list = activityManager.getAppTasks(); for (ActivityManager.AppTask appTask : list){ appTask.moveToFront(); break; } }else { /**获得当前运行的task(任务)*/ List<ActivityManager.RunningTaskInfo> taskInfoList = activityManager.getRunningTasks(100); for (ActivityManager.RunningTaskInfo taskInfo : taskInfoList) { /**找到本应用的 task,并将它切换到前台*/ if (taskInfo.topActivity.getPackageName().equals(context.getPackageName())) { activityManager.moveTaskToFront(taskInfo.id, 0); break; } } } }
Example 3
Source File: PushNotificationReceiver.java From letv with Apache License 2.0 | 6 votes |
@SuppressLint({"NewApi"}) public static boolean isAppOnForeground(Context mContext) { ActivityManager activityManager = (ActivityManager) mContext.getSystemService("activity"); String packageName = mContext.getPackageName(); LogInfo.log("PushReceiver", "packageName =" + packageName); List<RunningAppProcessInfo> appProcesses = activityManager.getRunningAppProcesses(); if (appProcesses == null) { LogInfo.log("PushReceiver", "------appProcesses == null-----"); return false; } for (RunningAppProcessInfo appProcess : appProcesses) { LogInfo.log("PushReceiver", "------appProcess.processName =" + appProcess.processName); if (appProcess.processName.equals(packageName) && appProcess.importance == 100) { for (RunningTaskInfo rti : activityManager.getRunningTasks(100)) { if (!(rti == null || rti.baseActivity == null || mContext.getPackageName() == null || !mContext.getPackageName().equals(rti.baseActivity.getPackageName()) || VERSION.SDK_INT < 11)) { activityManager.moveTaskToFront(rti.id, 1); } } return true; } } return false; }
Example 4
Source File: PackageManagerUtil.java From BaseProject with Apache License 2.0 | 6 votes |
@SuppressLint("MissingPermission") public static void moveAppTaskToFront(Context context) { /**获取ActivityManager*/ ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); if (activityManager == null) { return; } /**获得当前运行的task(任务)*/ List<ActivityManager.RunningTaskInfo> taskInfoList = activityManager.getRunningTasks(100); for (ActivityManager.RunningTaskInfo taskInfo : taskInfoList) { /**找到本应用的 task,并将它切换到前台*/ if (taskInfo.topActivity.getPackageName().equals(context.getPackageName())) { activityManager.moveTaskToFront(taskInfo.id, 0); break; } } }
Example 5
Source File: LauncherApplication.java From SoloPi with Apache License 2.0 | 5 votes |
/** * 返回SoloPi */ public void moveSelfToFront() { int contextFrom = 0; // 一级一级加载Context Context context = loadActivityOnTop(); if (context == null) { context = loadRunningService(); contextFrom = 1; } if (context == null) { context = getApplicationContext(); contextFrom = 2; } if (contextFrom != 0) { //获取ActivityManager ActivityManager mAm = (ActivityManager) getSystemService(ACTIVITY_SERVICE); //获得当前运行的task List<ActivityManager.RunningTaskInfo> taskList = mAm.getRunningTasks(100); for (ActivityManager.RunningTaskInfo rti : taskList) { //找到当前应用的task,并启动task的栈顶activity,达到程序切换到前台 if (rti.topActivity.getPackageName().equals(getPackageName())) { mAm.moveTaskToFront(rti.id, 0); return; } } // pending intent跳回去 Intent intent = getPackageManager().getLaunchIntentForPackage(getPackageName()); PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); try { pendingIntent.send(); } catch (PendingIntent.CanceledException e) { LogUtil.e(TAG, "Catch android.app.PendingIntent.CanceledException: " + e.getMessage(), e); } } }
Example 6
Source File: MainActivity.java From NXLoader with MIT License | 5 votes |
@Override public void onReceive(Context context, Intent intent) { Bundle bundle = intent.getExtras(); String msg = bundle.getString("msg"); logFragment.appendLog(msg); // switch to foreground if (!(context instanceof MainActivity)) { ActivityManager activityManager = (ActivityManager) context.getSystemService(Service.ACTIVITY_SERVICE); activityManager.moveTaskToFront(getTaskId(), 0); } }
Example 7
Source File: AppCompatDlalog.java From stynico with MIT License | 5 votes |
/** * 将当前应用运行到前台 */ private void bring2Front() { ActivityManager activtyManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE); List<ActivityManager.RunningTaskInfo> runningTaskInfos = activtyManager.getRunningTasks(3); for (ActivityManager.RunningTaskInfo runningTaskInfo : runningTaskInfos) { if (this.getPackageName().equals(runningTaskInfo.topActivity.getPackageName())) { activtyManager.moveTaskToFront(runningTaskInfo.id, ActivityManager.MOVE_TASK_WITH_HOME); return; } } }
Example 8
Source File: VerifyOTP.java From XERUNG with Apache License 2.0 | 5 votes |
@Override protected void onPause() { LocalBroadcastManager.getInstance(this).unregisterReceiver(mRegistrationBroadcastReceiver); isReceiverRegistered = false; ActivityManager activityManager = (ActivityManager) getApplicationContext().getSystemService(Context.ACTIVITY_SERVICE); activityManager.moveTaskToFront(getTaskId(), 0); super.onPause(); }
Example 9
Source File: VerifyOTP.java From XERUNG with Apache License 2.0 | 5 votes |
@Override protected void onPause() { LocalBroadcastManager.getInstance(this).unregisterReceiver(mRegistrationBroadcastReceiver); isReceiverRegistered = false; ActivityManager activityManager = (ActivityManager) getApplicationContext().getSystemService(Context.ACTIVITY_SERVICE); activityManager.moveTaskToFront(getTaskId(), 0); super.onPause(); }
Example 10
Source File: PushNotificationReceiver.java From letv with Apache License 2.0 | 5 votes |
@SuppressLint({"NewApi"}) private void pushLiveOver() { LetvConstant.setForcePlay(false); StatisticsUtils.setActionProperty(NetworkUtils.DELIMITER_LINE, -1, NetworkUtils.DELIMITER_LINE); if (MainActivity.getInstance() != null) { if (this.isShowToast) { UIsUtils.showToast(TipUtils.getTipMessage("70004", 2131100703)); } ActivityManager am = (ActivityManager) this.mContext.getSystemService("activity"); for (RunningTaskInfo rti : am.getRunningTasks(100)) { if (!(rti == null || rti.baseActivity == null || this.mContext.getPackageName() == null || !this.mContext.getPackageName().equals(rti.baseActivity.getPackageName()))) { if (VERSION.SDK_INT >= 11) { am.moveTaskToFront(rti.id, 1); } LogInfo.log("push_", "moveTaskToFront rti.id = " + rti.id); } } if (TextUtils.isEmpty(this.cid)) { MainLaunchUtils.launch(MainActivity.getInstance(), true); } else if (!(this.cid.equals("3") || this.cid.equals("8") || this.cid.equals("4") || this.cid.equals("9"))) { MainLaunchUtils.launch(MainActivity.getInstance(), true); } LogInfo.log("push_", "pushLiveOver live pushCid " + this.cid); return; } if (TextUtils.isEmpty(this.cid)) { MainLaunchUtils.launch(this.mContext, true); } else if (this.cid.equals("3")) { MainLaunchUtils.launchGotoLive(this.mContext, "ent", null, this.isShowToast, true); } else if (this.cid.equals("8")) { MainLaunchUtils.launchGotoLive(this.mContext, "other", null, this.isShowToast, true); } else if (this.cid.equals("4")) { MainLaunchUtils.launchGotoLive(this.mContext, "sports", null, this.isShowToast, true); } else if (this.cid.equals("9")) { MainLaunchUtils.launchGotoLive(this.mContext, "music", null, this.isShowToast, true); } else { MainLaunchUtils.launch(this.mContext, true); } LogInfo.log("push_", "pushLiveOver MainActivity.getInstance() == null no jump to live"); }
Example 11
Source File: KioskActivity.java From cordova-plugin-kiosk with Apache License 2.0 | 5 votes |
@Override protected void onPause() { super.onPause(); ActivityManager activityManager = (ActivityManager) getApplicationContext() .getSystemService(Context.ACTIVITY_SERVICE); activityManager.moveTaskToFront(getTaskId(), 0); }