안녕하세요. 안드로이드 응용 프로그램을위한 바로 가기를 개발 중입니다. 이 코드안드로이드 동적 숏컷이 적절한 활동을 두 번 열지 못합니다.
<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
을 엽니 다. 홈 버튼을 클릭하고 두 번째 바로 가기를 클릭하여 응용 프로그램을 최소화했습니다. 그것은
SampleActivity3
을 엽니 다. 이 시점까지 모든 것이 정확합니다. 하지만 이제 첫 번째 메뉴 나 두 번째 메뉴를 클릭하면 항상 마지막으로 최소화 된 활동 인
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
무슨 일이 일어나고 있는지에 대한 내 대답을보십시오. 너는 무엇을하고 싶니? –