¿Cómo se hace un Android “Inicio” atajo de derivación de la aplicación es el punto de la historia?

StackOverflow https://stackoverflow.com/questions/978172

Pregunta

Tengo una aplicación que permite crear Inicio "atajos" a un Activity específica. Resulta que algunos de mis usuarios van a utilizar la aplicación, pulse la tecla de casa para ir a hacer otra cosa, a continuación, utilice uno de los atajos para saltar de nuevo a esa actividad. Dado que la aplicación está todavía en la memoria que sólo se abre la nueva Activity en la parte superior de los demás y la tecla "Volver" les llevará de nuevo a través de toda la historia. Lo que me gustaría que suceda es si utilizar un acceso directo a continuación, para matar con eficacia la historia y tienen la llave simplemente salir de la aplicación. ¿Alguna sugerencia?

¿Fue útil?

Solución

En primer lugar, establecer el taskAffinity en Manifiesto para hacer la carrera Activity como una "tarea" diferente:

<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>

A continuación, cuando se construye el acceso directo, establecer las banderas FLAG_ACTIVITY_NEW_TASK y FLAG_ACTIVITY_CLEAR_TOP. Algo así como:

// build the shortcut's intents
final Intent shortcutIntent = new Intent();
shortcutIntent.setComponent(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
intent.putExtra(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);

Otros consejos

Trate de añadir Intent.FLAG_NEW_TASK a la Intención.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top