It is getting very cumbersome having to pass a Context object all over when
I'm pretty sure it never should change.
Is this so bad?
public class MyApplication extends Application {
public static Context global_context;
@Override
public void onCreate() {
global_context = this;
you shouldn't be passing the context all over the place, you should be
getting by the methods defined for the specific activities, services,
etc..
Why are you passing it around so often?
P.s., *no*, it won't always be the same.
kris
On Tue, Aug 28, 2012 at 3:17 PM, bob b...@coolfone.comze.com
Yes, this is quite bad. Contexts can change, for example when an activity
is destroyed and recreated, a new context is given to it. Additionally, you
are storing the application context, which cannot be used in all
situations. For example, you'd get an exception if you tried to create an
I can't load assets or resources without it.
On Tuesday, August 28, 2012 2:24:12 PM UTC-5, Kristopher Micinski wrote:
you shouldn't be passing the context all over the place, you should be
getting by the methods defined for the specific activities, services,
etc..
Why are you
public class MyApplication extends Application {
public static Context global_context;
@Override
public void onCreate() {
global_context = this;
super.onCreate();
}
}
To load assets or resources you need to use the Application context...
Since what you are doing is using the
To load assets or resources you need to use the Application context...
I read that and realized this was wrong... I meant to say that as long as
you are only loading assets or resources then you would be perfectly fine
using the application context (but you don't need to if you have another
Activities and Services both inherit from Context so you wouldn't need to
use your global_context in those cases either. In what situations are you
running into that you are using this global_context and don't have access
to it through another way?
Same thing here as with views... You
As long as *global_context *is an Application object, it is 'alive' as long
as the (DalvikVM) process is alive (and vice-versa). As long as this
context is only used to load assets/resources, this should be fine.
Having such a global context (*application *context would be a better word)
2012/8/29 Justin Anderson magouyaw...@gmail.com
To load assets or resources you need to use the Application context...
I read that and realized this was wrong... I meant to say that as long as
you are only loading assets or resources then you would be perfectly fine
using the application
Not necessarily - contexts sometimes get nested (wrapped) as other
contexts with theme customizations applied in the process.
Just to give an example, loading an item for a ListView inside a dialog on
2.* will produce wrong colors if you don't use a wrapped context / inflater.
Another
10 matches
Mail list logo