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???
相关问题
- How can I create this custom Bottom Navigation on
- Bottom Navigation View gets Shrink Down
- How to make that the snackbar action button be sho
- Listening to outgoing sms not working android
- How to create Circular view on android wear?
The
Service
will only run in one instance. However, everytime you start the service, theonStartCommand()
method is called. you can read document from following link :http://developer.android.com/guide/topics/fundamentals/services.html#StartingAService
Presumably, the same thing that happened the first time. That is difficult to say for certain, since we do not have your source code.
If you call
startService()
multiple times, the service will be called withonStartCommand()
multiple times, one per call tostartService()
.Whether it will "restart" will depend upon whether the service was still considered to be running from the previous
startService()
call. If something calledstopService()
orstopSelf()
to stop the service, then a subsequent call tostartService()
will create a fresh instance of the service.Services are natural singletons. There will be zero or one copy of your service running at any point.