1
アクティビティから閉じるよう依頼するまで、実行したいアンドロイドサービスを作成しました。私はSTART_STICKY
返信onStartcommand()
とそれを作成し、正常に動作し、アプリケーションを閉じても実行し続けます。しかし、問題はボタンをクリックしてサービスを停止したいということです(ラジオボタン:バックグラウンドで実行するはい/いいえ)。あなたのボタンのonClick()
方法でアクティビティからSTART_STICKYアンドロイドサービスを停止する方法
public class MyService extends Service {
public MyService() {
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
return START_STICKY;
}
@Override
public IBinder onBind(Intent intent) {
// TODO: Return the communication channel to the service.
throw new UnsupportedOperationException("Not yet implemented");
}
}
をそれが動作思って:)。 –