本文整理汇总了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;
}