Android: Communication of different Activities -
Android: Communication of different Activities -
i have question (not code based) regarded communication between different app components.
i want write "big" logging/tracking tool. tool have 3 parts.
part, main activity. wanna start/stop tracking/logging @ point via clicking/declicking checkbox part, location part, in wanna track location history of user (via location api) part, sensor logging part, in track sensor info can users smartphone.in part 2 , part 3 wanna set settings of location api (e.g. accuracy , refresh time) , sensor api, additionally in part 3 wanna activate/deactivate different sensors logging.
in part 1, main activity, wanna start finish logging/tracking.
it's more explained in attached picture.
i've no problem coding in java. problem is, i'm new in android. don't have problem 1 activity. more one... uuuh. dont understand communication between mainactivity , illustration location activity (names regarded picture)
in java have own classes location/sensor in store logic.
after click on "click turn on tracking" create 2 threads (for location , sensors) in tracking start. both save info in lists , after stop tracking written in textfiles want it.
and in android? in special case? have 3 activities? communicate via intents? it's bit confusing because in case of these activites have own oncreated()/onstop()/... methods. need seperate tracking/logging logic activities because wanna choose/set settings , close location/logging activity turn mainactivity after that.
would great if recommend tutorial or help me otherwise.
assuming wish receive location , sensor events when app in background, i'd suggest is:
keep tracking settings in persistent storage, e.g. sharedpreferences, configuration screens (activity/fragment) read , write these settings in main activity, when checkbox checked, read latest configuration, start tracking , persist tracker "on" to request locations, utilize methods take pendingintent argument, e.g. http://developer.android.com/reference/android/location/locationmanager.html#requestlocationupdates(long, float, android.location.criteria, android.app.pendingintent) , set target of pendingintent intentservice process , persist locations to request sensor events, need active listener. create separate service e.g. invoked regular interval via alarmmanager collect sample of sensor data, can persistedremember when doing things in service (e.g. listening sensor events) device's application processor may go sleep , stop receiving events. prevent need acquire wakelock careful not drain battery. also, when device restarted, you'll need re-enable location/alarm listeners.
at end, might end architecture this:
ui: activities edit tracking settings , enable/disable tracking trackinghelper: class logic enable/disable tracking - registers location listener , alarms triggers sensorservice collect sensor data sensorservice: service registers hear sensor events requested interval , stops itself loggerservice: intentservice receives location objects (and maybe other data) , persists them bootreceiver: broadcastreceiver calls trackinghelper.starttracking (if tracking enabled) android android-activity
Comments
Post a Comment