[android-developers] global_context

2012-08-28 Thread bob
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;

Re: [android-developers] global_context

2012-08-28 Thread Kristopher Micinski
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

Re: [android-developers] global_context

2012-08-28 Thread Raghav Sood
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

Re: [android-developers] global_context

2012-08-28 Thread bob
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

Re: [android-developers] global_context

2012-08-28 Thread Justin Anderson
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

Re: [android-developers] global_context

2012-08-28 Thread Justin Anderson
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

Re: [android-developers] global_context

2012-08-28 Thread Justin Anderson
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

Re: [android-developers] global_context

2012-08-28 Thread Streets Of Boston
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)

Re: [android-developers] global_context

2012-08-28 Thread Kostya Vasilyev
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

Re: [android-developers] global_context

2012-08-28 Thread Justin Anderson
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