【发布时间】:2011-04-29 14:44:53
【问题描述】:
我在本地创建了一个服务,想知道是否有办法调用它的方法。我正在考虑使用流套接字并让客户端向服务发送消息,但这似乎需要做很多工作。 我必须创建服务的代码
public class Welcome extends Activity implements OnClickListener{
private static final int NOTIFY_ME_ID=1337;
private Timer timer=new Timer();
private int count=0;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// set up buttons
View mAppoitment = findViewById(R.id.appoitment);
mAppoitment.setOnClickListener(this);
// start background thread
Log.v("TED:", "Starting thread");
startService(new Intent(Welcome.this,
BackgroundService.class));
泰德
【问题讨论】:
-
向服务发送
Intent。服务应该注册一个广播接收器来接收特定的意图。