Code example for ActivityManager

Methods: getRunningTasks

    static void handleApplicationClosing(final Context context, int keyCode) {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
            ActivityManager am = (ActivityManager) context
            List<RunningTaskInfo> tasks = am.getRunningTasks(2);
            RunningTaskInfo currentTask = tasks.get(0);
            RunningTaskInfo nextTask = tasks.get(1);
            // if we're looking at this application's base/launcher Activity, 
            // and the next task is the Android home screen, then we know we're 
            // about to close the app 
            if (currentTask.topActivity.equals(currentTask.baseActivity)
                    && nextTask.baseActivity.getPackageName().startsWith("")) {
                DroidFuApplication application = (DroidFuApplication) context
Experience pair programming with AI  Get Codota for Java