Reputation: 805
I have a main Activity which launches an IntentService class SchedulerWebSocketService.class
Intent webSockIntent = new Intent(getApplicationContext(), SchedulerWebSocketService.class);
startService(webSockIntent);
The service runs a web socket client. Based on the message received, the app will interpret the message, launching a background thread to begin a new task, such as taking a picture. The main Activity contains a variety of parameters, which need to be passed to the IntentService and then to the new runnable threads.
I know I can use the putExtra to transmit a few objects, such a strings. How do I pass a reference to the current Activity or other custom objects, which are shared between the main Activity and the new thread, which is launched by the IntentService?
Is there a way to somehow modify the constructor of the intent service and pass the argument to this new constructor when I call new Intent(...)?
Upvotes: 1
Views: 3861
Reputation: 64700
The recommended way to pass big objects is to bind to the service: once you do that your Activity will get access to the actual service and you can call methods on the service and pass it objects.
Upvotes: 1