I have written the following code for creating a shortcut of my application in Home screen:
private void createShortcut() {
Intent shortcutIntent = new Intent(this, ActActivation.class);
shortcutIntent.setClassName("org.mabna.order",
"org.mabna.order.ui.ActActivation");
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
Intent addIntent = new Intent();
addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "test");
addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
Intent.ShortcutIconResource.fromContext(this, R.drawable.icon));
addIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
this.sendBroadcast(addIntent);
}
It works correctly but every time I run my program and this code is run, I get the message "Shortcut Test created" and a new shortcut is added to my home screen. After 10 time opening my application, I have 10 shortcut.
How can I prevent this message box and creating multiple shortcuts?