Home

onReceive

onReceive is a callback method in Android's BroadcastReceiver class. It is invoked by the Android framework when a broadcast that matches the receiver’s intent filters is delivered, and it receives the Intent object carrying the action, data, and extras of the broadcast.

The canonical signature is public void onReceive(Context context, Intent intent). The context parameter provides access to

Execution and lifecycle considerations: onReceive runs on the main thread of the process. It should complete

Registration and scope: A BroadcastReceiver can be declared in the app’s manifest or registered dynamically at

Usage notes: Inside onReceive, developers typically inspect the action and extract extras from the intent to

See also BroadcastReceiver, Intent, IntentFilter, Service, WorkManager.

application
resources
and
services,
while
the
intent
carries
information
about
what
happened,
including
the
action
via
getAction()
and
any
accompanying
data
or
extras.
quickly
and
not
perform
long-running
operations.
If
substantial
work
is
needed,
the
receiver
should
start
a
Service
or
delegate
work
to
components
such
as
WorkManager.
After
onReceive
finishes,
the
system
may
terminate
the
process,
so
the
method
should
not
rely
on
long-lived
state
or
background
execution
within
the
callback
itself.
runtime.
Manifest-registered
receivers
can
respond
to
broadcasts
even
when
the
app
is
not
running,
while
dynamically
registered
receivers
exist
only
while
the
registering
component
is
active.
Since
the
introduction
of
background
execution
limits,
many
implicit
broadcasts
registered
in
the
manifest
are
restricted
on
modern
versions
of
Android,
encouraging
dynamic
registration
or
alternative
approaches.
determine
appropriate
behavior.
For
longer
tasks,
it
is
common
to
start
a
service
or
schedule
work
using
WorkManager,
and
to
consider
security
measures
such
as
validating
the
sender
and
intent
data.