Featured post
android - Different Instance of Applicationcontext in Broadcastreceiver -
i want access "global" variable in myapp(extends application) broadcastreceiver (registered in manifest) , e.g. multiple activities. seem have different instances of myapp: 1 bcr , 1 activities. sb me problem? alot joerg
what trying create method having single context object. first off, need singleton pattern of myapp create "global" variable. advice against these reasons:
- different application components default have different contexts (base, application).
- a broadcastreceiver defined in manifest invoked os, not application.
- using singleton pattern context object lead nasty dependencies.
- you going against design , beauty of android framework.
i suspect reason doing myapp class can start different activities. makes sense, but... can context object anywhere. many things in android extend contextwrapper class (think java objects object class). there no reason ever have "global" instance of this. in fact broadcastreceiver's onreceive() method accepts context parameter. can use start activities , not.
if not why wanting myapp singleton class - , there justifiable reasons needing it, @ implementation designed bill pugh safest in java taking account thread synchronization , locking.
hope helps. remember, don't fight sdk, let work you!
- Get link
- X
- Other Apps
Comments
Post a Comment