I am having an issue with my app. I need to get Location Updates at certain interval's and therefore basically need to be able to control the GPS module pretty well, this is not really easy with the Android OS. Basically i need to turn the GPS on for 2 min at 5 min interval's. I have the timing down, and i can get the location twice, but then the app crashes with the a RunTime Error - only one Looper may be created per thread. The timing is done in a service class and works well, it removes updates and everything its just this issue i am having.
I origninally had this error - "Can't create handler inside thread that has not called Looper.prepare()" which i fixed with the code below, but now i get the only one Looper error
My looper Thread looks like this (please don't be harsh, i am very new to Android lol)
public void run() {
Looper.prepare();
setLooper(Looper.myLooper());
LocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0,
0, locationListener);
Timer t = new Timer();
t.schedule(new TimerTask() {
@Override
public void run() {
stopLooper();
}
}, TWO_MINUTES);
Looper.loop();
t.cancel();
setLooper(null);
vb.getLm().removeUpdates(ll);
}
Like i said i am new, and i am not sure how to use a Handler. i did get some of this code from a post here at StackOverflow, just used it differently, but its no working.
Please i really need help. Thank you for any responses.
Ok i seem to have found the solution, just need to test it and then wait another 7 hours before i can post an answer lol. Thanks for any views and replies.