Hello, guru.

Can you please tell whether this code is guaranteed to restart the service?

stopService(new Intent(this, LocService.class)); startService(new Intent(this, LocService.class)); 

It is important that the service starts from scratch, with zero local variables.
Could it happen that at the time of the startService service will not be destroyed yet, therefore a new one will not be created, and the existing one will be revived.

    1 answer 1

    Want to reset the variables - reset them manually .
    Local pairs exist only within the method. As soon as the code leaves the method, the local variable will cease to exist.

    Therefore, make the message "restart service". Let him do everything himself as you need.

    Update

    In such a small piece of code it is difficult to say whether it will generally work well or not. Suppose there is a static variable in the code. It will most likely remain between similar "restarts".

    • I am interested in this particular code, it seems to work, but there are suspicions that it might be buggy. I want my doubts to be dispelled or confirmed. - osrsoft
    • Updated the answer. - KoVadim