I have a litlte code to add a shortcut to homescreen for the first running time:
Intent shortcutIntent = new Intent(getApplicationContext(),
SFlashActivity.class);
shortcutIntent.setAction(Intent.ACTION_MAIN);
Intent addIntent = new Intent();
addIntent
.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "New App");
addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
Intent.ShortcutIconResource.fromContext(getApplicationContext(),
R.drawable.ic_launcher));
addIntent
.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
addIntent
.putExtra("duplicate", false);
getApplicationContext().sendBroadcast(addIntent);
But with above code, my app always start Splash screen althought my app is running. So how could i make home screen shortcut resume to top activity. I noticed that, app's shortcut made by google play on install always resume the top activity.
Thank so much !
I also went through the same problem of resuming the application while coming back when the app is in background because of the Home button press,
Two changes To be done
1.Add below property to the activities in manifest file
This will resume the activities when coming from the launcher icon.
2.Upper change wont resume the application if you click on the app icon on Home screen which you have created programatically. Because you have specified the "SFlashActivity.class" for the launching purpose. To overcome this you will have to do a trick as below:
Add this function to your SFlashActivity.class
And in Oncreate:
Provided that your shortcut intent does not have flag FLAG_ACTIVITY_CLEAR_TOP.
Use the isTaskRoot() method Enter the following code snippet to your OnCreate() of your main activity Here is an example:
Found the solution here:
When launched via icon on the home screen, Android will always start the activity with the
android.intent.action.MAIN
filter in yourAndroidManifest.xml
, unless the application is already running (in which case it will obviously restore the activity on top of the stack).To achieve what you described you can simply store the last visible activity in
SharedPreferences
and have a Dispatcher activity that starts the last activity according to the preferences.So if activity is present in prefs start that activity or start SplashScreen.
In every activity you want to re-start automatically:
And a Dispatcher activity similar to the following:
Remarks
onPause
overrideandroid.intent.action.MAIN
actionRef : - How to make an android app return to the last open activity when relaunched?