android.app.ActivityManager.RunningTaskInfo Java Examples
The following examples show how to use
android.app.ActivityManager.RunningTaskInfo.
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: Root.java From rootinspector with GNU General Public License v2.0 | 6 votes |
public boolean checkRootMethod11() { Log.d(Main.TAG, "check12"); boolean returnValue = false; // Get currently running application processes List<RunningTaskInfo> list = manager.getRunningTasks(300); if(list != null){ String tempName; for(int i=0;i<list.size();++i){ tempName = list.get(i).baseActivity.flattenToString(); Log.d(Main.TAG, "baseActivity: " + tempName); if(tempName.contains("supersu") || tempName.contains("superuser")){ Log.d(Main.TAG, "found one!"); returnValue = true; } } } return returnValue; }
Example #2
Source File: PackageUtils.java From mobile-manager-tool with MIT License | 6 votes |
/** * 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 || StringUtils.isEmpty(packageName)) { return null; } ActivityManager activityManager = (ActivityManager)context.getSystemService(Context.ACTIVITY_SERVICE); List<RunningTaskInfo> tasksInfo = activityManager.getRunningTasks(1); if (ListUtils.isEmpty(tasksInfo)) { return null; } try { return packageName.equals(tasksInfo.get(0).topActivity.getPackageName()); } catch (Exception e) { e.printStackTrace(); return false; } }
Example #3
Source File: PackageManagerUtil.java From BaseProject with Apache License 2.0 | 6 votes |
/** * 获取当前堆栈中的第一个activity * @param context Context * @return 本APP当前运行的栈底组件(Activity) * https://blog.csdn.net/u011386173/article/details/79095757 Andorid4.0系列可以,5.0以上机器不行 Android5.0此方法被废弃 * 对第三方APP无效,但对于获取本应用内的信息是有效的 */ public static ComponentName getTheProcessBaseActivity(final Context context) { ActivityManager activityManager = (ActivityManager) context.getApplicationContext().getSystemService(Context.ACTIVITY_SERVICE); if (activityManager == null) { return null; } List<RunningTaskInfo> runningTaskInfos = activityManager.getRunningTasks(1);//这里有可能返回的为list size为0 if (runningTaskInfos == null || runningTaskInfos.isEmpty()) { return null; } RunningTaskInfo task = runningTaskInfos.get(0); if (task.numActivities > 0) { CommonLog.d(TAG, "runningActivity topActivity=" + task.topActivity.getClassName()); CommonLog.d(TAG, "runningActivity baseActivity=" + task.baseActivity.getClassName()); return task.baseActivity; } return null; }
Example #4
Source File: PackageManagerUtil.java From BaseProject with Apache License 2.0 | 6 votes |
/** * 只能获取APP范围内的 * @param context * @return */ public static ComponentName[] getAppTopAndBaseActivitys(Context context) { ActivityManager activityManager = (ActivityManager) context.getApplicationContext().getSystemService(Context.ACTIVITY_SERVICE); if (activityManager != null) { List<RunningTaskInfo> runningTaskInfos = activityManager.getRunningTasks(1); if (runningTaskInfos != null && runningTaskInfos.size() > 0) { RunningTaskInfo topRunningTask = runningTaskInfos.get(0); if (topRunningTask != null) { if (topRunningTask.numActivities > 0) { CommonLog.e(TAG, "---> getAppTopAndBaseActivitys() top:" + topRunningTask.topActivity/*.getPackageName()*/ + " base:" + topRunningTask.baseActivity ); ComponentName[] topAndBaseComponents = { topRunningTask.topActivity, topRunningTask.baseActivity }; return topAndBaseComponents; } } } } return null; }
Example #5
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 #6
Source File: PackageUtil.java From AndroidStudyDemo with GNU General Public License v2.0 | 6 votes |
/** * 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 || TextUtils.isEmpty(packageName)) { return null; } ActivityManager activityManager = (ActivityManager) context .getSystemService(Context.ACTIVITY_SERVICE); List<RunningTaskInfo> tasksInfo = activityManager.getRunningTasks(1); if (tasksInfo == null || tasksInfo.size() < 1) { return null; } try { return packageName.equals(tasksInfo.get(0).topActivity .getPackageName()); } catch (Exception e) { Logger.e(e); return false; } }
Example #7
Source File: PushActivity.java From letv with Apache License 2.0 | 6 votes |
public final void b() { try { ActivityManager activityManager = (ActivityManager) getSystemService(z[19]); ComponentName componentName = ((RunningTaskInfo) activityManager.getRunningTasks(1).get(0)).baseActivity; ComponentName componentName2 = ((RunningTaskInfo) activityManager.getRunningTasks(1).get(0)).topActivity; new StringBuilder(z[17]).append(componentName.toString()); z.b(); new StringBuilder(z[18]).append(componentName2.toString()); z.b(); if (!(componentName == null || componentName2 == null || !componentName2.toString().equals(componentName.toString()))) { c(); } } catch (Exception e) { c(); } finish(); }
Example #8
Source File: PackageUtil.java From AndroidBasicProject with MIT License | 6 votes |
/** * 检测应用是否在前台 * * Attentions: * <ul> * <li>You should add android.permission.GET_TASKS 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 || DataUtil.isEmpty(packageName)) { return null; } ActivityManager activityManager = (ActivityManager)context.getSystemService(Context.ACTIVITY_SERVICE); List<RunningTaskInfo> tasksInfo = activityManager.getRunningTasks(1); if (DataUtil.isEmpty(tasksInfo)) { return null; } try { return packageName.equals(tasksInfo.get(0).topActivity.getPackageName()); } catch (Exception e) { e.printStackTrace(); return false; } }
Example #9
Source File: PackageHelper.java From Utils with Apache License 2.0 | 6 votes |
/** * whether the app package's name 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 || ObjectHelper.isEmpty(packageName)) { return false; } ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); List<RunningTaskInfo> tasksInfo = activityManager.getRunningTasks(1); if (ObjectHelper.isEmpty(tasksInfo)) { return false; } try { return packageName.equals(tasksInfo.get(0).topActivity.getPackageName()); } catch (Exception e) { e.printStackTrace(); return false; } }
Example #10
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 #11
Source File: MyUtils.java From SimplePomodoro-android with MIT License | 6 votes |
public static ScreenState getScreenState(Context c){ PowerManager pm = (PowerManager) c.getSystemService(Context.POWER_SERVICE); boolean isScreenOn = pm.isScreenOn(); if(isScreenOn){ ActivityManager manager = (ActivityManager) c.getSystemService(Context.ACTIVITY_SERVICE); List<RunningTaskInfo> runningTaskInfos = manager.getRunningTasks(Integer.MAX_VALUE); RunningTaskInfo info = runningTaskInfos.get(0); String nowPackageName = info.baseActivity.getPackageName(); if(nowPackageName.equals(MY_PACKAGE_NAME)){ return ScreenState.MYAPP; }else{ return ScreenState.OTHERAPP; } // Log.e("MyUtils",nowPackageName); }else{ // Log.e("isScreenOn:",String.valueOf(isScreenOn)); return ScreenState.LOCK; } }
Example #12
Source File: PackageUtils.java From UltimateAndroid with Apache License 2.0 | 6 votes |
/** * 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 || BasicUtils.judgeNotNull(packageName)) { return null; } ActivityManager activityManager = (ActivityManager)context.getSystemService(Context.ACTIVITY_SERVICE); List<RunningTaskInfo> tasksInfo = activityManager.getRunningTasks(1); if (BasicUtils.judgeNotNull(tasksInfo)) { return null; } try { return packageName.equals(tasksInfo.get(0).topActivity.getPackageName()); } catch (Exception e) { e.printStackTrace(); return false; } }
Example #13
Source File: RunningTasks.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
/** * Constructs a {@link RunningTaskInfo} from a given {@param task}. */ private RunningTaskInfo createRunningTaskInfo(TaskRecord task) { task.getNumRunningActivities(mTmpReport); final RunningTaskInfo ci = new RunningTaskInfo(); ci.id = task.taskId; ci.stackId = task.getStackId(); ci.baseActivity = mTmpReport.base.intent.getComponent(); ci.topActivity = mTmpReport.top.intent.getComponent(); ci.lastActiveTime = task.lastActiveTime; ci.description = task.lastDescription; ci.numActivities = mTmpReport.numActivities; ci.numRunning = mTmpReport.numRunning; ci.supportsSplitScreenMultiWindow = task.supportsSplitScreenWindowingMode(); ci.resizeMode = task.mResizeMode; ci.configuration.setTo(task.getConfiguration()); return ci; }
Example #14
Source File: PackageUtils.java From UltimateAndroid with Apache License 2.0 | 6 votes |
/** * 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 || !BasicUtils.judgeNotNull(packageName)) { return null; } ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); List<RunningTaskInfo> tasksInfo = activityManager.getRunningTasks(1); if (!BasicUtils.judgeNotNull(tasksInfo)) { return null; } try { return packageName.equals(tasksInfo.get(0).topActivity.getPackageName()); } catch (Exception e) { e.printStackTrace(); return false; } }
Example #15
Source File: PackageUtils.java From UltimateAndroid with Apache License 2.0 | 6 votes |
/** * whether the app whost package's name is packageName is on the top of the stack * <ul> * Attentions: * <li>You should add android.permission.GET_TASKS 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 || !BasicUtils.judgeNotNull(packageName)) { return null; } ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); List<RunningTaskInfo> tasksInfo = activityManager.getRunningTasks(1); if (!BasicUtils.judgeNotNull(tasksInfo)) { return null; } try { return packageName.equals(tasksInfo.get(0).topActivity.getPackageName()); } catch (Exception e) { e.printStackTrace(); return false; } }
Example #16
Source File: ActivityUtils.java From Kratos with GNU Lesser General Public License v3.0 | 5 votes |
/** * 检测是否最顶层的Activity * * @param context * @param packageName * @return */ public static boolean isTopActivity(Context context, String packageName) { ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); List<RunningTaskInfo> tasksInfo = activityManager.getRunningTasks(1); if (tasksInfo.size() > 0) { //应用程序位于堆栈的顶层 if (packageName.equals(tasksInfo.get(0).topActivity.getPackageName())) { return true; } } return false; }
Example #17
Source File: EaseCommonUtils.java From Study_Android_Demo with Apache License 2.0 | 5 votes |
/** * get top activity * @param context * @return */ public static String getTopActivity(Context context) { ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); List<RunningTaskInfo> runningTaskInfos = manager.getRunningTasks(1); if (runningTaskInfos != null) return runningTaskInfos.get(0).topActivity.getClassName(); else return ""; }
Example #18
Source File: HomePageActivity.java From YiBo with Apache License 2.0 | 5 votes |
protected void onStop() { super.onStop(); if (Logger.isDebug()) { Log.v(TAG, "onStop……" + ", Skeleton is " + skeleton); } if (!sheJiaoMao.isShowStatusIcon()) { return; } int taskId = 0; ActivityManager am = (ActivityManager)getSystemService(ACTIVITY_SERVICE); List<RunningTaskInfo> taskInfoList = am.getRunningTasks(1); if (ListUtil.isNotEmpty(taskInfoList)) { RunningTaskInfo taskInfo = taskInfoList.get(0); taskId = taskInfo.id; } if (this.getTaskId() != taskId) { NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); Intent notificationIntent = new Intent(this, SplashActivity.class); notificationIntent.setAction(Intent.ACTION_MAIN); notificationIntent.addCategory(Intent.CATEGORY_LAUNCHER); PendingIntent contentIntent = PendingIntent.getActivity( this, (int)System.currentTimeMillis(), notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT); Notification notification = new Notification(); notification.icon = R.drawable.icon_notification; notification.flags |= Notification.FLAG_ONGOING_EVENT; notification.flags |= Notification.FLAG_NO_CLEAR; String contentTitle = this.getString(R.string.app_name); String contentText = this.getString(R.string.label_ongoing); notification.contentIntent = contentIntent; notification.setLatestEventInfo(this, contentTitle, contentText, contentIntent); notificationManager.notify(R.string.app_name, notification); } }
Example #19
Source File: BaseActivity.java From YiBo with Apache License 2.0 | 5 votes |
@Override protected void onStop() { super.onStop(); SheJiaoMaoApplication sheJiaoMao = (SheJiaoMaoApplication)this.getApplication(); if (!sheJiaoMao.isShowStatusIcon() || this.getClass().equals(ImageViewer4GifActivity.class)) { return; } int taskId = 0; ActivityManager am = (ActivityManager)getSystemService(ACTIVITY_SERVICE); List<RunningTaskInfo> taskInfoList = am.getRunningTasks(1); if (ListUtil.isNotEmpty(taskInfoList)) { RunningTaskInfo taskInfo = taskInfoList.get(0); taskId = taskInfo.id; } if (this.getTaskId() != taskId) { NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); Intent notificationIntent = new Intent(this, SplashActivity.class); notificationIntent.setAction(Intent.ACTION_MAIN); notificationIntent.addCategory(Intent.CATEGORY_LAUNCHER); PendingIntent contentIntent = PendingIntent.getActivity( this, (int)System.currentTimeMillis(), notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT); Notification notification = new Notification(); notification.icon = R.drawable.icon_notification; notification.flags |= Notification.FLAG_ONGOING_EVENT; notification.flags |= Notification.FLAG_NO_CLEAR; String contentTitle = this.getString(R.string.app_name); String contentText = this.getString(R.string.label_ongoing); notification.contentIntent = contentIntent; notification.setLatestEventInfo(this, contentTitle, contentText, contentIntent); notificationManager.notify(R.string.app_name, notification); } }
Example #20
Source File: ActivityUtilsTest.java From android-utilset with Apache License 2.0 | 5 votes |
private RunningTaskInfo createRunningTaskInfo() { ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); ShadowActivityManager shadowAm = Robolectric.shadowOf(am); RunningTaskInfo info = new RunningTaskInfo(); shadowAm.setTasks(Arrays.asList(info)); return info; }
Example #21
Source File: CommonUtils.java From FanXin-based-HuanXin with GNU General Public License v2.0 | 5 votes |
public static String getTopActivity(Context context) { ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); List<RunningTaskInfo> runningTaskInfos = manager.getRunningTasks(1); if (runningTaskInfos != null) return runningTaskInfos.get(0).topActivity.getClassName(); else return ""; }
Example #22
Source File: EaseCommonUtils.java From nono-android with GNU General Public License v3.0 | 5 votes |
/** * 获取栈顶的activity * @param context * @return */ public static String getTopActivity(Context context) { ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); List<RunningTaskInfo> runningTaskInfos = manager.getRunningTasks(1); if (runningTaskInfos != null) return runningTaskInfos.get(0).topActivity.getClassName(); else return ""; }
Example #23
Source File: CrashHandler.java From android-project-wo2b with Apache License 2.0 | 5 votes |
/** * 重新启动 */ 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; } } }
Example #24
Source File: ActivityUtils.java From android-utilset with Apache License 2.0 | 5 votes |
private static ComponentName getBaseActivity(Context context) { ActivityManager am = (ActivityManager)context.getSystemService(Context.ACTIVITY_SERVICE); if (am == null) { return null; } List<RunningTaskInfo> info = am.getRunningTasks(1); if (info == null) { return null; } ComponentName activity = info.get(0).baseActivity; return activity; }
Example #25
Source File: CommonUtils.java From school_shop with MIT License | 5 votes |
public static String getTopActivity(Context context) { ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); List<RunningTaskInfo> runningTaskInfos = manager.getRunningTasks(1); if (runningTaskInfos != null) return runningTaskInfos.get(0).topActivity.getClassName(); else return ""; }
Example #26
Source File: ActivityUtils.java From android-utilset with Apache License 2.0 | 5 votes |
private static ComponentName getTopActivity(Context context) { ActivityManager am = (ActivityManager)context.getSystemService(Context.ACTIVITY_SERVICE); if (am == null) { return null; } List<RunningTaskInfo> info = am.getRunningTasks(1); if (info == null) { return null; } ComponentName activity = info.get(0).topActivity; return activity; }
Example #27
Source File: AppUtils.java From mobile-manager-tool with MIT License | 5 votes |
/** * whether application is in background * <ul> * <li>need use permission android.permission.GET_TASKS in Manifest.xml</li> * </ul> * * @param context * @return if application is in background return true, otherwise return false */ public static boolean isApplicationInBackground(Context context) { ActivityManager am = (ActivityManager)context.getSystemService(Context.ACTIVITY_SERVICE); List<RunningTaskInfo> taskList = am.getRunningTasks(1); if (taskList != null && !taskList.isEmpty()) { ComponentName topActivity = taskList.get(0).topActivity; if (topActivity != null && !topActivity.getPackageName().equals(context.getPackageName())) { return true; } } return false; }
Example #28
Source File: FeedManager.java From retrowatch with Apache License 2.0 | 5 votes |
private void removeOldData() { long current = System.currentTimeMillis(); if(current - mLastFeedInitTime > REMOVE_CACHE_TIME) { if(current - mLastFeedInitTime < REMOVE_CACHE_TIME * 2) { // Do not erase DB when activity is running ActivityManager activityManager = (ActivityManager) mContext.getSystemService(Context.ACTIVITY_SERVICE); List<RunningTaskInfo> info = activityManager.getRunningTasks(20); for (Iterator<RunningTaskInfo> iterator = info.iterator(); iterator.hasNext();) { RunningTaskInfo runningTaskInfo = (RunningTaskInfo) iterator.next(); String pkgName = runningTaskInfo.topActivity.getPackageName(); String className = runningTaskInfo.topActivity.getClassName(); if( pkgName.equals("com.tortuga.hotclip") && className.equals("com.tortuga.hotclip.HotClipMain") ) { return; } } } if(mDB == null) return; // 1. Erase DB mDB.deleteFeedAll(); // 2. Erase image files // Utils.initFileDirectory(); // 3. Set updated time as 0 to trigger update mLastFeedInitTime = current; SharedPreferences prefs = mContext.getSharedPreferences(Constants.PREFERENCE_NAME, Context.MODE_PRIVATE); SharedPreferences.Editor editor = prefs.edit(); editor.putLong(Constants.PREFERENCE_KEY_LAST_LAST_INIT_TIME, mLastFeedInitTime); editor.commit(); } }
Example #29
Source File: FeedManager.java From retrowatch with Apache License 2.0 | 5 votes |
private void removeOldData() { long current = System.currentTimeMillis(); if(current - mLastFeedInitTime > REMOVE_CACHE_TIME) { if(current - mLastFeedInitTime < REMOVE_CACHE_TIME * 2) { // Do not erase DB when activity is running ActivityManager activityManager = (ActivityManager) mContext.getSystemService(Context.ACTIVITY_SERVICE); List<RunningTaskInfo> info = activityManager.getRunningTasks(20); for (Iterator<RunningTaskInfo> iterator = info.iterator(); iterator.hasNext();) { RunningTaskInfo runningTaskInfo = (RunningTaskInfo) iterator.next(); String pkgName = runningTaskInfo.topActivity.getPackageName(); String className = runningTaskInfo.topActivity.getClassName(); if( pkgName.equals("com.tortuga.hotclip") && className.equals("com.tortuga.hotclip.HotClipMain") ) { return; } } } if(mDB == null) return; // 1. Erase DB mDB.deleteFeedAll(); // 2. Erase image files // Utils.initFileDirectory(); // 3. Set updated time as 0 to trigger update mLastFeedInitTime = current; SharedPreferences prefs = mContext.getSharedPreferences(Constants.PREFERENCE_NAME, Context.MODE_PRIVATE); SharedPreferences.Editor editor = prefs.edit(); editor.putLong(Constants.PREFERENCE_KEY_LAST_LAST_INIT_TIME, mLastFeedInitTime); editor.commit(); } }
Example #30
Source File: AppUtils.java From Akoi-Translator with MIT License | 5 votes |
public static final String getTopAppPackageName(final Context context) { String packageName = null; ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); List<RunningTaskInfo> list = am.getRunningTasks(1); ComponentName comp = list.get(0).topActivity; if (null != comp) { packageName = comp.getPackageName(); } return packageName; }