-1

I created an Asynctask and started it in an activity, I have shown a toast in onPostExecute before completing asynctask I call finish() activity but the toast is still showing.

Lehue
  • 425
  • 8
  • 26
Mohd Shahzad
  • 249
  • 2
  • 3
  • 9
  • 3
    Possible duplicate of [How to stop displaying message from Toast when Application is closed?](http://stackoverflow.com/questions/14806651/how-to-stop-displaying-message-from-toast-when-application-is-closed) – Mujammil Ahamed Nov 15 '16 at 09:45
  • You can use `Toast.LENGTH_SHORT` to show it for a shorter period of time, assuming you use `Toast.LENGTH_LONG`. – Lehue Nov 15 '16 at 09:45
  • What do you want to do exactly? Please write some code. – aldakur Nov 15 '16 at 09:45
  • please post your code.. – Priya Jagtap Nov 15 '16 at 09:46
  • Are you calling finish() method before the AsyncTask is completed? If so, you need to cancel your AsyncTask first. – Nelson Almendra Nov 15 '16 at 09:47
  • You can use weak reference to the activity's view (any view) in asynctask, it will be null when activity finishes. if this view's weak reference turns out to be null, don't show toast. (this code is to be done in AsyncTask) https://developer.android.com/training/displaying-bitmaps/process-bitmap.html you might find this link useful. – Rahul Nov 15 '16 at 09:56

1 Answers1

0

Do the following

Toast t = Toast.makeText(this,"Toasttext",Toast.LENGTH_LONG);
t.show();

Then you can cancel all the Toast by calling

t.cancel();
Abhishek Singh
  • 9,008
  • 5
  • 28
  • 53