Skip to content
Advertisement

Android java.lang.AbstractMethodError on requestLocationUpdates

i get this error java.lang.AbstractMethodError: abstract method "void android.location.LocationListener.onProviderDisabled(java.lang.String)

when i call locationManager.requestLocationUpdates(). I saw another post where the answer was to override some methods i.e.

JavaScript

But the thing is i cannot override them anywhere in my project.

I have simplified the code in order to help the readers and instead of two classes i have one

MainActivity:

JavaScript

The exception is thrown at locationManager.requestLocationUpdates and has something to do with library version.

And lastly this is my build.gradle(app)

JavaScript

Advertisement

Answer

Found the solution. After android 10(Q) you won’t need lot’s of the the unimplemented methods of LocationListener like onProviderDisabled.

But most of our apps have high “margin” of backwards compatibility supporting much older Android versions so you will need to override these ones.

So in order to implement these we can do this by two approaches:

First solution is creating a new LocationListener as a variable and implement these methods straight away

JavaScript

A Second approach is to implement LocationListener in your class and implement these methods

JavaScript

And now you must implement the methods

JavaScript

And your LocationListener is your own class

JavaScript

Last thing to take in mind is that even tho public void onStatusChanged(String provider, int status, Bundle extras) {} is deprecated you SHOULD implement because as i said Android phones that use Android 9 or lower are going to trigger that method when taking location updates with locationManager.requestLocationUpdates

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement