There is no true way. You only need Context
:
getResources()
when you are in Activity
class (or MyActivity.this.getResources()
when you are calling from inner class, while being in Activity class)
getActivity().getResources()
(or even getContext().getResources()
) when you are in Fragment
class
context.getResources()
when you pass Context
through parameter
view.getContext().getResources()
when you get Context
from your View
The following two have "equivalent Context
", since you are in Fragment
like I can assume by your question tag:
pDialog.setMessage(getContext().getResources().getString(R.string.please_wait));
pDialog.setMessage(getResources().getString(R.string.please_wait));
where
pDialog.setMessage(getActivity().getApplicationContext().getResources().getString(R.string.please_wait));
you get Context
of entrie application.
Here some reference:
Difference between getContext() , getApplicationContext() , getBaseContext() and “this”