1

I want to develop an Android application that satisfies the following specifications:

  • Record data from a sensor (for example the accelerometer) at an approximate rate of 10-30 Hz.
  • Upload this raw data to a remote server (for example using TCP sockets).
  • The user interface should be minimum, just a pair of buttons to start or stop the recording and transmission of the data.
  • All the process should be unnoticeable for the user and keep working when the screen goes off for several hours.
  • Battery life is not critical (it should last several hours).

Vision: I would like to analyse in quasi-real time the sensor measurements of a group of users without their intervention (apart from starting the application).

After some research, I could manage to perform these tasks separately and inefficiently. I've tried classes such as Service and IntentService, SensorEventListener, etc. I don't know if I should use Thread, Service or IntentService for each task. Specifically, I have serious problems to communicate them.

My questions:

  1. What class(es) do you recommend to use in order to solve this problem?
  2. What task should be done on each of them?
  3. If the tasks are performed in different entities (threads, services, intentservices, etc.), how should I intercommunicate them (I'm thinking about the recording and uploading tasks)?

I am asking for the best-practice structure to solve my problem. You do not need to go into details in terms of developing/coding the solution.

Thank you very much and feel free to ask if something is not clear enough.

David

UPDATE:

After some more research and thanks to DROIDcoder, I manage to design a skeleton for my app:

As this is only a proposition, I add it as an edition. I will post a detailed answer when the whole system works.

The questions remains: can you think about a better design for the application?

Thanks again!

Community
  • 1
  • 1
David
  • 471
  • 1
  • 4
  • 14

2 Answers2

0

here are my suggestion

Upload this raw data to a remote server

You can use JSON parsing for server communications. you will use AsynTask(Background Thread) for background data uploading

All the process should be unnoticeable for the user and keep working when the screen goes off for several hours.

You should use services for background long term processing

Jamil
  • 4,949
  • 4
  • 23
  • 28
0

Finally what I have done:

Issue 1: record data from a sensor on the background for a long period of time. Solved using the class Service to initialize the sensor and listen for callbacks.

Issue 2: communicate the Activity class holding the UI with the Service class. Solved using the startService(Intent myMessage) method from the Activity class combined with a switch in the onStartCommand() method from the Service class to classify the message.

Issue 3: communicate the Service class with the Activity class. Solved registering a custom BroadcastReceiver in the Activity and sending Intents from the Service. I've used it to update a progress bar (in the Activity) during the file uploading (in the Service). An exceptional tutorial can be found here.

Issue 4: upload data to a remote server. Solved using AsyncTask inside the Service like in this site.

Community
  • 1
  • 1
David
  • 471
  • 1
  • 4
  • 14
  • I have been asked to become involved in an artist's project where one solution might require an app such as your are describing. I was wondering how far you got with this. Did you get an app into the app store, or just build one for personal use? – Michael S Dec 08 '15 at 03:10
  • Although the app was designed as a prototype and not as a final product, we definitely used it at work for some months and retrieved a significant amount of data with it. Testers were able to download it from the Google Play store and there were no major issues during the recordings. This is probably not the best architecture possible but it worked for us! – David Dec 09 '15 at 14:36