I am using startActivity(intent)
to start an application. I need to know whether the application will be resumed form background or will it be restarted (i.e. it is not in background), before launching the application.
Before Lollipop, I used to get the list of recent tasks and check if it has an application with matching package name.
But in Lollipop I cannot use getRecentTask
, so this won't help.
Just for trial, I have also tried:
originalIntent = context.getPackageManager().getLaunchIntentForPackage(packageName);
if(originalIntent != null){
mainActivityIntent = context.getPackageManager().getLaunchIntentForPackage(packageName);
mainActivityIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
if(originalIntent.equals(mainActivityIntent))
Log.d("temp", "New Task");
else
Log.d("temp", "Background Task");
}
without any success.
What can be done?
Note: The other application I am switching to can be any other application installed on the phone and not necessary my application.