Does your receiver handle the JSON update (i.e. it goes out to the server,
retrieves the updated json from the server and notifies the registered
activities)?
If so, this is not correct. BroadcastReceivers should never ever do long
running tasks.
Instead, your BroadcastReceiver should receive the "synch.my.app" request.
It then would start a Service (preferrably a wakefull IntentService) that
does the actual work (since IntentServices can run for longer times). The
IntentService then sends a "here.is.the.json" broadcast back, when it's
done, to the registered activities.
BTW: Instead of sending back "here.is.the.json" broadcasts, your calling
Activity could add a ResultReceiver to the Intent. The BroadcastReceiver
will send the Intent including this ResultReceiver to the IntentService.
And when the IntentService is done, the IntentService could just call
'send(resultCode, resultData)' to update the calling Activity of the final
result.
On Monday, February 25, 2013 1:25:44 PM UTC-5, stanlick wrote:
>
> I have been experimenting with an easy way to execute "synch" type bursts
> without all the hassle of Services, Loaders, Threads, etc. I have come up
> with a technique that works great, but I'd like to get a consensus
> regarding the pattern. I am performing sendBroadcast("synch.my.app") from
> the activity needing an update. This same activity is registering a
> broadcast receiver registerReceiver(payload, new
> IntentFilter("here.is.the.json")) which is being notified from the
> "synch.my.app" receiver. In other words, my broadcastreceiver is calling
> me back once it has the data. Is this crazy? I'm simply poking my json
> payload into the intent before sending broadcast back to activity.
--
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
---
You received this message because you are subscribed to the Google Groups
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.