Reputation: 1
I have a question (not code based) regarded to communication between different app components.
I want to write a "big" Logging/Tracking tool. This tool does have about 3 Parts.
In part 2 and part 3 I wanna set the settings of Location API (e.g. Accuracy and refresh time) and Sensor API, additionally in part 3 I wanna activate/deactivate different Sensors for logging.
In part 1, my main activity, I wanna start the complete logging/tracking.
It's more explained in the attached picture.
I've no problem with coding in JAVA. My problem is, I'm new in Android. I don't have any problem with one Activity. But with more than one... uuuh. I dont understand the communication between my MainActivity and for example Location Activity (names regarded to the picture)
In JAVA I would have my own classes Location/Sensor in which I would store my logic.
After click on "Click to turn on tracking" I would create 2 Threads (for Location and Sensors) in which tracking would start. Both would save their data in Lists and after I stop tracking it would be written in textfiles as I want it.
And in Android? In my special case? Do I have 3 Activities? Do I communicate via Intents? It's a bit confusing because in this case all of these Activites would have their own onCreated()/onStop()/... Methods. So I do need to seperate my tracking/logging logic from my Activities because I only wanna choose/set my settings and would close my Location/Logging Activity to turn back to my MainActivity after that.
Would be great if you could recommend a tutorial or help me otherwise.
Upvotes: 0
Views: 98
Reputation: 451
Assuming you wish to receive location and sensor events even when your app is in the background, what I'd suggest is:
Remember that when doing things in the service (e.g. listening to sensor events) the device's application processor may go to sleep and you will stop receiving events. To prevent this you would need to acquire a WakeLock but be careful not to drain the battery. Also, when device is restarted, you'll need re-enable your location/alarm listeners.
At the end, you might end up with a architecture like this:
Upvotes: 1