LA_
LA_

Reputation: 20419

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?

Upvotes: 7

Views: 13456

Answers (2)

Ashish Tikarye
Ashish Tikarye

Reputation: 870

try this code

public static void myprofsList(Activity context){
 static Context = mConext;

protected void onPostExecute(String result) {

      Toast toast=Toast.makeText(mConext,"Succefully Updated Profile Data",Toast.LENGTH_LONG);

  }
}

you've to just pass your string file.

Upvotes: -1

Kartik Domadiya
Kartik Domadiya

Reputation: 29968

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

Toast.makeText(getApplicationContext(), getApplicationContext().getResources().getString(R.string.toast_sync_completed), Toast.LENGTH_SHORT).show();

Upvotes: 11

Related Questions