2

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");
}
4

1 に答える 1

4

onStartCommandstopSelf();メソッド内で呼び出して、サービスを終了してみてください。これはあなたがサービスのために意図されたものを提供することを要求しません。Intent

于 2012-10-02T15:17:02.133 に答える