Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing LocationManager.addGpsStatusListener with Android from JNI causes nothing to happen
    primarykey
    data
    text
    <p>I have a strange issue I'm having trouble understanding. I can use LocationManager and its requestLocationUpdates method to receive location updates. I have a simple class that implements LocationListener:</p> <pre><code> public class PrisLocationListener implements LocationListener { @Override public void onLocationChanged(Location location) { ... } @Override public void onStatusChanged(String provider, int status, Bundle extras) { ... } @Override public void onProviderEnabled(String provider) { ... } @Override public void onProviderDisabled(String provider) { ... } } </code></pre> <p>I use this class in my Activity by creating a separate thread for it:</p> <pre><code> // create seperate thread for location callbacks mPrisLocationListener = new PrisLocationListener(); mLocationHandlerThread = new HandlerThread("LocationHandlerThread"); mLocationHandlerThread.start(); </code></pre> <p>And then passing it to the LocationManager:</p> <pre><code> mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,0,0, mPrisLocationListener, mLocationHandlerThread.getLooper()); </code></pre> <p>The above works as expected and I can get the device's GPS location. </p> <p>I also want GPS Status information (satellite count, TTFF, etc) so I create another class that implements GpsStatus.Listener:</p> <pre><code> public class PrisGpsListener implements GpsStatus.Listener { @Override public void onGpsStatusChanged(int event) { ... } } </code></pre> <p>The trouble starts when I try to use the above class. At the same point in my Activity as for the LocationListener, I initialize an instance of the GpsListener and pass it to the LocationManager:</p> <pre><code> mPrisGpsListener = new PrisGpsListener(); if(!mLocationManager.addGpsStatusListener(mPrisGpsListener)) { Log.i("Activity: ","addGpsStatusListener failed"); // doesn't fail, addGpsStatusListener returns true } // LocationManager.requestLocationUpdates called after addGpsStatusListener </code></pre> <p>The problem is that if I add the 'addGpsStatusListener' call to my code, nothing happens with respect to location services. That is, not only do I not get any status updates from the GpsListener, but I don't get the normal location updates anymore either. Logcat doesn't show me anything at all when the relevant functions are called.</p> <p>It's strange that requestLocationUpdates by itself works fine, but calling addGpsStatusListener to the mix makes everything fail. I have no idea what to try here so any suggestions would be appreciated.</p> <hr> <p>EDIT:</p> <p>As Rafael pointed out, all this works fine when called from Activity::onCreate()... however, (and this should have been one of the first things I mentioned), there's a separate function in my main Activity that calls the above LocationManager methods and instantiates the relevant objects. <em>I invoke the method from native code through JNI</em></p> <p>The method is called using JNI some time after the Activity is created.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload