I am a beginner in Android development. I'm creating a small app that takes a picture after a device reaches a certain speed. However, one of the parameters of the requestLocationUpdates method (which of course is used to track the user’s location), requires a Looper in its third prameter. How would I create a looper? And where should it go? My requestLocationUpdates method currently looks like this: (I have null in place of a Looper)
protected void requestUpdates() {
if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
MC.requestLocationUpdates(locRequest, mLocationCallback, null);
}
}
The Android dev site has advised to do something like this:
class LooperThread extends Thread {
public Handler mHandler;
public void run() {
Looper.prepare();
mHandler = new Handler() {
public void handleMessage(Message msg) {
// process incoming messages here
}
};
Looper.loop();
}
}
However, I still have no clue where to put this code, what to do with it once I put it in, or how I can use it within my MainActivity. Any suggestions will be greatly appreciated.