Last active
December 6, 2015 14:30
-
-
Save gam0022/c00fa8777a06de37923f to your computer and use it in GitHub Desktop.
IntentServiceでToastを使うと消えなくなる問題に対処する ref: http://qiita.com/gam0022/items/56475779c598c6e8b073
This file contains 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 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(); | |
} | |
} |
This file contains 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 { | |
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