Home

getIntent

getIntent is a method in the Android Activity class that returns the Intent that started the activity. The Intent object carries information such as the action to perform, the data or URI to operate on, the MIME type, and a collection of extras—key-value pairs used to pass data between components.

Common usage involves reading the starting Intent shortly after an activity is created, typically in onCreate

Behavior with certain launch modes: If an activity is configured with launch modes such as singleTask or

In fragments, data can be accessed via getActivity().getIntent(), but fragments typically use their own argument bundles

Implementation notes: getIntent is a simple accessor and may return null for the extras in some edge

See also: Intent, startActivity, onNewIntent.

or
onStart.
For
example,
one
can
obtain
the
Intent
with
getIntent(),
then
read
its
contents:
String
action
=
getIntent().getAction();
Uri
data
=
getIntent().getData();
String
value
=
getIntent().getStringExtra("key");
int
count
=
getIntent().getIntExtra("count",
0);
boolean
flag
=
getIntent().getBooleanExtra("flag",
false).
singleTop,
a
new
Intent
delivered
to
an
existing
instance
will
invoke
onNewIntent(Intent
intent)
rather
than
creating
a
new
activity.
In
this
situation,
getIntent()
may
still
return
the
original
Intent
unless
setIntent(intent)
is
called
to
update
the
internal
reference.
(setArguments/getArguments)
to
pass
data,
which
reduces
coupling
to
the
hosting
activity’s
Intent.
cases,
so
null
checks
are
prudent
when
calling
getExtras()
or
getXxxExtra()
methods.
Developers
should
consider
updating
the
activity’s
Intent
reference
with
setIntent(intent)
if
new
data
should
be
reflected
by
subsequent
calls
to
getIntent.