从服务中使用处理器更新活动 [英] Update Activity from service using handler
本文介绍了从服务中使用处理器更新活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想改变状态的切换按钮
在我的活动当事件在服务发生。任何人都可以请帮我实现这个使用的处理程序?
我的意思是我应该在哪里写的code创建的处理程序以及如何从一个服务触发了吗?我读了类似的帖子,但是,他们并没有真正有助于实现这一目标。
I want change the state of a ToggleButton
in my Activity when an event occurs in a service. Can anybody please help me to implement this using Handler?
I mean where should I write the code to create the handler and how to trigger it from a service? I read similar posts but, they were not really helpful in achieving this.
推荐答案
在你的Activity
In your Activity
public class MyActivity extends Activity {
public static Runnable runnable;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
runnable=new Runnable(){
@Override
public void run() {
//Change status here
}
};
从服务
Handler handler=new Handler();
handler.post(MyActivity.runnable);
这篇关于从服务中使用处理器更新活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文