On Wed, Jul 16, 2014 at 6:20 PM, peter <[email protected]> wrote: > I'm just curious what the design discussion was like with not making > Application Context consistently accessible from any point in code. >
You are unlikely to get a true, from-the-source answer as to the reasoning behind an architectural decision, so you won't get anything from this group beyond opinion and speculation. Really, with a system as massive as Android we can all nitpick how some things work or don't work (DialogFragment anyone?). If you believe it's a flaw or needs improvement, you can file a ticket at b.android.com with a suggestion on fixing it, or contribute a fix yourself <https://source.android.com/source/contributing.html>. In Android, you are either already a Context (Activity, Service, etc), have one readily available (Fragment.getActivity(), View.getContext(), etc), or have one lying around as an argument about 99.9% of the time, so you can usually call Context.getApplicationContext() as needed. If this is not good enough for you, you can take the matter into your own hands and create a custom Application class that saves itself as a singleton and provides a globally accessible static method to the instance. > Especially when we have something like Toasts which can be called from any > level of context but requires an application context to function in all > situations. > If you are finding that a Toast fails with a non-application context, then this is more likely a failure in your code logic (using an Activity that has been destroyed, for example) than an issue with Android. ------------------------------------------------------------------------------------------------- TreKing <http://sites.google.com/site/rezmobileapps/treking> - Chicago transit tracking app for Android-powered devices -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] 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 unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.

