本文介绍了从IntentService创建敬酒的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想有我的IntentService显示敬酒消息,但是从onHandleIntent消息发送时,敬酒演出,但被卡住,屏幕永不阔叶。我猜它是因为onHandleIntent方法不会发生在主服务线程,但我怎么能移动吗?
I'm trying to have my IntentService show a Toast message,but when sending it from the onHandleIntent message, the toast shows but gets stuck and the screen and never leaved.I'm guessing its because the onHandleIntent method does not happen on the main service thread, but how can I move it?
有没有人有这个问题,并解决它?
Has anyone has this issue and solved it?
推荐答案
在的onCreate()
初始化处理程序
然后张贴到它从你的线程。
in onCreate()
initialize a Handler
and then post to it from your thread.
private class DisplayToast implements Runnable{
String mText;
public DisplayToast(String text){
mText = text;
}
public void run(){
Toast.makeText(mContext, mText, Toast.LENGTH_SHORT).show();
}
}
protected void onHandleIntent(Intent intent){
...
mHandler.post(new DisplayToast("did something"));
}
这篇关于从IntentService创建敬酒的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!