Android的服务......让敬酒时,应用程序崩溃 [英] Android Service...application crashes when making a Toast
本文介绍了Android的服务......让敬酒时,应用程序崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的服务类:
public class MySrv extends Service {
@Override
public void onCreate() {
// TODO Auto-generated method stub
super.onCreate();
final Context c = getApplicationContext();
Timer t = new Timer("mytimer");
TimerTask task = new TimerTask() {
@Override
public void run() {
// TODO Auto-generated method stub
Toast.makeText(c, "Not a beautyfull day today...", Toast.LENGTH_SHORT).show();
}
};
t.schedule(task, 5000, 6000);
}
@Override
public IBinder onBind(Intent intent) {
// TODO Auto-generated method stub
return null;
}
}
在Toast.makeText()的应用程序崩溃...所以我在做什么错了?
The application crashes at Toast.makeText()... So what am I doing wrong?
推荐答案
这里的问题是,你正试图以更新计时器线程的UI,你应该使用一个处理程序这一点。
The problem here is that you are trying to update the UI in the timers thread, you should use a Handler for this.
这篇关于Android的服务......让敬酒时,应用程序崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文