当前位置: 首页>>代码示例>>Java>>正文


Java ActivityManager.getRunningTasks方法代码示例

本文整理汇总了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;
    }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:25,代码来源:Kits.java

示例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;
    }
}
 
开发者ID:lizhangqu,项目名称:CorePatch,代码行数:30,代码来源:PackageUtils.java

示例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;
}
 
开发者ID:dufangyu1990,项目名称:JKApp,代码行数:12,代码来源:ActivityControl.java

示例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;
}
 
开发者ID:LanguidSheep,项目名称:sealtalk-android-master,代码行数:18,代码来源:WindowService.java

示例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 ;
}
 
开发者ID:A-Miracle,项目名称:QiangHongBao,代码行数:13,代码来源:QQAccessibilityJob.java

示例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;
}
 
开发者ID:socoolby,项目名称:CoolClock,代码行数:19,代码来源:FuncUnit.java

示例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;
}
 
开发者ID:junchenChow,项目名称:exciting-app,代码行数:12,代码来源:ConfigApplication.java

示例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;
}
 
开发者ID:jeasinlee,项目名称:AndroidBasicLibs,代码行数:17,代码来源:PackageUtil.java

示例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;
}
 
开发者ID:liu-xiao-dong,项目名称:JD-Test,代码行数:15,代码来源:AppTaskUtil.java

示例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 "";
}
 
开发者ID:waylife,项目名称:ViewDebugHelper,代码行数:18,代码来源:ActivityHelper.java

示例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;
}
 
开发者ID:zhuyu1022,项目名称:amap,代码行数:24,代码来源:AppPackageUtil.java

示例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;
		}
	}
}
 
开发者ID:benniaobuguai,项目名称:android-project-gallery,代码行数:36,代码来源:CrashHandler.java

示例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();
}
 
开发者ID:TommyLemon,项目名称:APIJSON-Android-RxJava,代码行数:12,代码来源:CommonUtil.java

示例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;
}
 
开发者ID:jqjm,项目名称:Liteframework,代码行数:16,代码来源:AppUtil.java

示例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;
}
 
开发者ID:newDeepLearing,项目名称:decoy,代码行数:16,代码来源:SysInfoUtil.java


注:本文中的android.app.ActivityManager.getRunningTasks方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。