Reputation: 19
I need to stop the service from itself and I use the stopSelf
method, but the service is not stopped.
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
int hour = MainActivity.sa3a;
int minute = MainActivity.dakika;
java.text.DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
Date date = new Date();
System.out.println(dateFormat.format(date));
int x = date.getHours();
int y = date.getMinutes();
String n = String.valueOf(x);
Toast.makeText(send.this,n, Toast.LENGTH_SHORT).show();
if (hour == x && minute == y) {
Toast.makeText(send.this, "start", Toast.LENGTH_SHORT).show();
send.this.stopSelf();
Toast.makeText(send.this, "stop_Self_is_Not_work", Toast.LENGTH_LONG).show();
} else {
Toast.makeText(send.this, "yOKKKKKK", Toast.LENGTH_LONG).show();
}
return START_STICKY;
}
Upvotes: 0
Views: 2551
Reputation: 772
In order to see that service is indeed stopping, you need to override the onDestroy() callback. Make a toast you want to show in the onDestroy method and then when you call stopSelf() your toast should show.
If the toast in your current condition is not shown, means the condition is not met. If you only call stopSelf from that condition, the service will not be stopped. You need to further review your conditions to guarantee stopping the service where you wish.
Upvotes: 1