Android: resume application from previous position

How can I resume my application from a previous position.

Please note that it is still active, just paused. Therefore, if I press the button of the current android application or the application icon, it will resume.

But who am I doing 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 explicitly launches LoginForm, and not just resumes the application.

Does anyone know how to do this?

Edit:

Just to clarify, I don't want anything special. I basically want to imitate clicking on the android launch button.

+7
source share
2 answers

Basically you answered your question :-)

Just mimic what Android does when the application starts:

 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 can try this (assuming LoginForm is the root activity of your application and that an instance of this action is 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 simply lead to the completion of the task for the application from the background to the foreground, without actually creating an instance of the action. Try it first. If this does not work for you, do something else.

+12
source

Use it just like android for your launch 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); 
0
source

All Articles