-1

I'm creating a tracking app and i want to get location from GPS and then keep coordinates in string (Because I must use this later).

Step-by-step how app looks

1) I push button "get location"

2) I'm connecting with gps and (after some time) i get locations and display them in editText

3) After change string from null to coordinates i want to save it and keep it by using shared preferences because i need them later (even after re open app)

What should I do to save that string in proper moment (when it's changed from null to coordinates)

Gopal Singh Sirvi
  • 4,539
  • 5
  • 33
  • 55
Kadou
  • 1
  • 1
  • the same way you update your string...you can use a [location listener](http://developer.android.com/reference/android/location/LocationListener.html) and save the coordinates there – Paizo Jul 20 '15 at 12:57
  • See this documentation: http://developer.android.com/training/basics/data-storage/shared-preferences.html – krystian71115 Jul 20 '15 at 12:58
  • Seems like you need something like this [1]: http://stackoverflow.com/questions/7391891/how-to-check-if-an-edittext-was-changed-or-not – Michu93 Jul 20 '15 at 13:00
  • I know how to use sharedpreferences but I just don't know how(when) i should i save it. Updating this string is quite complicated because getting location may takes 30 sec or 5 min and i want to save without using buttons or something. It's should be some kind of observer i think so – Kadou Jul 20 '15 at 13:03
  • @MichałWalkowiak You made it, probably it's this what I'm looking for :) – Kadou Jul 20 '15 at 13:10

1 Answers1

0

You should do your saving inside this method

https://developer.android.com/reference/android/location/LocationListener.html#onLocationChanged(android.location.Location)

This is called when the location is retrived.

zarcel
  • 1,211
  • 2
  • 16
  • 35