How to run LocationUpdatesForegroundService sample without any buttons
anujpanveli opened this issue · comments
Please explain clearly because i tried running this sample without any buttons i am getting null pointer exception on the MainActivity's mService.requestLocationUpdates().
Simply take the code inside the RequestLocationUpdates on click listener, paste in a void function and simply call that function in OnServiceConnected. The service immediately starts on launching the main activity.
void requestlocationupdate()
{
if (!checkPermissions()) {
requestPermissions();
} else {
mService.requestLocationUpdates();
}
}
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
MeterService.LocalBinder binder = (MeterService.LocalBinder) service;
mService = binder.getService();
mBound = true;
requestlocationupdate();
}
Thanks for your great works