Skip to content

Instantly share code, notes, and snippets.

@gam0022
Last active December 6, 2015 14:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gam0022/c00fa8777a06de37923f to your computer and use it in GitHub Desktop.
Save gam0022/c00fa8777a06de37923f to your computer and use it in GitHub Desktop.
IntentServiceでToastを使うと消えなくなる問題に対処する ref: http://qiita.com/gam0022/items/56475779c598c6e8b073
public class DisplayToast implements Runnable {
private final Context mContext;
String mText;
public DisplayToast(Context mContext, String text){
this.mContext = mContext;
mText = text;
}
public void run(){
Toast.makeText(mContext, mText, Toast.LENGTH_SHORT).show();
}
}
public class MyService extends IntentService {
Handler mHandler;
public MyService(){
super("MyService");
mHandler = new Handler();
}
@Override
protected void onHandleIntent(Intent intent) {
mHandler.post(new DisplayToast(this, "Hello World!"));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment