Reputation: 97
I'm testing an app with mapbox sdk and instead of mapbox's location Engine provider i've created a class named "GoogleLocationEngine" using this link in order to track user location (Google API): https://github.com/mapbox/mapbox-android-demo/issues/449
but the app gives me this error (usually when it's in the background) :
A/libc: Fatal signal 11 (SIGSEGV), code 1, fault addr 0x8 in tid 18372
although when i use the mapbox sdk :
LocationEngineProvider(context).obtainBestLocationEngineAvailable()
method, the error still shows up and i don't know how to track it, so how can i solve this? My device is SAMSUNG Galaxy Note 4 (SM-N900C) here is my MainActivity.java :
import android.location.Location;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.widget.Toast;
import com.google.android.gms.location.LocationCallback;
import com.google.android.gms.location.LocationResult;
import com.mapbox.android.core.location.LocationEngine;
import com.mapbox.android.core.location.LocationEngineListener;
import com.mapbox.android.core.location.LocationEnginePriority;
import com.mapbox.android.core.permissions.PermissionsListener;
import com.mapbox.android.core.permissions.PermissionsManager;
import com.mapbox.mapboxsdk.Mapbox;
import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.maps.MapView;
import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.plugins.locationlayer.LocationLayerPlugin;
import com.mapbox.mapboxsdk.plugins.locationlayer.modes.CameraMode;
import com.mapbox.mapboxsdk.plugins.locationlayer.modes.RenderMode;
import java.util.List;
public class MainActivity extends AppCompatActivity implements
LocationEngineListener,
PermissionsListener{
private MapView mapView;
private MapboxMap map;
private PermissionsManager permissionsManager;
private LocationEngine locationEngine;
private Location originLocation;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Mapbox.getInstance(this, getString(R.string.access_token));
setContentView(R.layout.activity_main);
mapView = findViewById(R.id.mapView);
mapView.onCreate(savedInstanceState);
mapView.getMapAsync(mapboxMap -> {
map = mapboxMap;
enableLocation();
});
}
private void enableLocation(){
if(PermissionsManager.areLocationPermissionsGranted(this)){
initializeLocationEngine();
initializeLocationLayer();
} else {
permissionsManager = new PermissionsManager(this);
permissionsManager.requestLocationPermissions(this);
}
}
@SuppressWarnings("MissingPermission")
private void initializeLocationEngine(){
locationEngine = GoogleLocationEngine.getLocationEngine(this);
locationEngine.setPriority(LocationEnginePriority.HIGH_ACCURACY);
locationEngine.activate();
Location lastLocation = locationEngine.getLastLocation();
if(lastLocation != null){
originLocation = lastLocation;
setCameraPosition(lastLocation);
} else {
locationEngine.addLocationEngineListener(this);
}
}
@SuppressWarnings("MissingPermission")
private void initializeLocationLayer(){
LocationLayerPlugin locationLayerPlugin = new LocationLayerPlugin(mapView, map, locationEngine);
locationLayerPlugin.setLocationLayerEnabled(true);
locationLayerPlugin.setCameraMode(CameraMode.TRACKING);
locationLayerPlugin.setRenderMode(RenderMode.NORMAL);
}
private void setCameraPosition(Location location){
map.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(location.getLatitude() , location.getLongitude()) , 13.0));
}
@SuppressWarnings("MissingPermission")
@Override
public void onConnected() {
Log.d("onConnected" , "is Connected");
locationEngine.requestLocationUpdates();
}
@Override
public void onLocationChanged(Location location) {
if(location != null){
originLocation = location;
setCameraPosition(location);
} else
Toast.makeText(this, "Location is null", Toast.LENGTH_SHORT).show();
}
@Override
public void onExplanationNeeded(List<String> permissionsToExplain) {
//present a toast or a dialog
Toast.makeText(this, permissionsToExplain.get(0) , Toast.LENGTH_SHORT).show();
}
@Override
public void onPermissionResult(boolean granted) {
if(granted){
enableLocation();
}
}
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
permissionsManager.onRequestPermissionsResult(requestCode , permissions , grantResults);
}
@Override
public void onStart() {
super.onStart();
mapView.onStart();
}
@Override
public void onResume() {
super.onResume();
mapView.onResume();
}
@Override
public void onPause() {
super.onPause();
mapView.onPause();
}
@Override
public void onStop() {
super.onStop();
mapView.onStop();
}
@Override
public void onLowMemory() {
super.onLowMemory();
mapView.onLowMemory();
}
@Override
protected void onDestroy() {
super.onDestroy();
mapView.onDestroy();
}
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
mapView.onSaveInstanceState(outState);
}
}
UPDATE : Recently I've realized that the method
locationEngine = new LocationEngineProvider(this).obtainBestLocationEngineAvailable();
is not working! i was thinking that this method works for me but when i commented it and test my app again it didn't show my location, when i used my GoogleLocationEngine class it worked but still the same error is remaining. any idea dear friends?
Upvotes: 2
Views: 3639
Reputation: 97
the Issue's been solved! based on this paragraph :
It's important to include the location layer onStart() and onStop() lifecycle events in their respective activity methods. This prevents memory leaks from occurring and reduces battery consumption. The plugin has support for the new LifecycleObserver APIs, by adding the plugin as a lifecycle observer in your activity, you won't need to handle the lifecycles manually.
source link : mapbox_locationLayer
and this mapboxDemo_LocationLayerPluginActivity.java (GitHub), i should use these methods in my functions :
locationPlugin = new LocationLayerPlugin(mapView, mapboxMap, locationEngine);
locationPlugin.setLocationLayerEnabled(true);
locationPlugin.setCameraMode(CameraMode.TRACKING);
locationPlugin.setRenderMode(RenderMode.COMPASS);
Lifecycle lifecycle = getLifecycle();
lifecycle.addObserver(locationPlugin);
and in my onStart() :
@Override
public void onStart() {
super.onStart();
mapView.onStart();
if(locationEngine != null){
locationEngine.requestLocationUpdates();
locationEngine.addLocationEngineListener(this);
}
}
also in my onStop() :
@Override
public void onStop() {
super.onStop();
mapView.onStop();
if(locationEngine != null){
locationEngine.removeLocationEngineListener(this);
locationEngine.removeLocationUpdates();
}
}
and then the Fatal Signal Error is gone now.
I must say Thank you mapbox support Team for supporting me and solving this problem.
Upvotes: 3