如何使一个Android"家"快捷方式绕过应用程序,它的指向是历史? [英] How do you make an Android "Home" shortcut bypass the app it's point to's history?

查看:112
本文介绍了如何使一个Android"家"快捷方式绕过应用程序,它的指向是历史?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序,它允许您创建主页快捷方式,以一个特定的活动。事实证明,我的一些用户使用的应用程序,打的Home键去做别的事情,然后使用快捷方式之一跳回的活动。由于应用程序仍然在内存中它只是打开了新的活动在他人之上的返回键,将他们带回在整个历史。如果他们使用的快捷方式,然后有效地杀死历史,并有返回键只退出程序我想有发生的。有什么建议?

I have an app that allows you to create Home "shortcuts" to a specific Activity. It turns out that some of my users will use the app, hit the home key to go do something else, then use one of the shortcuts to jump back to that Activity. Since the app is still in memory it just opens the new Activity on top of the others and the "Back" key will take them back through the whole history. What I'd like to have happen is if they use a shortcut then to effectively kill the history and have the back key just exit the app. Any suggestions?

推荐答案

首先,设立的 taskAffinity在清单使活动运行为不同的任务:

First, set up the taskAffinity in the Manifest to make the Activity run as a different "task":

<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 标志。是这样的:

then, when building the shortcut, set the FLAG_ACTIVITY_NEW_TASK and FLAG_ACTIVITY_CLEAR_TOP flags. Something like:

// 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);

这篇关于如何使一个Android&QUOT;家&QUOT;快捷方式绕过应用程序,它的指向是历史?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆