How to Remove Unneeded taskAffinity from a Sensitive Activity and Check Navigation
A sensitive Activity does not always need a separate affinity. If navigation requirements do not call for one, its value can be replaced with android:taskAffinity="". But that change alone is not enough: you need to check that the screen opens, the intended Activity resumes after task switching, and Back returns the user along the expected route. We will walk through the decision using an entirely fictional example with our own apps and synthetic data.
First, determine why the screen needs an affinity
taskAffinity defines an Activity’s association with tasks through affinity. It affects task selection when launching with FLAG_ACTIVITY_NEW_TASK and the destination task during reparenting. The decision for a sensitive screen therefore starts with a specific requirement: does it need this association for its intended navigation? The fact that a screen is sensitive does not, by itself, define the required route.
This article covers how an Activity participates in Android tasks. Define which task the screen should open in, what should resume after switching tasks, and where Back should lead. An empty affinity alone does not prove that the displayed interface is authentic or fully protected against spoofing.
Set the empty value explicitly
To give an Activity no affinity for any task, set android:taskAffinity="" specifically for that Activity. Removing the attribute produces a different result: the Activity inherits the application’s affinity. By default, the application’s affinity name matches the namespace in build.gradle. An absent attribute in the sensitive screen’s configuration therefore cannot be treated as a completed change.
In our entirely fictional product, “Practice Requests,” SensitiveActivity displays a synthetic record called “Request TEST-042.” The team has determined that this screen does not need a separate affinity. The specific change is to replace the previous value with an empty string. The configuration check must confirm that SensitiveActivity explicitly has an empty value, rather than inheriting one from application.
Record the other launch conditions
Before testing, record the effective launchMode, allowTaskReparenting and flags used for normal launches of SensitiveActivity. The launching Intent’s flags can override launchMode behavior, so the manifest alone cannot establish every transition. A before-and-after comparison is meaningful only under the same launch conditions.
allowTaskReparenting determines whether an Activity can move from the task that launched it to a task with the corresponding affinity when the latter comes to the foreground. If the attribute is not set on the Activity, the application value applies; the default is false. Record the effective value so that the expected route accounts for this setting.
Check opening and return navigation with Back
The following scenarios are acceptance checks proposed by the author using fictional data, not an official Android testing procedure. As a positive control in your own test app, open “List,” then SensitiveActivity with the “Request TEST-042” record. Use a normal launch without special flags and with launchMode=standard. Perform the same sequence before and after clearing the affinity.
Acceptance requires two observable results: the correct synthetic record opens, and Back returns to “List” without an unexpected intermediate Activity. Under standard behavior, Back removes the current Activity from the stack and resumes the previous one. Successfully opening the screen is therefore not enough: you also need to observe the intended return navigation.
Compare switching between your own tasks
Open SensitiveActivity, press Home and switch to a second test app you own—for example, “Practice Calendar,” with a clearly different synthetic screen. Then return to the first task in the usual way. In a normal scenario, returning to the original task resumes the Activity at the top of its stack.
Record the expected screen on resume and the next Back transition in advance. Repeat the scenario before and after the change under the same conditions. An unexpected screen or loss of the intended route counts as a regression. This check evaluates navigation; it does not test content protection in Recents.
Check the NEW_TASK variants your product uses
If the product normally uses FLAG_ACTIVITY_NEW_TASK, add separate cases where a task with the corresponding affinity is absent and where one already exists. With this flag, an existing task with a matching affinity may receive the Activity; if no such task exists, a new one starts. Do not require every launch with this flag to create a new task.
For the launchMode and allowTaskReparenting settings actually used, define the expected task, the screen after switching and the return route in advance. Compare observations before and after clearing the affinity. Do not make the sensitive Activity externally accessible for testing. If the route breaks, first compare the result against the recorded settings and launch flags.
Set priorities and limit your conclusions
The first priority is a justified decision about whether affinity is needed and an explicitly empty value if it is not. The second is successful completion of the intended opening, switching and return routes. Accept the change only when both conditions are met. Success means no regression was found in the tested scenarios, not that every form of interface spoofing is impossible.
Application configuration can only partially mitigate the first variant of StrandHogg. Preventing the second requires a platform fix present in Android 11 and later. Checks for obscured touches, HIDE_OVERLAY_WINDOWS, FLAG_SECURE, snapshots and Recents, confirmation for Keystore, deep links, Intent addressing and redirection, PendingIntent and component permissions remain separate requirements outside this article’s scope.
If your product includes a website or web component, you can start with a free CheckMyApp website or web-product audit. For the Android change described here, the outcome remains a decision about one Activity, a verified configuration and observable criteria for navigation regressions.