yayaa / LocationManager

Simplify getting user's location for Android
806 stars 187 forks source link

ContinuousTask delayed null exception #74

Closed pmsferreira closed 4 years ago

pmsferreira commented 6 years ago

Sometimes when I call getLocation(), I get this exception "Attempt to invoke virtual method 'void com.yayandroid.locationmanager.helper.continuoustask.ContinuousTask.delayed(long)' on a null object reference".

Configuration

private static final int WAIT_PERIOD = 1000;

public static LocationConfiguration getConfiguration(){

    LocationRequest locationRequest = LocationRequest.create()
            .setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);

    //google play services configuration
    GooglePlayServicesConfiguration gpsc = new GooglePlayServicesConfiguration.Builder()
            .locationRequest(locationRequest)
            .askForGooglePlayServices(true)
            .askForSettingsApi(true)
            .ignoreLastKnowLocation(true)
            .setWaitPeriod(WAIT_PERIOD)
            .build();

    //location configuration
    LocationConfiguration.Builder locationConfiguration = new LocationConfiguration.Builder();
    locationConfiguration
            .keepTracking(false)
            .useGooglePlayServices(gpsc)
            .askForPermission(new PermissionConfiguration.Builder().build())
            .useDefaultProviders(new DefaultProviderConfiguration.Builder()
                    .setWaitPeriod(ProviderType.DEFAULT_PROVIDERS, WAIT_PERIOD)
                    .build());

    return locationConfiguration.build();
}

Logs

LocationManager: We got permission! DispatcherLocationProvider: GooglePlayServices is available on device. DispatcherLocationProvider: Attempting to get location from Google Play Services providers... : Attempt to invoke virtual method 'void com.yayandroid.locationmanager.helper.continuoustask.ContinuousTask.delayed(long)' on a null object reference

yayaa commented 6 years ago

Thanks for reporting, are you able to reproduce this issue in a particular pattern / usecase? Or It happens randomly?

pmsferreira commented 6 years ago

Hi @yayaa it only happens randomly when i use getLocation() inside a thread runnable:

final Handler handler = new Handler(); Runnable runnable = new Runnable() { @Override public void run() { if(location != null ) { / app code / } }); }} else handler.postDelayed(this, 500); } }; handler.post(runnable); getLocation();

stoefln commented 6 years ago

Same here!

yayaa commented 4 years ago

Sorry for late action, but this should solve the problem.

I'll try to do other bugfixes as well, and release 2.1.0 version as short term plan.