0

I'm developing an application for a small research project that utilizes the ActivityRecognition API and the GPS. What I'm trying to achieve is to have both APIs running as a background process, and record current data periodically in a log file. This log file can then be manually analysed after data is collected.

My trouble is understanding the best way of going this. I originally developed from the ActivityRecognition sample app. My process is as follows:

  1. Create location listener via requestLocationUpdated when button in MainActivity is tapped. Also create ActivityRecogition listener in MainAcitivity.
  2. When location update event is triggered, sending data via broadcast.
  3. If MainActivity is running, listen to broadcast via broadcastReciever, update gui, store last update in class-wide scope variable (in MainActivity)
  4. When ActivityRecognition gets an update, log the data in a file along with the GPS data stored in class-wide scope variable in MainActivity.

The obvious problem with this is that although the location service operates in the background even when the MainActivity has hit an onPause, the ActivityRecognition nor the file logger are not running in the background as a service so require MainActivity to be running.

What's the best practice for handling multiple background processes for one purpose? To create on background service to handle both of these? Then run this on app onCreate/button tap? Then send data to MainActivity (if it's there to listen) via a broadcast message?

Sнаđошƒаӽ
  • 16,753
  • 12
  • 73
  • 90
kirgy
  • 1,567
  • 6
  • 23
  • 39

1 Answers1

1

Kirgy.. Use service for the gps task and for the activityRecognition make use of a receiver and an intent that triggers a broadcast each time activityRecognition occurs

Chijioke
  • 26
  • 3
  • To clarify - are you saying to move the ActivityRecognition code to the location service? Having both run under one service, then having "events" sent to the MainActivity via a broadcast when needed to update the GUI? Is this the best/common way of achieving this? – kirgy Mar 30 '16 at 14:53
  • Nope... I can have multiple services... Use intent Service for the activityRecognition so imediatelt it is done running it task.. is terminates it self.. Got it ?.. and post a snippet of what you have done so far.. so I can get a clearer view – Chijioke Apr 01 '16 at 07:39