使用onStartCommand
方法时如何让我的服务停止?
我知道我必须使用stopService()
但是Eclipse给了我一个错误。
到目前为止我有这个代码:
package be.pegus.classapp;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.os.IBinder;
import android.util.Log;
public class ClassService extends Service {
private static String tag = "something";
@Override
public IBinder onBind(Intent intent) {
// TODO Auto-generated method stub
return null;
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
return Log.d(tag, "k");
}
@Override
public void onDestroy() {
// TODO Auto-generated method stub
super.onDestroy();
Log.d(tag, "destroy");
}
答案 0 :(得分:2)
您可以尝试在 onStartCommand 方法中调用stopSelf();
来完成您的服务。这不需要您提供用于服务的Intent
。