> > 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 Application context I think you should be fine with this because this application context doesn't go away until your application dies. *Note that if you want to do UI related stuff you should most definitely NOT be using this context.* However, you should note that a lot of classes provide access to a context, and you really should be using that. For example, View has a getContext() method, and you can use that to load assets or resources. But you absolutely should not be passing this context around to things that will outlast the view that you got it from. http://developer.android.com/reference/android/view/View.html#getContext%28%29 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? Thanks, Justin Anderson MagouyaWare Developer http://sites.google.com/site/magouyaware On Tue, Aug 28, 2012 at 2:53 PM, bob <b...@coolfone.comze.com> wrote: > 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 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> wrote: >> > 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; >> > super.onCreate(); >> > } >> > >> > } >> > >> > -- >> > You received this message because you are subscribed to the Google >> > Groups "Android Developers" group. >> > To post to this group, send email to android-d...@**googlegroups.com >> > To unsubscribe from this group, send email to >> > android-developers+**unsubscr...@googlegroups.com >> > For more options, visit this group at >> > http://groups.google.com/**group/android-developers?hl=en<http://groups.google.com/group/android-developers?hl=en> >> > -- > You received this message because you are subscribed to the Google > Groups "Android Developers" group. > To post to this group, send email to android-developers@googlegroups.com > To unsubscribe from this group, send email to > android-developers+unsubscr...@googlegroups.com > For more options, visit this group at > http://groups.google.com/group/android-developers?hl=en > -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en