Flyview
Flyview

Reputation: 1959

Exclude from recent apps list for Android 4.4.2 only

I would like to exclude my app from the recent apps list (long press home, multitasking button, etc) BUT only for Android 4.4.1 and 4.4.2. The reason being is that on these Android versions, services can't restart themselves and my service is killed when my app is swiped away from the recents list. Normally it restarts itself without a problem, but it can't do so on 4.4.1 and 4.4.2.

I know you can add android:excludeFromRecents="true" in the manifest but that will exclude it on all Android versions.

I tried what was suggested here but can't get it to work:

Remove app from recent apps programmatically

Any ideas?

Upvotes: 0

Views: 1206

Answers (2)

CommonsWare
CommonsWare

Reputation: 1007584

To exclude yourself from the recent-tasks list on 4.4 (not only 4.4.2):

Step #1: Create res/values/bools.xml with a bool resource, named is_44, set to false

Step #2: Create res/values-v19/bools.xml with a bool resource, named is_44, set to true

Step #3: Create res/values-v21/bools.xml with a bool, named is_44, set to false

Step #4: Use android:excludeFromRecents="@bool/is_44" in your <activity>

So, for API Level 19 and 20, you will be excluded from recents, but not other API levels.

Upvotes: 1

Trinimon
Trinimon

Reputation: 13967

If Android 4.4.x is exact enough you could create a folder layout-v19 and define an extra layout for the activity, which should be excluded from the recent apps list:

<activity 
    android:name=".anActivity"
    android:excludeFromRecents="true"
    ...>

See Providing Resources documentation (search for Platform Version) and API levels here

Upvotes: 1

Related Questions