Android : android start app from service to previous state (resume)

on Sunday, August 31, 2014


What I am trying to accomplish is, starting from an app's ActivityInfo (third party app), I would like to launch it from my Service in the state it was. In the same way that if an user presses the home button and there touches, for example, Whatsapp's icon, Whatsapp will launch to the conversation he previously was. I have managed to launch any app. What I don't know is how to launch the app to the previous state, that is, the particular conversation I (or the user) was in -assuming it is still in memory, of course.


I first tried:



ActivityInfo app = (ActivityInfo) getActivityInfo();
String packName = app.packageName;
Intent appIntent = pm.getLaunchIntentForPackage(packName);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(appIntent);


Then I tried:



ActivityInfo app = (ActivityInfo) getActivityInfo();
String packName = app.packageName;
Intent appIntent = pm.getLaunchIntentForPackage(packName);
appIntent.setFlags(0);
appIntent.setPackage(null);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(appIntent);


I have also tried:



ActivityInfo app = (ActivityInfo) getActivityInfo();
Intent appIntent = new Intent();
appIntent.setComponent(new ComponentName(app.applicationInfo.packageName, app.name));
appIntent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(appIntent);


So, does anyone know how to achieve this?


0 comments:

Post a Comment