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?