Shortcuts vs Launcher Widgets (Android)


We have enabled shortcuts for two of our app screen. Using manifest, we have initialized Activity which is referring to the shortcut as below.

<activity android:name=".ui.shortcuts.ShortCut1" android:screenOrientation="portrait" android:icon="@drawable/shortcut1" android:label="@string/app_shortcut_name1" android:theme="@style/AppLightTheme"> <intent-filter> <category android:name="android.intent.category.DEFAULT" /> <action android:name="android.intent.action.CREATE_SHORTCUT" /> </intent-filter> </activity>

From code I have enabled the shortcuts as follows.

Intent shortcutIntent = null; shortcutIntent = new Intent(ApplicationNekt.getContext(), ShortCut1.class); shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); Intent intent = new Intent(); intent.putExtra("duplicate", false); intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent); intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, ApplicationNekt.getContext().getString(R.string.app_shortcut_name1)); intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,Intent.ShortcutIconResource.fromContext(ApplicationNekt.getContext(), R.drawable.shortcut1)); intent.setAction("com.android.launcher.action.INSTALL_SHORTCUT"); ApplicationNekt.getContext().sendBroadcast(intent);

Now In Nova and Action launchers, they display the shortcuts under shortcuts section with the icon and text i gave in manifest. If I click and hold , I am able to place the icon on home tab. Immediately after that, my target activity opens. But the when I go back to phone home screen, shortcut icon they created in previous step was removed.

Am I missing something here?


Kevin from Nova launcher replied to support email.

Its also explained in different thread <a href="https://stackoverflow.com/questions/41592723/android-define-shortcut-that-can-be-used-in-custom-launcher/41688735#41688735" rel="nofollow">Android define shortcut that can be used in custom launcher</a>

In my case, I have both shortcut adding code as well as I want to support users who wants to add shortcuts from Nova/Action Launcher's Widget screen. So I did the following.

Below code I wrote in ShortCut1.java class file. This is the activity code.

public class ShortCut1 extends Activity{ @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); // This code runs when the user actually clicks and // opens the shortcut. so redirect him to target screen. openTargetTab(0); // This code is useful when called by the Nova/Action launcher's // widget is clicked. So return them with icon, name and target // activity. Once they receive it they will set the short cut icon on home. // Note: Even when the shortcut is clicked, this result is set, // but nobody reads the response. So it should be ok. Intent resIntent = getResIntent(); setResult(RESULT_OK, resIntent); finish(); } private Intent getResIntent() { Intent shortcutIntent = new Intent(); // Target intent is set to this own class. So that when the user clicks on the shortcut this intent will be passed. Intent target = new Intent(this, ShortCut1.class); shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, target); shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, Application.getContext().getString(R.string.shortcut_name)); shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext(Application.getContext(), R.drawable.shortcut1)); return shortcutIntent; } private void openHomeTab(int tabIndex) { // Final target screen. Intent intent = new Intent(this, TargetActivity.class); startActivity(intent); } }

NOTE: I have not removed or changed any code on Manifest or the shortcut adding code. As I need that support also in my app, I left that code as it is. So when the user clicks on "Add shortcut", that code will run. Only change I did here is, I have called "Setresult" with proper intent which is understandable by 3rd party launchers.


  • To which C# data type does MS Access “Number” type correspond?
  • Updating List
  • Android: Create a single choice dialog with disabled OK button until selected
  • Login works only for last user in the database
  • How to call a web service with a configurable URL
  • Concatenate Strings in the strings.xml file for Android
  • NotificationListenerService works intermittently for Oreo
  • Android - Issue with async tasks
  • How to parse bundle data received from facebook in android?
  • How to load music in Android with libGDX?
  • SkImageDecoder::factory returned null
  • How can convert this C# code to C++/CLI
  • how to convert text readed from barcode to arabic text
  • Control CheckBox status
  • How to access R.string.xxx resources from a method by passing string 'xxx' as parameter to
  • Getting data from SQLite database to String Android
  • Android Studio - Can't Read preferenceSettings
  • Getting the phone number of nearby place
  • How does google-services.json replace default_web_client_id?
  • Issues with unchecked generics
  • How to save state of CheckBox while scrolling in ListView?
  • Android MVVM with Programmatic UI Customization
  • testing with mock in robotium
  • android locationListener not working?
  • Xamarin Android Request to Server is not establishing instead getting an exception?
  • Transforming string to UTF8
  • ProgressDialog setProgress and setMessage inside asyncTask don't work
  • Home screen shortcut to activity
  • Convert from DataFrame to JavaPairRDD
  • Help with SimpleCursorAdapter and Listview
  • Does pImpl fundamentally solve C++ DLL issue?
  • Is it possible to set an Android Notification or a later date and time that will fire when the app i
  • Android displaying images dynamically
  • How do I set the public and private key on RSAParameters to use for RSACryptoServiceProvider?
  • What is using connection in the code
  • TelephonyManager crashing on android studio
  • GCM registration works for debug APK but not release APK
  • Android Login- checking if username and password match with MySQL database
  • How to extract text from a PDF and decode characters?
  • Why querying a date BC is changed to AD in Java?