What are the best practices for location-based Android application architecture?

I want to know what are the best practices for Android architecture / location based workflow?

My current code uses several Activity and one support service and several AsyncTask.

I start my service, as soon as my application starts, I make all the HTTP calls and disassemblies in my service. And I also wrote a subclass of AsyncTask to get the location of the user. I run AsyncTask every time I need to update the user's location. AyncTask calls LocationManager.requestLocationUpdates () and requests the location as quickly as possible. My strategy for this is:
1. First I get LastKnownLocation for GPS and network and compare them using the http://developer.android.com/guide/topics/location/obtaining-user-location.html#BestEstimate method.
2. When 3 GPS locations and 5 network locations are received, or one or both of the GPS and network did not respond after 1 minute, I will stop the task.
3. I am returning the best mark I have.

Locating AsyncTask starts in the Service, and I installed AlarmService within 5 minutes to send my Intent service to check if the user location needs to be updated. My minimum interval between two AsyncTask is 10 minutes. The user can request location updates manually by simply clicking a button.

The above describes how I implement the Location service in my application.
I need to know if my practice is suitable. If not what is wrong? If so, is there anything that can be improved?

+4
source share
2 answers

I think you pretty much got it. I have a very similar solution where I want to "enter and exit" as soon as I can.

I implemented a "precision" check in my algorithm. I provide the service within 1 minute from the start to get the BEST possible location, or I will exit even earlier if I get a fix of 25 m or better.

In addition, I do not use AsyncTask for the location itself. The service does not block the stream, it receives and processes callbacks from the LocationManager, so I don’t see why you want to make AsyncTask.

When I finished getting the location and going to exit - I call an asynchronous task to process the Http message to the server.

As for the interval - I give custom options 5/15/30 / 1hr and 1 / 2day. I use inaccurate alarms for this - supposedly better on battery.

+4
source

This is not an answer for one, but here are some additional points. Reto Meier, in its Pro Android tips on Google IO, suggested not using Wi-Fi if the battery was low.

It can also be expanded to a location. Let the user know that his battery is too weak and the application will not use GPS and the network provider, instead he will use the last known location, which may be inaccurate.

You have not mentioned this, so I will move on to the worst case scenario, which you cannot check if location providers are enabled. You need to check for the same and warn the user about enabling the location service if all providers are disabled.

+4
source

All Articles