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

xml - Extract substrings with XSLT -

math - "ELO Rating" and how does "TSR Rating" work? -

How can do a tuple comparison in coffeescript similar to that in python? -