Android '홈' 바로가기가 앱 기록을 가리키는 앱을 우회하도록 어떻게 만드나요?
-
13-09-2019 - |
문제
특정 항목에 대한 홈 "바로가기"를 만들 수 있는 앱이 있습니다. Activity
.내 사용자 중 일부는 앱을 사용하고 홈 키를 눌러 다른 작업을 수행한 다음 바로 가기 중 하나를 사용하여 해당 활동으로 돌아갑니다.앱이 아직 메모리에 있으므로 새 앱이 열립니다. Activity
다른 것 위에 올려 놓고 "뒤로" 키를 누르면 전체 기록을 통해 다시 돌아갈 수 있습니다.내가 원하는 것은 단축키를 사용하여 기록을 효과적으로 종료하고 뒤로 키를 눌러 앱을 종료하는 것입니다.어떤 제안이 있으십니까?
해결책
먼저, taskAffinity 매니페스트에서 Activity
다른 "작업"으로 실행:
<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>
그런 다음 바로가기를 만들 때 FLAG_ACTIVITY_NEW_TASK
그리고 FLAG_ACTIVITY_CLEAR_TOP
플래그.다음과 같은 것 :
// 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);
다른 팁
추가해 보세요 Intent.FLAG_NEW_TASK
의도에.
제휴하지 않습니다 StackOverflow