문제

I'm making an application in Android that should detect, classify and map road surface anomalities (potholes, speedbumps, road rugosity/roughness, etc.) using mobile sensors (accelerometer, GPS), and I'm in need of a little advice on some design choices since I'm a quite new to Android development.

So far, I have created a background service (using AsyncTask) that reads the sensors and stores data in buffers. I need to use the data provided by the service to perform some low level filters and computations which I must then use for the pothole/speedbump/rugosity/mapping/etc. detection procedures.

I want to somehow modularise/layer these procedures such that the lowest level filters provide the data for higher level procedures and I'd love some suggestions/best practices on how to achieve this.

I'd also like to know how to consume the data provided by the background service (timer triggered event at a given interval, ...) ?

도움이 되었습니까?

해결책

I am no Android expert, but I have been developing an app with similar structure than yours. To accomplish it, I am using an actual long-running Service for the top-level background proccessing and data management which launchs different Threads to perform low-level computing and data acquisition.

For the communication threads->service, I am registering a BroadcastReceiver in the service and broadcasting information from the threads. To communicate service->activities I am just binding the service to the activity as described in "Extending the Binder class" in Android API Guide.

So the structure is like this: Activity --(bound)--> Service --(spawns multiple)--> Thread

You can get communication in top-down direction by directly calling public methods in the Service and Threads and down-top by broadcasting messages and receiving them in the Activity and Service.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top