Skip to content

Instantly share code, notes, and snippets.

@ET-CS
Last active December 15, 2015 20:59
Show Gist options
  • Save ET-CS/5322683 to your computer and use it in GitHub Desktop.
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/)
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