How can I resume my app from its previous position.
Note that it is still active, just paused. So if I click the androids current app button, or the app icon it resumes fine.
But who do I do this from my widget..
I have the following:
// Create an Intent to launch Activity
Intent intent = new Intent(context, LoginForm.class);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
This obviously launches the LoginForm as opposed to just resuming the application.
Does anyone know how to do this?
Edit:
Just to clarify, I dont want anything special. I basically want to mimic pressing the android icon launcher.
Use this it is same as android doing for your launcher activity
Intent notificationIntent = new Intent(context, SplashActivity.class);
notificationIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP);
notificationIntent.setAction(Intent.ACTION_MAIN);
notificationIntent.addCategory(Intent.CATEGORY_LAUNCHER);
PendingIntent clickActionIntent = PendingIntent.getService(context, 0, notificationIntent, 0);
You've basically answered your own question ;-)
Just simulate what Android does when you launch the app:
Intent intent = new Intent(context, LoginForm.class);
intent.setAction(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
or you could try this (assuming LoginForm
is the root activity of your application and that there is an instance of this activity still active in the task stack):
Intent intent = new Intent(context, LoginForm.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
Setting FLAG_ACTIVITY_NEW_TASK
should just bring an exising task for the application from the background to the foreground without actually creating an instance of the activity. Try this first. If it doesn't work for you, do the other.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With