Reputation: 394
I have a service S that starts at boot. It has a contentobserver C that starts an intentservice X to do some processing. The default activity A is started by the user.
I want to know if it's possible to bind A to the running service S without stopping it so that I can pass on a resultreceiver R to S that in turn has to be passed on to X.
I want to achieve this so that I can start X again, this time free from C, from the bound service S with R as a parcelable extra. Via R, a progress dialog is updated in A whenever it's run.
Before trying my luck with resultreceivers, I was using notifications, the one from the support library. But the problem was that I was building and showing them again for each iteration of a loop. The alert sound was playing repeatedly for like 300 odd times and that was unpleasant.
Tried my luck with broadcasts but I had some bad experiences. So tossed them away.
Is there any other way around this problem? My problem could be solved if there's a way to update the notification with building it again.
I'm using 4.1.1 build, API 16 in which setlatesteventinfo seems to be deprecated.
I am still open to go back to the idea of updating a running notification. Or a different workaround. Any help will be appreciated.
EDIT:
Using notifications is a way to implement this app in which there would be no need for the resultreceiver and ibinder interfaces.
I can't find the setlatesteventinfo in the API level 16. I'm trying to use the v4 support library. In my implementation, I build a new notification for every iteration of a loop. But I've not figured out a way to keep the sound alert for the first time only and not for the rest. Has anybody succeeded in properly updating a notification?
Upvotes: 3
Views: 11890
Reputation: 520
The android documentation on Bound Services says:
The third parameter is a flag indicating options for the binding. It should usually be BIND_AUTO_CREATE in order to create the service if its not already alive.
Still have to confirm that the onCreate() of service S is not called again though.
Upvotes: 3
Reputation: 5859
I want to know if it's possible to bind A to the running service S without stopping it
That is certainly possible. As Hoan pointed out, you need to call bindService() from your activity. This article has some example code on how to do it.
As for the rest of your question, it seems like it could be broken down into several new questions. It's really hard to comprehend and answer all at once.
Upvotes: 6