Vivek
Vivek

Reputation: 63

Stop fetching GPS location if application goes in background in ANDROID

I am currently working on a task where i need to fetch the locations from GPS. The concern i am having here is that once i obtain the location & the task goes completed, after this if the application goes in background i do not wish to obtain any locations until & unless my application is back on screen (foreground) whatis currently not happening. (kindly note here i am not talking about switching the activity from one to another via intent as my app has only one screen & one activity).

I wish to know what place exactly the code to handle this situation must go & how can i do achieve this. I have tried with setting the instance to null & remove update but it proves ineffective. May be i am putting it at wrong place i am putiing it outside onCreate() inside the class extending activity.

Upvotes: 1

Views: 1730

Answers (1)

Reno
Reno

Reputation: 33792

Call requestForLocationUpdates() in onResume()

and removeUpdates() in onPause()

Once I obtain the location & the task goes completed

If you just want one Lat, Lon fix: don't use the tracking mode, instead use : requestSingleUpdate()

Upvotes: 4

Related Questions