建立图标到屏幕,其实还主要考虑到了 activity堆栈的问题,
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
还有上一篇划横线的 是会改变推展顺序的
当然使用别名 也可以改变堆栈 只是这个别名运行在另一个task上
<activity android:taskAffinity=""
android:name=".IncomingShortcutActivity">
<intent-filter>
<action android:name="com.example.App.Shortcut"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
// build the shortcut's intentsfinal
Intent shortcutIntent = new Intent();
shortcutIntent[color=red].setComponent[/color](new ComponentName(this.getPackageName(), ".IncomingShortcutActivity"));
shortcutIntent.putExtra(EXTRA_STOPID, Integer.toString(this.stop_id));
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
final Intent intent = new Intent();
intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
// Sets the custom shortcut's title
intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, custom_title);
// Set the custom shortcut icon
[color=red] intent.putExtra[/color](Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext(this, R.drawable.bus_stop_icon));
// add the shortcut
intent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
sendBroadcast(intent);
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
还有上一篇划横线的 是会改变推展顺序的
当然使用别名 也可以改变堆栈 只是这个别名运行在另一个task上
<activity android:taskAffinity=""
android:name=".IncomingShortcutActivity">
<intent-filter>
<action android:name="com.example.App.Shortcut"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
// build the shortcut's intentsfinal
Intent shortcutIntent = new Intent();
shortcutIntent[color=red].setComponent[/color](new ComponentName(this.getPackageName(), ".IncomingShortcutActivity"));
shortcutIntent.putExtra(EXTRA_STOPID, Integer.toString(this.stop_id));
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
final Intent intent = new Intent();
intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
// Sets the custom shortcut's title
intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, custom_title);
// Set the custom shortcut icon
[color=red] intent.putExtra[/color](Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext(this, R.drawable.bus_stop_icon));
// add the shortcut
intent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
sendBroadcast(intent);