I have method that resolves an Intent to a ComponentName:
private static ComponentName resolveViewExternalIntent(Context context)
{
Intent intent = createIntent();
return intent.resolveActivity(context.getPackageManager());
}
Rarely, I get the following ACRA crash report:
java.lang.NullPointerException
at android.content.Intent.resolveActivity(Intent.java:4518)
at com.mypackage.myclass.resolveViewExternalIntent(SourceFile:271)
at om.mypackage.myActivity.onResume(SourceFile:517)
That line in the Intent class gets the NPE because PackageManager is null
.
I see this infrequently, but frequently enough that made me write this question.
Does anybody have any idea, under what circumstances can Context/Activity.getPackageManager() return null? In my case, context
is the Activity object itself, not the ApplicationContext. The app is executing the Activity.onResume() lifecycle method when this happens.