I am developing an android app that has a button and two EditTexts. When the button is pressed, a service starts and the data from the two EditTexts pass to it. If the user changes the data and presses again the button, what will happen?? Will the service restart again with the new data??? Or will it create two services with different data???
If the user changes the data and presses again the button, what will happen?
Presumably, the same thing that happened the first time. That is difficult to say for certain, since we do not have your source code.
Will the service restart again with the new data?
If you call startService()
multiple times, the service will be called with onStartCommand()
multiple times, one per call to startService()
.
Whether it will "restart" will depend upon whether the service was still considered to be running from the previous startService()
call. If something called stopService()
or stopSelf()
to stop the service, then a subsequent call to startService()
will create a fresh instance of the service.
Or will it create two services with different data?
Services are natural singletons. There will be zero or one copy of your service running at any point.