An old question, however I can provide an updated answer and actual test results.
Initially, I assumed that I installed my onCreate () application in order to first save the application context, for example like this:
@Override public void onCreate() { myapp.app_context = this; super.onCreate();
Now my recipient is declared like this:
<receiver android:name=".myreceiver" android:permission="android.permission.RECEIVE_BOOT_COMPLETED"> <intent-filter> <action android:name="android.intent.action.BOOT_COMPLETED" /> </intent-filter> <intent-filter> <action android:name="android.intent.action.MY_PACKAGE_REPLACED" /> </intent-filter> </receiver>
And upon receipt:
@Override public void onReceive(Context context, Intent intent) { ctx = myapp.app_context;
Got a stack trace showing that ctx (myapp.app_context) is NULL! Got 1 on the Android 6 Galaxy J7 device and 1 on the Android 9 Xperia XZ1.
3c71
source share