Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
165 views
in Technique[技术] by (71.8m points)

android - Altering the result of getRecentTasks

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.

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?

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

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="" />

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...