Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Toast in ASyncTask/onPostExecute with string from resources?

I have the following code:

@Override
protected void onPostExecute(Void arg0) {
                    ...
        Toast.makeText(getBaseContext(), getBaseContext().getResources().getString(R.string.toast_sync_completed), Toast.LENGTH_SHORT).show();
}

It fails (FC). If pass "Test string" instead of getResources().getString(R.string.toast_sync_completed), then it works correctly. What am I doing wrong?

like image 698
LA_ Avatar asked Mar 26 '11 08:03

LA_


1 Answers

Change getBaseContext()... to getApplicationContext().....

Toast.makeText(getApplicationContext(), getApplicationContext().getResources().getString(R.string.toast_sync_completed), Toast.LENGTH_SHORT).show();
like image 155
Kartik Domadiya Avatar answered Nov 20 '22 01:11

Kartik Domadiya