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 AlertDialog using this context.
Raghav Sood
Sent from my Nexus 7
On Aug 29, 2012 12:53 AM, "Kristopher Micinski" <krismicinski@gmail.com> 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 <bob@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-developers@googlegroups.com
> To unsubscribe from this group, send email to
> android-developers+unsubscribe@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+unsubscribe@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+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
No comments:
Post a Comment