Android Intent flags, decoded
Intent flags fine-tune how Android launches activities, delivers broadcasts and
grants temporary access to content URIs. They are bit constants on
android.content.Intent, combined with bitwise-OR and passed to setFlags or
addFlags. This reference lists the common FLAG_ACTIVITY_*,
FLAG_RECEIVER_* and FLAG_GRANT_* flags with their real hex values, the
component type each applies to and what behaviour they change — plus a
calculator that OR’s your selection into a single int.
How it works
Each flag occupies one bit of a 32-bit int. To apply several, OR them together:
Intent i = new Intent(this, DetailActivity.class);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(i);
Activity flags control the back stack and task affinity, receiver flags control
broadcast delivery and ordering, and grant flags hand a receiver short-lived
read or write access to the URIs in the Intent’s data or ClipData. Because the
activity and receiver flag sets are read in different contexts, a handful share
the same bit value — so only combine flags meant for the same component type.
Tips and notes
NEW_TASKis mandatory when starting an activity from a non-Activity context.CLEAR_TOP+SINGLE_TOPis the standard “bring existing screen forward” combo.- Grant flags are temporary and revoked when the receiving task finishes.
- Watch for the shared-bit flags (e.g.
0x40000000) — never mix component types.