android intent - Notify activity when IntentService completes - multiple activities -


up point intentservice(s) has been working great because each intentservice has been receiving requests single activity (sqlite inserts) , responding same activity.

then figured out how load views in activity data same intentservice (sqlite); things getting complicated. say: have @ least two activities making requests (read/insert/update) same intentservice (an intentservice exists each of 10 tables in sqlite database).

main challenge: intentservice has know which activity intent came , send responses (arrays of data or result of insert/update request sqlite db) correct activity.

up till each activity has been communicating intentservice using handler.callback, doesn't seem task. other 2 options resultreceiver , localbroadcastmanger.

i need insight mechanism necessary intentservice identify each intent's source/calling activity responses/results go they're supposed go.

thanks!

quasaur, if committed using intentservice, i'm not sure there else outside of handlers , other components mentioned use. however, intentservices designed fire-and-forget kind of component, 1 not need communicate caller. if need work in service , communicate callers directly, better off binding regular service.

from documentation: intentservice subclass of service uses worker thread handle start requests, 1 @ time. best option if don't require service handle multiple requests simultaneously. need implement onhandleintent(), receives intent each start request can background work.

another issue see requirement route responses particular activities. should have 1 activity @ time. routing more 1 suppose have more 1 @ time problematic.

all put side, if looking database abstraction layer, recommend contentprovider. it's core component of android used everywhere in system. documentation can found here: http://developer.android.com/reference/android/content/contentprovider.html

keep in mind contentproviders difficult write hand , harder write correctly. gave talk @ our local android developer meetup discussed tool available eclipse generate them you. it's changed way develop android apps completely. feel free give look: https://www.youtube.com/watch?feature=player_embedded&v=5ldxerza_ak. i'm second speaker.


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -