I created an application that changes the wallpaper of users. I want to add a shortcut for Android so that the user can change the wallpaper without having to fully open the application (the main use case is to attach it to a gesture in the form of Nova Launcher, which allows you to select a shortcut for each gesture).
Everything works for me, with one big problem. Each time a shortcut starts, my own action happens, but then the main ALSO launch activity starts! This is clearly undesirable, and I cannot understand what is happening.
Here is the ShortcutActivity code:
public class ShortcutActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); final Intent intent = getIntent(); final String action = intent.getAction(); if (Intent.ACTION_CREATE_SHORTCUT.equals(action)) { setupShortcut(); finish(); return; } else { Toast.makeText(this, "Do something interesting.", Toast.LENGTH_SHORT).show(); finish(); } } void setupShortcut() { Intent shortcutIntent = new Intent("CHANGE"); shortcutIntent.setClass(this, getClass()); Intent intent = new Intent(); intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(R.string.shortcut_title)); intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent); Parcelable iconResource = Intent.ShortcutIconResource.fromContext(this, R.drawable.ic_launcher); intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconResource); setResult(RESULT_OK, intent); } }
Here is my (simplified) manifest:
<application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/title_activity" android:theme="@style/AppTheme"> <activity android:name=".WallpaperSettings" android:label="@string/title_activity_wallpaper_settings"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".ShortcutActivity" android:theme="@android:style/Theme.NoDisplay" android:label="@string/shortcut_title"> <intent-filter> <action android:name="android.intent.action.CREATE_SHORTCUT" /> <category android:name="android.intent.category.DEFAULT" /> </intent-filter> </activity> </application>
Is it possible to do without launching the main launch activity?
source share