Altering the result of getRecentTasks
Asked Answered
K

2

3

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.)

Knout answered 6/6, 2011 at 23:3 Comment(0)
K
4

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="" />
Knout answered 16/6, 2011 at 16:51 Comment(10)
Note that this is clearly an abuse of the platform, and thus something the platform will likely protect itself from in the future.Purchasable
I tried using the method of adding disabled activity and enabling at run-time as specified in the answer but still it shows me recent application list with last opened applications. In short there is no change in it's normal behavior. Please help me out Thank You.Syncom
Sorry to hear you're having trouble. I'm guessing I was unclear when I explained. Start by ignoring the disable/enable part - once you have it working, you can fiddle with that. The simplest form is to have a single FLAG_ACTIVITY_NEW_TASK intent which your program starts when it begins, whose sole purpose is to be an extra started activity. It shouldn't do much more than exit. See if that shows up in recent activities - if it doesn't, then something's not set right in the intent use or the manifest. Once you have that working, make five more of them and have them chain to each other.Knout
@Purchasable - I'm sorry I have to abuse the recent activities list this way, but there is no other mechanism provided. I do not condone this activity for most applications. Regardless, you can still get to the application manager from that recent applications screen and kill the offending application. Toddler Lock seems to make use of a race condition to even lock out the ability to get to the application manager, but I have elected not to go that far since I'm not actually dealing with toddlers.Knout
18 activities are required, incredible.Vaenfila
If 18 recent activities are displayed, yes. And you don't get to re-use one activity many times, because (if I recall correctly) that will get collapsed into a single entry in the recent activities. But it sounds like you might have gotten it to work; do you have any advice for MaheshValu ?Knout
can you explain in a little more detail/ and example of one of these activities in your manifest?Butanone
You'll need to be more specific about what you need details about. I would rather concentrate my effort on sections which would actually help you, rather than the whole thing. If you are asking what the activities do... activity 1 does nothing more than start activity 2, which starts activity 3, and so on... at the end of the chain it then starts the application's actual activity. Invisible to the user except when they pull up recent activities.Knout
Interesting solution. I was confronted with the same problem, having to create an application that runs in Kiosk mode. But I dealt with clearing the recent tasks by having my application run as the default homescreen and then rebooting the device. After that, your application will be the only one running and when opening the recent task panes it will be empty.Lucania
@Lucania - I have not yet checked, but in Lollipop the recent activities is both a lot more available, and has a lot more tasks. It is likely that as hackbod suggested, the platform is protecting itself and the homescreen approach will become necessary.Knout
P
1

You can't do this from an application. You would need to build a custom system image with the behavior you want.

Purchasable answered 6/6, 2011 at 23:6 Comment(1)
The fact at least one existing application dos this - without a custom system image - says your answer is incorrect. Download "Toddler Lock", run it, and hold the home key.Knout

© 2022 - 2024 — McMap. All rights reserved.