I am a little new to Android. What I need to do is send data back and forth between the activity and the service locally. The transmitted information is sensitive and cannot be used by other applications. Does this exclude the use of translation and the onBind () function if I understand things correctly?
Thus, the action should send some string parameters to the service. He also needs to tell the service whose activity has started so that the service can respond to the correct class, since many different actions will use this service. After the service displays information through an HTTP request, it is supposed to send this data (only a long string, which will be parsed later) back to the activity that started it. How should I do it? Using static variables / functions is not an option, since again many assets will use this service. Of course, one could use a static array to store classes, but that just seems ugly ... Can we just send simple variables (not objects) via intent? There must be a better way to do this. I surf the Internet for hours.Any help would be greatly appreciated.
EDIT
An example found in Android Developers [ http://developer.android.com/reference/android/app/Service.html#stopSelf(int)] helped implement a local binder.
For those of you who are interested here, there is some more information about my implementation.
- As soon as the onServiceConnected function is called, the function in the service is called to establish what activity it is bound to. After that, both service and activity can interact with each other back and forth.
- Verify that the thread in the service class has a handler. This allows the thread to send a message to its handler after completing its task. The handler then sends the result from the service back to its associated activity. When doing this through a handler, make sure that the application returns to the main thread when it is done.