2

I want to allow my app to send GPS data to server constantly in background after log in until app close..

I use locationManager to send GPS data....

I start to think about manual thread, AsynTask, to handle it....

Question:

  • locationManager.requestLocationUpdates(provider, 60, 5, this); it will update automatically after 60 ms???

  • Are there any good strategy to get GPS data and send it constantly to server in background until app closes?

citizen conn
  • 15,300
  • 3
  • 58
  • 80
sayvortana
  • 825
  • 2
  • 16
  • 32
  • Dude keep in mind that any device that uses your app for a reasonable amount of time will experience serious battery drainage. :P – Vinay Jul 22 '11 at 02:18

2 Answers2

1

locationManager.requestLocationUpdates(provider, 60, 5, this); it will update automatically after 60 ms???

Yes or until it recognizes a distance difference of at least 5 meters, whichever takes place first.

Are there any good strategy to get GPS data and send it constantly to server in background until app closes?

You could use http sockets. http://socket.io/ Sockets are fun: Good beginners tutorial to socket.io?

Community
  • 1
  • 1
citizen conn
  • 15,300
  • 3
  • 58
  • 80
1

Start an Android Service(android sdk class) in the background that automatically sends HTTP POSTs to a web service with the location that you are getting from the LocationManager class. You could persist each unique location in a SQLite database so that every location is sent. If the connection to the server is terminated a SQLite database could persist the data until the connection is re-established.

  • that's very helpful, any tutorial about that by the way ,..,. Thx zzz – sayvortana Jul 22 '11 at 08:42
  • For a SQLite database I would look at the Notepad tutorial on the developer.android.com website. For the web service it is going to depend on what you would like to use to create your web service. I like to use WCF .NET web services. – zzzzzzzzzzzzzzzzzzzzzzzzzzzzzz Jul 22 '11 at 13:26
  • I forgot to mention your service should be running in a separate thread. It won't do this automatically unless you are using IntentService. – zzzzzzzzzzzzzzzzzzzzzzzzzzzzzz Jul 22 '11 at 13:27
  • Yes, but it shouldn't. You either need to create an IntentService that runs in a background thread, or you need to create your own thread to run a normal service in the background. If you run a service in your main thread it will cause some problems with the UI. – zzzzzzzzzzzzzzzzzzzzzzzzzzzzzz Jul 25 '11 at 13:04