Ive posted this numerous times on Stack Overflow and have attempted to seek help through Mapbox support and i am not getting any answers to my issue which is incredibly frustrating and holding us up on our project. Any insight on how we could resolve this would be greatly appreciated..
Upon reaching the destination, if i cancel Navigation or go back to my previous screen (In this case a Recyclerview list of jobs) My UI becomes unresponsive and my application crashes, once it crashes i also cannot end the navigation notification. I am only making use of activities, no fragments.
Dependencies:
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
//noinspection GradleCompatible
implementation "com.android.support:appcompat-v7:${supportLibVersion}"
implementation 'android.arch.lifecycle:extensions:1.1.1'
implementation 'com.android.support:design:27.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.google.code.gson:gson:2.8.2'
implementation 'com.android.volley:volley:1.1.0'
implementation 'com.android.support:recyclerview-v7:27.1.0'
implementation('com.mapbox.mapboxsdk:mapbox-android-sdk:5.5.0@aar') {
transitive = true
}
implementation 'com.mapbox.mapboxsdk:mapbox-android-navigation:0.11.1'
implementation('com.mapbox.mapboxsdk:mapbox-android-navigation-ui:0.11.1') {
transitive = true
}
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
}
My logs:
03-31 08:12:02.671 24930-24930/com.comp.deliveryapplication W/art: Attempt to remove non-JNI local reference, dumping thread
Attempt to remove non-JNI local reference, dumping thread
03-31 08:12:02.675 24930-24930/com.comp.deliveryapplication W/art: Attempt to remove non-JNI local reference, dumping thread
Attempt to remove non-JNI local reference, dumping thread
Attempt to remove non-JNI local reference, dumping thread
Attempt to remove non-JNI local reference, dumping thread
Attempt to remove non-JNI local reference, dumping thread
03-31 08:12:11.280 24930-24936/com.comp.deliveryapplication I/art: Thread[3,tid=24936,WaitingInMainSignalCatcherLoop,Thread*=0x7f7f04f400,peer=0x12c324c0,"Signal Catcher"]: reacting to signal 3
03-31 08:12:11.574 24930-24936/com.comp.deliveryapplication I/art: Wrote mini stack traces to '/data/anr/traces.txt.mini'
03-31 08:12:11.580 24930-24936/com.comp.deliveryapplication I/art: Wrote stack traces to '/data/anr/traces.txt'

I'm sure this is some how related to the Activity#onDestroy method some how. I have all of the life cycle methods in place for the NavigationView and i have a Navigation listener attached too. Yet the below method, which i added to my onDestroy method does not do anything. (I wrapped it in an if statement otherwise it as seen as null but it doesn't do anything regardless.) The mapView seems to get destroyed correctly but the navigationView does not from what i can tell.
if (navigationView != null) {
navigationView.onDestroy();
}
Is this perhaps related to #813 ?
Hey @jethro-2018 are you able to provide any more code snippets giving us insight into your implementation? Can you confirm you are using NavigationView in an Activity? Btw, this is not related to #813.
Sure thing:
` @Override
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
Bundle bundle = getIntent().getExtras();
String personJsonString = (String) bundle.get("CURRENT_JOB");
Properties data = new Gson().fromJson(personJsonString, Properties.class);
job_id = data.getProperty("job_id");
String destination_lat = data.getProperty("destination_lat");
String destination_lon = data.getProperty("destination_lon");
dlat = Double.parseDouble(destination_lat);
dlon = Double.parseDouble(destination_lon);
Log.e("job_id", job_id);
db = new DatabaseHelper(this);
gps = new GPS();
mapView = (MapView) findViewById(R.id.mapView);
mapView.onCreate(savedInstanceState);
// Add user location to the map
mapView.getMapAsync(new OnMapReadyCallback() {
@Override
public void onMapReady(final MapboxMap mapboxMap) {
map = mapboxMap;
enableLocationPlugin();
originCoord = new LatLng(originLocation.getLatitude(), originLocation.getLongitude());
originPosition = Point.fromLngLat(originCoord.getLongitude(), originCoord.getLatitude());
if (destinationMarker != null) {
mapboxMap.removeMarker(destinationMarker);
}
destinationCoord = new LatLng(dlon, dlat);
Log.e("DESTINATION-COORD", destinationCoord.toString());
destinationMarker = mapboxMap.addMarker(new MarkerOptions()
.position(destinationCoord)
);
destinationPosition = Point.fromLngLat(dlon, dlat);
getRoute(originPosition, destinationPosition);
};
});
button = findViewById(R.id.startButton);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
//setTheme(R.style.Theme_AppCompat_NoActionBar);
getSupportActionBar().hide();
setContentView(R.layout.activity_navigation);
navigationView = findViewById(R.id.navigationView);
navigationView.onCreate(savedInstanceState);
navigationView.getNavigationAsync(new OnNavigationReadyCallback() {
@Override
public void onNavigationReady() {
Point origin = originPosition;
Point destination = destinationPosition;
String awsPoolId = null;
boolean simulateRoute = true;
MapboxNavigationOptions navigationOptions = MapboxNavigationOptions.builder()
.unitType(NavigationUnitType.TYPE_METRIC)
.build();
NavigationViewOptions options = NavigationViewOptions.builder()
.navigationListener(MapActivity.this)
.navigationOptions(navigationOptions)
.directionsProfile(DirectionsCriteria.PROFILE_DRIVING)
.progressChangeListener(MapActivity.this)
.origin(origin)
.destination(destination)
.awsPoolId(awsPoolId)
.shouldSimulateRoute(simulateRoute)
.build();
navigationView.startNavigation(options);
}
});
}
});
}`
` @Override
@SuppressWarnings({"MissingPermission"})
public void onConnected() {
locationEngine.requestLocationUpdates();
}
@Override
public void onLocationChanged(Location location) {
if (location != null) {
originLocation = location;
setCameraPosition(location);
locationEngine.removeLocationEngineListener(this);
}
}
@Override
@SuppressWarnings({"MissingPermission"})
protected void onStart() {
super.onStart();
if (locationEngine != null) {
locationEngine.requestLocationUpdates();
locationEngine.setInterval(5000);
}
if (locationPlugin != null) {
locationPlugin.onStart();
}
mapView.onStart();
}
@Override
protected void onStop() {
super.onStop();
if (locationEngine != null) {
locationEngine.removeLocationUpdates();
}
if (locationPlugin != null) {
locationPlugin.onStop();
}
mapView.onStop();
}
@Override
protected void onDestroy() {
super.onDestroy();
mapView.onDestroy();
if (locationEngine != null) {
locationEngine.removeLocationUpdates();
locationEngine.deactivate();
}
if (navigationView != null) {
navigationView.onDestroy();
}
}
@Override
public void onLowMemory() {
super.onLowMemory();
mapView.onLowMemory();
navigationView.onLowMemory();
}
@Override
protected void onResume() {
super.onResume();
mapView.onResume();
}
@Override
protected void onPause() {
super.onPause();
mapView.onPause();
if (locationEngine != null) {
locationEngine.removeLocationEngineListener(this);
}
}
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
navigationView.onSaveInstanceState(outState);
mapView.onSaveInstanceState(outState);
}`
This is bit of the rest of my code as it currently stands, im messing around with a few different things. The onRestoreInstanceState for navigationView was causing a few issues but dont think its related to this.
I basically load the route as the activity is created, so that a driver can hit start trip as soon as it opens. Upon cancelling the Navigation Voice commands still run in the background until it stops responding, so i don't think its getting destroyed correctly.
I think the immediate issue is where you call NavigationView#onCreate. Your code waits for the button to be clicked to call this. You should bind the view and call onCreate outside of the click listener and then call get navigation async in the listener if you wish.
I think another issue may be running two mapviews in the same activity. NavigationView is essentially a MapView wrapped with navigation logic. If possible I'd suggest separating these into separate activities or fragments.
I will say, running multiple maps in one activity is possible, as demonstrated by this example in our test app https://github.com/mapbox/mapbox-gl-native/blob/master/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/DoubleMapActivity.java.
Great! Thanks, I will give this a try!
I successfully split the Map and Navigation into separate activities which solved my problem. Thanks for the assistance.
@jethro-2018 Great to hear, thanks for the update.