How to open particular activity using shortcut?

256 Views Asked by At

I am trying to open particular activity using shortcut but always run application.

When application is running in background and click on shortcut icon -> particular activity is open.

If application is killed from background then how to open particular activity using shortcut.

* Below method use for create shortcut

private void createShortcutOfApp() {

    Intent shortcutIntent = new Intent(getApplicationContext(),
        YourTargetActivity.class);
    shortcutIntent.setAction(Intent.ACTION_MAIN);

    Intent addIntent = new Intent();
    addIntent
        .putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
    addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "App shortcut name");
    addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
    Intent.ShortcutIconResource.fromContext(getApplicationContext(),
    R.mipmap.logo_of_your_app_shortcut));

    addIntent
        .setAction("com.android.launcher.action.INSTALL_SHORTCUT");
    addIntent.putExtra("duplicate", false);  //may it's already there so   don't duplicate
    getApplicationContext().sendBroadcast(addIntent);
}

permission in manifest

uses-permission  android:name="com.android.launcher.permission.INSTALL_SHORTCUT

define in manifest

android:name=".YourTargetActivity"
android:exported="true"

I am tired to solve this problem, please help me.

1

There are 1 best solutions below

1
On

Follw below link to know how to open particular activity on relaunch application. It works for me.

How to make an android app return to the last open activity when relaunched?