改变getRecentTasks的结果结果、getRecentTasks

2023-09-12 07:47:03 作者:其实你不懂

我有专为在工作场所的环境,一些人会用相机作为他们日常工作的一部分平板电脑的应用程序。虽然这是适当的和必要的主管离开该应用,它应该是困难的其他人意外地这样做。然而,Home键长preSS是pretty的容易做的意外。我已经做到了我自己。这带来了最近的任务列表;用户可以点击其中任何一个,他们是输了,因为他们中的一些不那么复杂的平均智能手机拥有者。

I have an app designed for a tablet in a workplace setting where a number of people will use the camera as part of their routine. While it's appropriate and necessary for a supervisor to leave the app, it should be difficult for other people to accidentally do so. However, a long press of the home key is pretty easy to do accidentally. I've done it myself. That brings up a list of recent tasks; the user can tap any one of them and they're lost, since some of them aren't as sophisticated as your average smartphone owner.

编程可以检索通过getRecentTasks这个名单。我的问题是我怎么可以从列表中删除所有,但最近的任务(我的),减少长度只有一个元素,或者更改列出的任务指向回到我的申请。我知道这是可能的:幼儿锁做它

Programmatically you can retrieve this list via getRecentTasks. My question is how I can remove all but the most recent task (mine) from that list, reduce the length to just one element, or change the listed tasks to point back at my application. I know this is possible: Toddler Lock does it.

我的第一次尝试是修改意图回来,在他们通过引用获得通过的希望。没有这样的运气。任何其他的想法?

My first attempt was to modify the intents returned, in hopes they were passed by reference. No such luck. Any other ideas?

(我不是在谈论home键的短preSS。我已经计算过,一出,部分是基于东西在这里找到。)

(I'm not talking about a short press of the home key. I already figured that one out, partially based on things found here.)

推荐答案

幸得幼儿锁的作者,我与他谈到了这个问题。引入的误差完全是我的。

Credit goes to the author of Toddler Lock, with whom I spoke about the issue. Errors introduced are entirely mine.

在你的清单与亲和力等于空字符串的残疾人活动创建。在你的程序中,启用它,然后用标志FLAG_ACTIVITY_NEW_TASK的意图启动它。它会显示在最近的活动。禁用任务并将其从显示屏上消失。

Create within your manifest a disabled activity with affinity equal to the empty string. In your program, enable it and then start it up using an intent flagged FLAG_ACTIVITY_NEW_TASK. It will show up in the recent activities. Disable the task and it disappears from the display.

请这些够了,你淹没最近的活动显示。如果有办法回去的活动比你虚活动的用户将能够走出你的程序的。

Make enough of these and you flood the recent activities display. If it has a way to go back more activities than you have dummy activities the user will be able to get out of your program.

请确保您禁用当您退出,并确保如果从最近的活动选择的任务之一,你的程序做了一些合理的任务。

Make sure you disable the tasks when you exit, and make sure that if you select one of those tasks from recent activities your program does something reasonable.

下面是两个在我的清单中的任务的例子:

Here's an example of two of the tasks in my manifest:

    <activity android:name="com.foo.android.recentactivity.Clear1"
              android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen"
              android:label="."
              android:enabled="false"
              android:icon="@drawable/clearicon"
              android:taskAffinity="" />
    <activity android:name="com.foo.android.recentactivity.Clear2"
              android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen"
              android:label="."
              android:enabled="false"
              android:icon="@drawable/clearicon"
              android:taskAffinity="" />