Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initialize location manager if null when getting last location #348

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ apply plugin: 'realm-android'
apply plugin: 'com.jfrog.bintray'
apply plugin: 'maven-publish'

version '0.8.9'
version '0.8.10'

project.version = this.version

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@ public void onResult(@NonNull LocationSettingsResult locationSettingsResult) {
@Nullable
@Override
public Location getLastLocation() {
if (locationManager == null) {
locationManager = (LocationManager) context.getApplicationContext().getSystemService(Context.LOCATION_SERVICE);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We may need to investigate why location manager is getting null. With this fix we don't know which other methods maybe broken because of this.

Either create a method locationManager() that if the references location manager is null reinitializes it so that it can be used in other methods until its known why location manager is becoming null

}
Location lastLocationFromProvider = locationManager.getLastKnownLocation(getProvider());
return lastLocationFromProvider != null && (lastLocation == null || lastLocationFromProvider.getTime() > lastLocation.getTime()) ? lastLocationFromProvider : lastLocation;
}
Expand Down