Android:A/libc:致命信号 11 (SIGSEGV),代码 1,tid 18372 中的故障地址 0x8
Android : A/libc: Fatal signal 11 (SIGSEGV), code 1, fault addr 0x8 in tid 18372
我正在使用 mapbox sdk 测试一个应用程序,而不是 mapbox 的位置引擎提供者,我创建了一个名为 "GoogleLocationEngine" 的 class,使用这个 link 来跟踪用户位置(Google API):
https://github.com/mapbox/mapbox-android-demo/issues/449
但是应用程序给我这个错误(通常是在后台):
A/libc: Fatal signal 11 (SIGSEGV), code 1, fault addr 0x8 in tid 18372
尽管当我使用 mapbox sdk 时:
LocationEngineProvider(context).obtainBestLocationEngineAvailable()
方法,还是报错,不知道怎么追踪,请问如何解决?我的设备是 SAMSUNG Galaxy Note 4 (SM-N900C)
这是我的 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);
}
}
更新:最近我意识到方法
locationEngine = new LocationEngineProvider(this).obtainBestLocationEngineAvailable();
无效!我在想这个方法对我有用但是当我评论它并再次测试我的应用程序时它没有显示我的位置,当我使用我的 GoogleLocationEngine class 它有效但仍然是同样的错误其余的。
亲爱的朋友们有什么想法吗?
问题已解决!
基于这一段:
在各自的 activity 方法中包含位置层 onStart() 和 onStop() 生命周期事件很重要。这可以防止发生内存泄漏并减少电池消耗。该插件支持新的 LifecycleObserver API,通过在您的 activity 中将插件添加为生命周期观察器,您将无需手动处理生命周期。
来源link:mapbox_locationLayer
和这个 mapboxDemo_LocationLayerPluginActivity.java (GitHub),我应该在我的函数中使用这些方法:
locationPlugin = new LocationLayerPlugin(mapView, mapboxMap, locationEngine);
locationPlugin.setLocationLayerEnabled(true);
locationPlugin.setCameraMode(CameraMode.TRACKING);
locationPlugin.setRenderMode(RenderMode.COMPASS);
Lifecycle lifecycle = getLifecycle();
lifecycle.addObserver(locationPlugin);
在我的 onStart() 中:
@Override
public void onStart() {
super.onStart();
mapView.onStart();
if(locationEngine != null){
locationEngine.requestLocationUpdates();
locationEngine.addLocationEngineListener(this);
}
}
也在我的 onStop() 中:
@Override
public void onStop() {
super.onStop();
mapView.onStop();
if(locationEngine != null){
locationEngine.removeLocationEngineListener(this);
locationEngine.removeLocationUpdates();
}
}
然后 致命信号错误现在消失了。
我必须说谢谢 mapbox 支持团队支持我并解决了这个问题。
我正在使用 mapbox sdk 测试一个应用程序,而不是 mapbox 的位置引擎提供者,我创建了一个名为 "GoogleLocationEngine" 的 class,使用这个 link 来跟踪用户位置(Google API): https://github.com/mapbox/mapbox-android-demo/issues/449
但是应用程序给我这个错误(通常是在后台):
A/libc: Fatal signal 11 (SIGSEGV), code 1, fault addr 0x8 in tid 18372
尽管当我使用 mapbox sdk 时:
LocationEngineProvider(context).obtainBestLocationEngineAvailable()
方法,还是报错,不知道怎么追踪,请问如何解决?我的设备是 SAMSUNG Galaxy Note 4 (SM-N900C) 这是我的 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);
}
}
更新:最近我意识到方法
locationEngine = new LocationEngineProvider(this).obtainBestLocationEngineAvailable();
无效!我在想这个方法对我有用但是当我评论它并再次测试我的应用程序时它没有显示我的位置,当我使用我的 GoogleLocationEngine class 它有效但仍然是同样的错误其余的。 亲爱的朋友们有什么想法吗?
问题已解决! 基于这一段:
在各自的 activity 方法中包含位置层 onStart() 和 onStop() 生命周期事件很重要。这可以防止发生内存泄漏并减少电池消耗。该插件支持新的 LifecycleObserver API,通过在您的 activity 中将插件添加为生命周期观察器,您将无需手动处理生命周期。
来源link:mapbox_locationLayer
和这个 mapboxDemo_LocationLayerPluginActivity.java (GitHub),我应该在我的函数中使用这些方法:
locationPlugin = new LocationLayerPlugin(mapView, mapboxMap, locationEngine);
locationPlugin.setLocationLayerEnabled(true);
locationPlugin.setCameraMode(CameraMode.TRACKING);
locationPlugin.setRenderMode(RenderMode.COMPASS);
Lifecycle lifecycle = getLifecycle();
lifecycle.addObserver(locationPlugin);
在我的 onStart() 中:
@Override
public void onStart() {
super.onStart();
mapView.onStart();
if(locationEngine != null){
locationEngine.requestLocationUpdates();
locationEngine.addLocationEngineListener(this);
}
}
也在我的 onStop() 中:
@Override
public void onStop() {
super.onStop();
mapView.onStop();
if(locationEngine != null){
locationEngine.removeLocationEngineListener(this);
locationEngine.removeLocationUpdates();
}
}
然后 致命信号错误现在消失了。
我必须说谢谢 mapbox 支持团队支持我并解决了这个问题。