java - How to make a callback from a Service to an Activity -
Sorry for annoying you again, but I still can not find a way to callback service from my activity. ..
Similar questions were found -
// Callback interface interface MyCallback {void callbackCall (); } // class callback class worker {MyCallback callback; Void onEvent () {callback.callbackCall (); }} // Option 1: Class Callback implies MyCallback {void callback () {// callback code goes here}} worker.callback = new callback (); Not yet sure how to integrate that sample into my project.
Any suggestions or links to clear the tutorial would be nice!
This kind of callback (Observer Pattern) that you are showing in your example is a service and an activity Use Supervisor not to work between, when from Class A, you want to create an example of class B and send the callback from B to A. Regarding services and activities, things are completely different. AFAICT, if you want to callback your activity with service , then use the best method to use it ResultReceiver : < There are many interesting things about / p> - , it gets its constructor (which you have to make inside the activity), which will allow you to change the UI service.
- This is how you can reference your
result receiver in intent extras that you used to start the service. Its onReiveive method has result code integer which allows you to generate different types of callbacks (this is if there are several methods in your callback interface). In addition, it receives one that you can use to insert all the result data. On the other hand, if you want to callback (not sure that the word is correct in this case), from your activity From your service , I think you need to send a broadcast message or something like that.
Comments
Post a Comment