Salut Je développe des raccourcis pour l'application Android. Mon code ressembleRaccourcis dynamiques Android n'ouvrant pas l'activité correcte deuxième fois
private void setShortMenu() {
ArrayList<ShortcutInfo> shortcutInfos = new ArrayList<>();
Intent intent = new Intent(this, SampleActivity2.class);
intent.setAction(Intent.ACTION_VIEW);
intent.putExtra("val",1);
intent.addCategory("android.shortcut.conversation");
ShortcutManager shortcutManager = getSystemService(ShortcutManager.class);
ShortcutInfo shortcut = new ShortcutInfo.Builder(this, "id2")
.setShortLabel("Web site")
.setLongLabel("Open the web site")
.setIcon(Icon.createWithResource(this, R.mipmap.ic_launcher))
.setIntent(intent)
.build();
shortcutInfos.add(shortcut);
Intent intent2 = new Intent(this, SampleActivity3.class);
intent2.setAction(Intent.ACTION_VIEW);
intent.addCategory("android.shortcut.conversation");
intent.putExtra("val",2);
ShortcutInfo shortcut2 = new ShortcutInfo.Builder(this, "id1")
.setShortLabel("Web site...")
.setLongLabel("Open the web site...")
.setIcon(Icon.createWithResource(this, R.mipmap.ic_launcher))
.setIntent(intent2)
.build();
shortcutInfos.add(shortcut2);
shortcutManager.setDynamicShortcuts(shortcutInfos);
}
Mes regards manifeste comme ceci:
<application
android:name=".SampleApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<!--<meta-data android:name="android.app.shortcuts"
android:resource="@xml/shortcuts" />-->
</activity>
<activity android:name=".SampleActivity" />
<activity android:name=".SampleActivity2" />
<activity android:name=".SampleActivity3"></activity>
Problème avec ce code est comme ça. J'ai tué l'application de fond. cliquez sur le premier raccourci. Il ouvre SampleActivity2
. J'ai minimisé l'application en cliquant sur le bouton d'accueil et cliquez sur le deuxième raccourci. Il ouvre SampleActivity3
. Jusqu'à ce point tout est correct. Mais maintenant, si je clique sur le premier menu ou le deuxième menu, il ouvre toujours SampleActivity3
qui est la dernière activité minimisée. Si je fais même chose avec la manière statique des raccourcis il fonctionne très bien:
<shortcuts xmlns:android="http://schemas.android.com/apk/res/android">
<shortcut
android:shortcutId="compose"
android:enabled="true"
android:icon="@mipmap/ic_launcher"
android:shortcutShortLabel="@string/compose_shortcut_short_label1"
android:shortcutLongLabel="@string/compose_shortcut_short_label1"
android:shortcutDisabledMessage="@string/compose_shortcut_short_label1">
<intent
android:action="android.intent.action.VIEW"
android:targetPackage="com.example.nilkash.shortcutmenu"
android:targetClass="com.example.nilkash.shortcutmenu.SampleActivity2" >
<extra android:name="val" android:value="1" />
</intent>
<categories android:name="android.shortcut.conversation" />
</shortcut>
<shortcut
android:shortcutId="compose1"
android:enabled="true"
android:icon="@mipmap/ic_launcher"
android:shortcutShortLabel="@string/compose_shortcut_short_label2"
android:shortcutLongLabel="@string/compose_shortcut_short_label2"
android:shortcutDisabledMessage="@string/compose_shortcut_short_label2">
<intent
android:action="android.intent.action.VIEW"
android:targetPackage="com.example.nilkash.shortcutmenu"
android:targetClass="com.example.nilkash.shortcutmenu.SampleActivity3" >
<extra android:name="val" android:value="2" />
</intent>
<categories android:name="android.shortcut.conversation" />
</shortcut>
et manifeste j'ajouté:
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<meta-data android:name="android.app.shortcuts"
android:resource="@xml/shortcuts" />
</activity>
Y at-il quelque chose de mal dans mon code. Besoin d'aide. Je vous remercie.
poster votre manifeste. –
Question mise à jour avec le code manifeste. S'il vous plaît, aidez-moi. – nilkash
Voir ma réponse pour une description de ce qui se passe. Que voudriez-vous arriver? –