Search code examples
androidbroadcastreceiverandroid-contextandroid-broadcastreceiver

What is the context of Android Receiver defined via Manifest file?


Say I have an Android broadcast receiver defined on the manifest file.

What is the context I received on onReceived(Context context, ...)?

Is it going to be an instance of the Application Context?

Thanks


Solution

  • I would not count on it being any particular type of Context. It is not documented as being Application and could very easily be some sort of ContextWrapper. The actual class might even vary between Android versions.

    If you need the Application context, call getApplicationContext() on the passed-in Context. That way, you are guaranteed to get the correct object.