2

I've used GET_TASKS permission in my app in order to get previous intent.

private Intent getPreviousIntent(Intent newIntent) {
    final ActivityManager am = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
    final List<ActivityManager.RecentTaskInfo> recentTaskInfos = am.getRecentTasks(1024,0);
    String myPkgNm = getPackageName();

    if (!recentTaskInfos.isEmpty()) {
        ActivityManager.RecentTaskInfo recentTaskInfo;
        for (int i = 0; i < recentTaskInfos.size(); i++) {
            recentTaskInfo = recentTaskInfos.get(i);
            if (recentTaskInfo.baseIntent.getComponent().getPackageName().equals(myPkgNm)) {
                newIntent = recentTaskInfo.baseIntent;
                newIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            }
        }
    }
    return newIntent;
}

In api level 21 getAppTasks is added instead of getRecentTasks.It is ok but the question is that how can i get previous intent lower than api level 21? Please help me in order to solve this issue?

nAkhmedov
  • 3,522
  • 4
  • 37
  • 72
  • 1
    You can check the API Level on running device and use for lower getAppTasks...http://stackoverflow.com/questions/3093365/how-can-i-check-the-system-version-of-android – Opiatefuchs Apr 10 '15 at 06:17
  • No problem to check API level, but *getAppTasks* doesn't work lower than api level 21. The problem is that how i can get previous intent for example android 4 without using *getRecentTasks*? – nAkhmedov Apr 10 '15 at 06:19
  • Yes, but You can do an if else statement. If Your project targeting API Level 21, and minimum a lower level, You can check by if/else which API the device has and then use the method You need in that if/else....You need an example? – Opiatefuchs Apr 10 '15 at 06:25
  • Please read the question again. if u did please help how can i get previous intent from my app? I don't wanna use deprecated methods – nAkhmedov Apr 10 '15 at 06:31
  • 4
    I read the question correctly :) ....but You have to use deprecated methods if You developing on minSDK lower than Your target.....that´s the only way... – Opiatefuchs Apr 10 '15 at 06:40
  • Possible duplicate of [GET\_TASKS Permission Deprecated](http://stackoverflow.com/questions/27974583/get-tasks-permission-deprecated) – Lokesh Nov 25 '15 at 16:41

0 Answers0