Question on the Context parameter to makeToast()



I’ve got a quick theory question regarding the Context parameter of makeToast(). The book says that the Context parameter is needed by makeToast in order for the Toast class to find and use the String’s resource ID. Why is this the case? The resource IDs within R.Java seem to be associated with the entire App - not just a particular Activity. Thanks in advance!


Toast actually doesn’t care too much that it is specifically an Activity - it can make do with any old Context. But it does need some Context associated with your application to be able to make use of your app’s resource id.

(Even if Toast weren’t using your resource id, it’d still need a Context. Otherwise, it would not be able to display anything to the screen, which the OS manages. You can’t do anything OS related without a Context.)