كيف يمكنك جعل اختصار أندرويد "Home" تجاوز التطبيق الذي تشير إليه التاريخ؟

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

سؤال

لدي تطبيق يسمح لك بإنشاء "اختصارات" المنزلية Activity. وبعد اتضح أن بعض مستخدمي سيستخدم التطبيق، وضرب المفتاح المنزلي للذهاب إلى شيء آخر، ثم استخدم أحد الاختصارات للقفز مرة أخرى إلى هذا النشاط. نظرا لأن التطبيق لا يزال في الذاكرة، فهذا يفتح الجديد Activity على رأس الآخرين، فإن مفتاح "الظهر" سيأخذهم من خلال التاريخ بأكمله. ما أود حدوث حدوثه هو إذا استخدموا اختصارا، ثم قتل التاريخ بفعالية ولديك المفتاح الخلفي فقط يمكنك الخروج من التطبيق. أي اقتراحات؟

هل كانت مفيدة؟

المحلول

أولا، إعداد المهام في البيان لجعل 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 إلى النية.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top