0
I’m studying Services on Android, I can perform the same in a simple test just for understanding, but I can’t stop it in main Activity at all. I believe I’ve tried everything. I tried to put stopSelf() in onDestroy, I changed the call of stopService() in the main acitivity anyway, but it doesn’t work, the service keeps running. It shows in onDestroy() that it was destroyed, but it is still working. I would like to better understand this situation.
Another question would be on the basis of... Will I be able to stop the service, but as it is linked to a thread to the main part, it will only actually stop when what is inside the thread ends?
Setting the field.
private Intent serviceIntent;
Performing startService() and stopService() at the click of their respective buttons.
serviceIntent = new Intent(this, MyIntentService.class);
startService(serviceIntent);
ou
stopService(serviceIntent);
Intentservice Extended Class. Only thing it does is a counter from 0 to 20 in the Log.
@Override
protected void onHandleIntent(@Nullable Intent intent) {
// Recebendo o valor passado pela intent.
int numero = intent.getIntExtra("numero", 50);
for(int i = 1; i < numero; i++) {
Log.d("onHandleIntent", ""+i);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
That seems strange to me. I made a small example that works well for me, you can make some modifications and see what happens: https://github.com/calheiros/my-app.git
– jefferson
The worst that’s pretty much the same thing that you did, the difference is that I put a down count until a certain amount.
– ijrdev