Last active
December 15, 2015 20:59
-
-
Save ET-CS/5322683 to your computer and use it in GitHub Desktop.
Android toast stuck solution (from tutorial: http://itekblog.com/android-toast-stuck-solution/)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MyService extends IntentService { | |
... | |
private class DisplayToast implements Runnable{ | |
String mText; | |
public DisplayToast(String text){ | |
mText = text; | |
} | |
public void run(){ | |
Toast.makeText(mContext, mText, Toast.LENGTH_SHORT).show(); | |
} | |
} | |
private Context mContext; | |
private Handler mHandler; | |
/* (non-Javadoc) | |
* @see android.app.IntentService#onCreate() | |
*/ | |
@Override | |
public void onCreate() { | |
mContext = this; | |
mHandler = new Handler(); | |
super.onCreate(); | |
} | |
protected void onHandleIntent(Intent intent) { | |
mHandler.post(new DisplayToast("The right way to toast from IntentService!")); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment