There is no true way. You only need Context:
- getResources()when you are in- Activityclass (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- Fragmentclass
- context.getResources()when you pass- Contextthrough parameter
- view.getContext().getResources()when you get- Contextfrom 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”