android - Call getPackageName() early in the application lifecycle -


i need call getpackagename in application lifecycle. tried call in application constructor see throws nullpointerexception. had @ android source code , found that android calls internal attach method in turn calls documented protected attachbasecontext method. once moved code constructor attachbasecontext works expected.

question: idea assume attachbasecontext method kind of extension application constructor?

if need pacakagename suggest use buildconfig#application_id, because static variable , doesn't require waiting application initialization. difference between package name , application id can find here.

if anyway need entry point application, imho seems idea use attachbasecontext(context c) method, because:

  • it might called once (as constructor).
  • it first place in application can application context

Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -