我创建了一项意向服务。现在我想停止该服务的活动如何停止该服务?我的代码是:
我的活动.java
@Override
public void onCreate(Bundle savedInstanceState) {
Intent intent = new Intent(this, myService.class);
intent.putExtra("myHand", new Messenger(this.myHand));
startService(intent);
}
我的服务.java
public class myService extends IntentService {
@Override
protected void onHandleIntent(Intent intent) {
String signal = intent.getAction();
if (signal != null && signal.equals("stop")) {
stopSelf();
} else {
t.schedule(new TimerTask() {System.out.println("print")}, 0, 10000);
}
}
}
单击按钮停止服务
Intent in = new Intent(this, myService.class);
in.setAction("stop");
stopService(in);
谁能帮我停止服务?