What is the context that is passed int the onReceive
method of a BroadcastReciver
:
public void onReceive (Context context, Intent intent)
According to the official documentation:
The Context in which the receiver is running.
What is the context that is passed int the onReceive
method of a BroadcastReciver
:
public void onReceive (Context context, Intent intent)
According to the official documentation:
The Context in which the receiver is running.
It is an application context . Same one that you get with method
But:
This instance is a ReceiverRestrictedContext with two main functions disabled; calling registerReceiver() and bindService(). These two functions are not allowed from within an existing BroadcastReceiver.onReceive(). Each time a receiver processes a broadcast, the Context handed to it is a new instance.
Use
getApplicationContext()
to send context to onReceive Method.A little research gives below result...
For static receiver
I got below log
For bynamic receiver (registered into an Activity MainActivity) like
I got below log
So when it make true the statement given into documentation that The Context in which the receiver is running.