こんにちは私はアンドロイドアプリケーションのショートカットを開発しています。Android動的ショートカットが適切なアクティビティを初めて開けない
<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>
このコードの問題は、このようなものです:私のコードは私のマニフェストはこのようになります
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);
}
のように見えます。私は背景からアプリケーションを殺した。最初のショートカットをクリックします。それはSampleActivity2
を開きます。ホームボタンをクリックして2番目のショートカットをクリックしてアプリケーションを最小限に抑えました。それはSampleActivity3
を開きます。この点まではすべて正しいです。しかし、最初のメニューまたは2番目のメニューをクリックすると、最後に最小化されたアクティビティであるSampleActivity3
が常に開きます。 私はショートカットの静的な方法で同じことのことを行う場合、それが正常に動作します:
<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>
とマニフェストで私がコメントを追加しました:
<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>
は私のコードで間違ったいずれかのものがあります。助けが要る。ありがとうございました。
あなたのマニフェストを投稿してください。 –
質問をマニフェストコードで更新しました。私を助けてください。 – nilkash
何が起こっているのかについては私の答えを見てください。あなたは何をしたいですか? –