I was reading over the android documentation for toasts, and noticed that the example code uses getApplicationContext()
rather than getActivity()
or this
. From the docs:
Context context = getApplicationContext();
CharSequence text = "Hello toast!";
int duration = Toast.LENGTH_SHORT;
Toast toast = Toast.makeText(context, text, duration);
toast.show();
Based on other sources, I have been given to understand that using getApplicationContext()
is generally bad practice. Are toasts somehow an exception? If so, why? Or are the Android docs just wrong in this case?