0

I have an activity that roughly follows this structure:

public class myActivity extends Activity implements myCallback{
   //Code

   @Override
   public void onCreate(Bundle savedInstaceState){
       super.onCreate(savedInstanceState);
       new myAsyncTask(myActivity.this).execute();
   }
   public void myCallback(Context context){
   //Code
   Toast.makeText(context,"Hello",Toast.LENGTH_SHORT).show();
   }
}

And myAsyncTask has the myCallback() interface defined and it calls it eventually. No matter what I do, whatever UI element I try to show, be it a Toast or a ProgressDialog, it won't show. Nor do I get any exceptions. The rest of the callback code gets perfectly executed. Why is this?

Moises Jimenez
  • 1,962
  • 3
  • 21
  • 43

2 Answers2

0

Try using:

public class myActivity extends Activity implements myCallback{
   //Code
   Context mContext;


   @Override
   public void onCreate(Bundle savedInstaceState){
       super.onCreate(savedInstanceState);
       mContext = this;
       new myAsyncTask(getApplicationContext()).execute();
   }
   public void myCallback(Context context){
   //Code
   Toast.makeText(mContext,"Hello",Toast.LENGTH_SHORT).show();
   }
}
Raghav Sood
  • 81,899
  • 22
  • 187
  • 195
0

Instead of using context , use getApplicationContext... i hope it will show toast... like this

   Toast.makeText(getApplicationContext(),"Hello",Toast.LENGTH_SHORT).show();
G M Ramesh
  • 3,420
  • 9
  • 37
  • 53