本文整理匯總了Java中android.app.ActivityManager.getRunningTasks方法的典型用法代碼示例。如果您正苦於以下問題:Java ActivityManager.getRunningTasks方法的具體用法?Java ActivityManager.getRunningTasks怎麽用?Java ActivityManager.getRunningTasks使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.app.ActivityManager
的用法示例。
在下文中一共展示了ActivityManager.getRunningTasks方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: isTopActivity
import android.app.ActivityManager; //導入方法依賴的package包/類
/**
* 判斷某個包名是否運行在頂層
*
* @param context
* @param packageName
* @return
*/
public static Boolean isTopActivity(Context context, String packageName) {
if (context == null || TextUtils.isEmpty(packageName)) {
return null;
}
ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
List<ActivityManager.RunningTaskInfo> tasksInfo = activityManager.getRunningTasks(1);
if (tasksInfo == null || tasksInfo.isEmpty()) {
return null;
}
try {
return packageName.equals(tasksInfo.get(0).topActivity.getPackageName());
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
示例2: isTopActivity
import android.app.ActivityManager; //導入方法依賴的package包/類
/**
* whether the app whost package's name is packageName is on the top of the stack
* <ul>
* <strong>Attentions:</strong>
* <li>You should add <strong>android.permission.GET_TASKS</strong> in manifest</li>
* </ul>
*
* @param context
* @param packageName
* @return if params error or task stack is null, return null, otherwise retun whether the app is on the top of
* stack
*/
public static Boolean isTopActivity(Context context, String packageName) {
if (context == null || packageName == null || packageName.length() == 0) {
return null;
}
ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
List<RunningTaskInfo> tasksInfo = activityManager.getRunningTasks(1);
if (tasksInfo == null || tasksInfo.size() == 0) {
return null;
}
try {
return packageName.equals(tasksInfo.get(0).topActivity.getPackageName());
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
示例3: getTopActicvityName
import android.app.ActivityManager; //導入方法依賴的package包/類
public static String getTopActicvityName(Context context)
{
String className="";
ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
List<ActivityManager.RunningTaskInfo> list = am.getRunningTasks(1);
if (list != null && list.size() > 0) {
ComponentName cpn = list.get(0).topActivity;
className = cpn.getClassName();
}
return className;
}
示例4: isAppAtBackground
import android.app.ActivityManager; //導入方法依賴的package包/類
/**
* 判斷當前應用程序處於前台還是後台
* @param context
* @return
* true:前台 false:後台
*/
private boolean isAppAtBackground(final Context context) {
ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
List<ActivityManager.RunningTaskInfo> tasks = am.getRunningTasks(1);
if (tasks.isEmpty()) {
ComponentName topActivity = tasks.get(0).topActivity;
if (topActivity.getPackageName().equals(context.getPackageName())) {
return true;
}
}
return false;
}
示例5: isRunningForeground
import android.app.ActivityManager; //導入方法依賴的package包/類
/** QQ是否運行在前台 */
private boolean isRunningForeground(Context context){
ActivityManager am = (ActivityManager)context.getSystemService(Context.ACTIVITY_SERVICE);
List<ActivityManager.RunningTaskInfo> tasks = am.getRunningTasks(1);
if(!tasks.isEmpty()){
String packageName = tasks.get(0).topActivity.getPackageName();
if(Config.PACKAGE_NAME_QQ.equals(packageName)){
return true ;
}
}
return false ;
}
示例6: isForeground
import android.app.ActivityManager; //導入方法依賴的package包/類
/**
* @param context
* @param className Activity Class Name
*/
public static boolean isForeground(Context context, String className) {
if (context == null || TextUtils.isEmpty(className)) {
return false;
}
ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
List<ActivityManager.RunningTaskInfo> list = am.getRunningTasks(1);
if (list != null && list.size() > 0) {
ComponentName cpn = list.get(0).topActivity;
if (className.equals(cpn.getClassName())) {
return true;
}
}
return false;
}
示例7: getTopActivityName
import android.app.ActivityManager; //導入方法依賴的package包/類
public String getTopActivityName(Context context) {
String topActivityClassName = null;
ActivityManager activityManager = (ActivityManager) (context
.getSystemService(Context.ACTIVITY_SERVICE));
List<RunningTaskInfo> runningTaskInfos = activityManager.getRunningTasks(1);
if (runningTaskInfos != null) {
ComponentName f = runningTaskInfos.get(0).topActivity;
topActivityClassName = f.getClassName();
}
return topActivityClassName;
}
示例8: getTopRunningTask
import android.app.ActivityManager; //導入方法依賴的package包/類
/**
* 獲取指定程序信息
*/
public static ActivityManager.RunningTaskInfo getTopRunningTask(Context context) {
try {
ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
// 得到當前正在運行的任務棧
List<ActivityManager.RunningTaskInfo> runningTasks = am.getRunningTasks(1);
// 得到前台顯示的任務棧
ActivityManager.RunningTaskInfo runningTaskInfo = runningTasks.get(0);
return runningTaskInfo;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
示例9: isApplicationBroughtToBackground
import android.app.ActivityManager; //導入方法依賴的package包/類
/**
*判斷當前應用程序處於前台還是後台
*/
public static boolean isApplicationBroughtToBackground(final Context context) {
ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
List<ActivityManager.RunningTaskInfo> tasks = am.getRunningTasks(1);
if (!tasks.isEmpty()) {
ComponentName topActivity = tasks.get(0).topActivity;
if (!topActivity.getPackageName().equals(context.getPackageName())) {
return true;
}
}
return false;
}
示例10: getTopActivity
import android.app.ActivityManager; //導入方法依賴的package包/類
/**
* 慎重使用此函數<br/>
* GET_TASK was deprecated in API level 21. No longer enforced
*/
public static String getTopActivity(final Context context) {
try {
ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
List<ActivityManager.RunningTaskInfo> tasks = am.getRunningTasks(1);
if (!tasks.isEmpty()) {
ComponentName topActivity = tasks.get(0).topActivity;
return topActivity.getClassName();
}
}catch (Exception ex){
ex.printStackTrace();
}
return "";
}
示例11: getTopActivityName
import android.app.ActivityManager; //導入方法依賴的package包/類
/**
* <一句話功能簡述> 獲取最上層的Activity包名
*
* @Description<功能詳細描述>
*
* @param context
* @return
* @LastModifiedDate:2015-9-6
* @author rqj
* @EditHistory:<修改內容><修改人>
*/
public static String getTopActivityName(Context context) {
String topActivityClassName = null;
ActivityManager activityManager = (ActivityManager) (context
.getSystemService(android.content.Context.ACTIVITY_SERVICE));
List<RunningTaskInfo> runningTaskInfos = activityManager
.getRunningTasks(1);
if (runningTaskInfos != null) {
ComponentName f = runningTaskInfos.get(0).topActivity;
topActivityClassName = f.getClassName();
}
return topActivityClassName;
}
示例12: reStart
import android.app.ActivityManager; //導入方法依賴的package包/類
/**
* 重新啟動
*/
public void reStart()
{
ActivityManager am = (ActivityManager) mContext.getSystemService(Context.ACTIVITY_SERVICE);
AlarmManager mgr = (AlarmManager) mContext.getSystemService(Context.ALARM_SERVICE);
List<RunningTaskInfo> taskInfos = am.getRunningTasks(Integer.MAX_VALUE);
RunningTaskInfo taskInfo = null;
ComponentName baseActivity = null;
String pkgName = null;
for (int i = 0, len = taskInfos.size(); i < len; i++)
{
taskInfo = taskInfos.get(i);
baseActivity = taskInfo.baseActivity;
pkgName = baseActivity.getPackageName();
if (pkgName.equalsIgnoreCase(mContext.getPackageName()))
{
ComponentName topActivity = taskInfo.topActivity;
if (!topActivity.getClassName().equalsIgnoreCase(baseActivity.getClassName()))
{
Intent intent = new Intent();
intent.setClassName(mContext, baseActivity.getClassName());
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent pendingIntent = PendingIntent.getActivity(mContext, 0, intent,
Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
mgr.set(AlarmManager.RTC, System.currentTimeMillis(), pendingIntent);
}
return;
}
}
}
示例13: getTopActivity
import android.app.ActivityManager; //導入方法依賴的package包/類
/**獲取頂層 Activity
* @param context
* @return
*/
public static String getTopActivity(Context context) {
ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
@SuppressWarnings("deprecation")
List<RunningTaskInfo> runningTaskInfos = manager.getRunningTasks(1);
return runningTaskInfos == null ? "" : runningTaskInfos.get(0).topActivity.getClassName();
}
示例14: isRunningForeground
import android.app.ActivityManager; //導入方法依賴的package包/類
/**
* need < uses-permission android:name =“android.permission.GET_TASKS” />
* 判斷是否前台運行
*/
public static boolean isRunningForeground(Context context) {
ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
List<ActivityManager.RunningTaskInfo> taskList = am.getRunningTasks(1);
if (taskList != null && !taskList.isEmpty()) {
ComponentName componentName = taskList.get(0).topActivity;
if (componentName != null && componentName.getPackageName().equals(context.getPackageName())) {
return true;
}
}
return false;
}
示例15: stackResumed
import android.app.ActivityManager; //導入方法依賴的package包/類
public static boolean stackResumed(Context context) {
ActivityManager manager = (ActivityManager) context
.getApplicationContext().getSystemService(
Context.ACTIVITY_SERVICE);
String packageName = context.getApplicationContext().getPackageName();
List<RunningTaskInfo> recentTaskInfos = manager.getRunningTasks(1);
if (recentTaskInfos != null && recentTaskInfos.size() > 0) {
RunningTaskInfo taskInfo = recentTaskInfos.get(0);
if (taskInfo.baseActivity.getPackageName().equals(packageName) && taskInfo.numActivities > 1) {
return true;
}
}
return false;
}