Issue calling launch navigation activity
I am facing problem in your launch activity when calling code in oreo it is working fine but lower version than oreo report crash which is
11-19 20:07:13.489 27257-27257/com.makani E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.makani, PID: 27257
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.makani/com.mapbox.services.android.navigation.ui.v5.MapboxNavigationActivity}: android.view.InflateException: Binary XML file line #8: Binary XML file line #8: Error inflating class com.mapbox.services.android.navigation.ui.v5.NavigationView
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2659)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2724)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1473)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6123)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:757)
Caused by: android.view.InflateException: Binary XML file line #8: Binary XML file line #8: Error inflating class com.mapbox.services.android.navigation.ui.v5.NavigationView
Caused by: android.view.InflateException: Binary XML file line #8: Error inflating class com.mapbox.services.android.navigation.ui.v5.NavigationView
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:430)
at android.view.LayoutInflater.createView(LayoutInflater.java:645)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:787)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:727)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:858)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821)
at android.view.LayoutInflater.inflate(LayoutInflater.java:518)
at android.view.LayoutInflater.inflate(LayoutInflater.java:426)
at android.view.LayoutInflater.inflate(LayoutInflater.java:377)
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
at com.mapbox.services.android.navigation.ui.v5.MapboxNavigationActivity.onCreate(MapboxNavigationActivity.java:31)
at android.app.Activity.performCreate(Activity.java:6672)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1140)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2612)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2724)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1473)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6123)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:757)
Caused by: android.view.InflateException: Binary XML file line #25: Binary XML file line #25: Error inflating class com.mapbox.services.android.navigation.ui.v5.RecenterButton
Caused by: android.view.InflateException: Binary XML file line #25: Error inflating class com.mapbox.services.android.navigation.ui.v5.RecenterButton
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:430)
at android.view.LayoutInflater.createView(LayoutInflater.java:645)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:787)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:727)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:858)
11-19 20:07:13.490 27257-27257/com.makani E/AndroidRuntime: at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821)
at android.view.LayoutInflater.inflate(LayoutInflater.java:518)
at android.view.LayoutInflater.inflate(LayoutInflater.java:426)
at android.view.LayoutInflater.inflate(LayoutInflater.java:377)
at android.view.View.inflate(View.java:20866)
at com.mapbox.services.android.navigation.ui.v5.NavigationView.initializeView(NavigationView.java:485)
at com.mapbox.services.android.navigation.ui.v5.NavigationView.
here below is my code :
package com.makani.activities;
public class DrawPathOnMapActivity extends BaseActivity implements OnMapReadyCallback, MapboxMap.OnMapLongClickListener, LocationEngineListener, OnRouteSelectionChangeListener, View.OnClickListener {
//------------------------navigation variables------------
private static final int CAMERA_ANIMATION_DURATION = 1000;
private static final int DEFAULT_CAMERA_ZOOM = 16;
private static final int CHANGE_SETTING_REQUEST_CODE = 1;
private static final int INITIAL_ZOOM = 16;
private LocationEngine locationEngine;
private NavigationMapRoute mapRoute;
private MapboxMap mapboxMap;
private Marker currentMarker;
private Point currentLocation;
private Point destination;
private DirectionsRoute route;
private LocaleUtils localeUtils;
private boolean locationFound;
private MapView mapView;
// private Button launchRouteBtn;
private ProgressBar loading;
// private FrameLayout launchBtnFrame;
//------------------------navigation variables------------
private String TAG = DrawPathOnMapActivity.class.getSimpleName();
private Intent intent;
private String searchText;
private FrameLayout frameLaunchBtn;
private Button btnShare, btnStart;
private MyaddressModel myaddressModel;
private TextView tvPlaceName, tvAddress, tvDistance;
private double fromLat, fromLng, toLat, toLng;
private String comingFrom, setOn;
private boolean isFirstTime;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Mapbox.getInstance(this, getString(R.string.map_box_access_token));
setContentView(R.layout.activity_navigation_launcher);
whichToolbar(HEADER_WITH_BACK_N_SEARCH, false, true);
//ButterKnife.bind(this);
mapView = (MapView) findViewById(R.id.mapView);
//launchRouteBtn = (Button) findViewById(R.id.launch_route_btn);
loading = (ProgressBar) findViewById(R.id.loading);
// launchBtnFrame = (FrameLayout) findViewById(R.id.launch_btn_frame);
mapView.onCreate(savedInstanceState);
mapView.getMapAsync(this);
localeUtils = new LocaleUtils();
init();
getIntentValues();
initAction();
}
private void getIntentValues() {
intent = getIntent();
if (intent != null) {
if (intent.getSerializableExtra("myAddressModel") != null) {
// set name of header
myaddressModel = (MyaddressModel) intent.getSerializableExtra("myAddressModel");
searchText = myaddressModel.getFullAddress();
}
if (intent.getStringExtra("text") != null) {
// set name of header
searchText = intent.getStringExtra("text");
}
if (intent.getStringExtra("comingFrom") != null) {// coming from which activity
// set name of header
comingFrom = intent.getStringExtra("comingFrom");
}
if (intent.getStringExtra("setOn") != null) {//if source thn set on source if destination set it on destination
// set name of header
setOn = intent.getStringExtra("setOn");
if (setOn.length() == 0) {
isFirstTime = true;
}
} else {
isFirstTime = true;
}
}
}
private void init() {
localeUtils = new LocaleUtils();
btnShare = (Button) findViewById(R.id.btnShare);
btnStart = (Button) findViewById(R.id.btnStart);
tvPlaceName = (TextView) findViewById(R.id.tvPlaceName);
tvAddress = (TextView) findViewById(R.id.tvAddress);
tvDistance = (TextView) findViewById(R.id.tvDistance);
btnStart.setVisibility(View.GONE);
btnShare.setVisibility(View.GONE);
btnShare.setOnClickListener(this);
btnStart.setOnClickListener(this);
//frameLaunchBtn = findViewById(R.id.launch_btn_frame);
}
private void initAction() {
if (myaddressModel != null) {
if (myaddressModel.getPlaceName() != null) {
tvPlaceName.setText(myaddressModel.getPlaceName());
}
if (myaddressModel.getFullAddress() != null) {
tvAddress.setText(myaddressModel.getFullAddress());
}
if (setOn != null) {
if (setOn.equals(getResources().getString(R.string.source))) {
app.setSourceModel(myaddressModel);
if (myaddressModel.getLat() != null && myaddressModel.getLat().length() > 0) {
fromLat = Double.parseDouble(myaddressModel.getLat());
app.setFromLat(fromLat);
}
if (myaddressModel.getLng() != null && myaddressModel.getLng().length() > 0) {
fromLng = Double.parseDouble(myaddressModel.getLng());
app.setFromLng(fromLng);
}
} else {
app.setDestinationModel(myaddressModel);
if (myaddressModel.getLat() != null && myaddressModel.getLat().length() > 0) {
toLat = Double.parseDouble(myaddressModel.getLat());
app.setToLat(toLat);
}
if (myaddressModel.getLng() != null && myaddressModel.getLng().length() > 0) {
toLng = Double.parseDouble(myaddressModel.getLng());
app.setToLng(toLng);
}
}
}
}
imForcurrentLocation.setImageDrawable(CommonMethods.getDrawableWrapper(this, R.drawable.disable_source));
//imForcurrentLocation.setVisibility(View.INVISIBLE);
}
@Override
protected void onStart() {
super.onStart();
mapView.onStart();
}
@SuppressWarnings({"MissingPermission"})
@Override
public void onResume() {
super.onResume();
mapView.onResume();
setCurrentAct(DRAW_PATH_ON_MAP_ACT);
setHomeHeaderSearchFrom2ToText(getResources().getString(R.string.your_location), searchText);
//setHomeHeaderSearchText(searchText);
if (currentLocation != null) {
app.setFromLat(currentLocation.latitude());
app.setFromLng(currentLocation.longitude());
}
mapView.onResume();
if (locationEngine != null) {
locationEngine.addLocationEngineListener(this);
if (!locationEngine.isConnected()) {
locationEngine.activate();
}
}
if (currentLocation != null)
animateCamera(new LatLng(currentLocation.latitude(), currentLocation.longitude()));
if (setOn != null) {
if (setOn.equals(getResources().getString(R.string.source))) {
imForcurrentLocation.setImageDrawable(CommonMethods.getDrawableWrapper(this, R.drawable.enable_source));
}
}
if (locationEngine != null) {
locationEngine.addLocationEngineListener(this);
if (!locationEngine.isConnected()) {
locationEngine.activate();
}
}
}
@Override
public void onPause() {
super.onPause();
mapView.onPause();
if (locationEngine != null) {
locationEngine.removeLocationEngineListener(this);
}
}
@Override
public void onLowMemory() {
super.onLowMemory();
mapView.onLowMemory();
}
@Override
protected void onStop() {
super.onStop();
mapView.onStop();
}
@Override
protected void onDestroy() {
super.onDestroy();
mapView.onDestroy();
if (locationEngine != null) {
locationEngine.removeLocationUpdates();
locationEngine.deactivate();
}
}
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
mapView.onSaveInstanceState(outState);
}
// @OnClick(R.id.launch_route_btn)
public void onRouteLaunchClick() {
launchNavigationWithRoute();
}
@Override
public void onMapReady(MapboxMap mapboxMap) {
mapboxMap.setStyleUrl(Style.LIGHT);
this.mapboxMap = mapboxMap;
this.mapboxMap.addOnMapLongClickListener(this);
initLocationEngine();
initializeLocationComponent();
initMapRoute();
}
@Override
public void onMapLongClick(@NonNull LatLng point) {
/* destination = Point.fromLngLat(point.getLongitude(), point.getLatitude());
btnStart.setEnabled(false);
loading.setVisibility(View.VISIBLE);
setCurrentMarkerPosition(point);
if (currentLocation != null) {
fetchRoute();
}*/
}
@SuppressWarnings({"MissingPermission"})
@Override
public void onConnected() {
locationEngine.requestLocationUpdates();
}
@Override
public void onLocationChanged(Location location) {
currentLocation = Point.fromLngLat(location.getLongitude(), location.getLatitude());
onLocationFound(location);
btnStart.setVisibility(View.VISIBLE);
btnShare.setVisibility(View.VISIBLE);
if (currentLocation != null) {
fetchRoute();
}
}
@Override
public void onNewPrimaryRouteSelected(DirectionsRoute directionsRoute) {
route = directionsRoute;
}
@SuppressWarnings({"MissingPermission"})
private void initLocationEngine() {
locationEngine = new LocationEngineProvider(this).obtainBestLocationEngineAvailable();
locationEngine.setPriority(HIGH_ACCURACY);
locationEngine.setInterval(0);
locationEngine.setFastestInterval(1000);
locationEngine.addLocationEngineListener(this);
locationEngine.activate();
if (locationEngine.getLastLocation() != null) {
Location lastLocation = locationEngine.getLastLocation();
onLocationChanged(lastLocation);
currentLocation = Point.fromLngLat(lastLocation.getLongitude(), lastLocation.getLatitude());
}
}
@SuppressWarnings({"MissingPermission"})
private void initializeLocationComponent() {
LocationComponent locationComponent = mapboxMap.getLocationComponent();
locationComponent.activateLocationComponent(this, locationEngine);
locationComponent.setLocationComponentEnabled(true);
locationComponent.setRenderMode(RenderMode.COMPASS);
}
@Override
protected void onClickYourLocation() {
super.onClickYourLocation();
imForcurrentLocation.setImageDrawable(CommonMethods.getDrawableWrapper(this, R.drawable.disable_source));
// imForcurrentLocation.setVisibility(View.INVISIBLE);
setHomeHeaderSearchFrom2ToText(getResources().getString(R.string.your_location), searchText);
if (currentLocation != null) {
app.setFromLat(currentLocation.latitude());
app.setFromLng(currentLocation.longitude());
}
}
@Override
protected void onClickedSource() {
super.onClickedSource();
intent = new Intent(this, HomeSearchActivity.class);
intent.putExtra("comingFromActivity", comingFrom);
intent.putExtra("setOn", getResources().getString(R.string.source));
intent.putExtra("comingFrom", comingFrom);
startActivity(intent);
}
@Override
protected void onClickedDestination() {
super.onClickedDestination();
intent = new Intent(this, HomeSearchActivity.class);
intent.putExtra("comingFromActivity", comingFrom);
intent.putExtra("setOn", getResources().getString(R.string.destination));
intent.putExtra("comingFrom", comingFrom);
startActivity(intent);
}
private void initMapRoute() {
mapRoute = new NavigationMapRoute(mapView, mapboxMap);
mapRoute.setOnRouteSelectionChangeListener(this);
if (isFirstTime) {
if (myaddressModel != null && myaddressModel.getLat() != null && myaddressModel.getLat().length() > 0
&& myaddressModel.getLng() != null && myaddressModel.getLng().length() > 0) {
app.setToLat(Double.parseDouble(myaddressModel.getLat()));
app.setToLng(Double.parseDouble(myaddressModel.getLng()));
app.setDestinationModel(myaddressModel);
LatLng latLng = new LatLng();
latLng.setLatitude(Double.parseDouble(myaddressModel.getLat()));
latLng.setLongitude(Double.parseDouble(myaddressModel.getLng()));
setDestinationMarkerPosition(latLng);
destination = Point.fromLngLat(latLng.getLongitude(), latLng.getLatitude());
}
} else {
LatLng latLng = new LatLng();
latLng.setLatitude(app.getToLat());
latLng.setLongitude(app.getToLng());
setDestinationMarkerPosition(latLng);
destination = Point.fromLngLat(app.getToLat(), app.getToLng());
}
if (setOn != null) {
if (setOn.equals(getResources().getString(R.string.source))) {
app.setSourceModel(myaddressModel);
if (myaddressModel.getLat() != null && myaddressModel.getLat().length() > 0) {
fromLat = Double.parseDouble(myaddressModel.getLat());
app.setFromLat(fromLat);
}
if (myaddressModel.getLng() != null && myaddressModel.getLng().length() > 0) {
fromLng = Double.parseDouble(myaddressModel.getLng());
app.setFromLng(fromLng);
}
imForcurrentLocation.setImageDrawable(CommonMethods.getDrawableWrapper(this, R.drawable.enable_source));
//imForcurrentLocation.setVisibility(View.VISIBLE);
setHomeHeaderSearchFrom2ToText(myaddressModel.getFullAddress(), app.getDestinationModel().getFullAddress());
setSorceMarker(new LatLng(fromLat, fromLng));
// source = Point.fromLngLat(app.getFromLat(), app.getFromLng());
} else {
app.setDestinationModel(myaddressModel);
if (myaddressModel.getLat() != null && myaddressModel.getLat().length() > 0) {
toLat = Double.parseDouble(myaddressModel.getLat());
app.setToLat(toLat);
}
if (myaddressModel.getLng() != null && myaddressModel.getLng().length() > 0) {
toLng = Double.parseDouble(myaddressModel.getLng());
app.setToLng(toLng);
}
setHomeHeaderSearchFrom2ToText(app.getSourceModel().getFullAddress(), myaddressModel.getFullAddress());
LatLng latLng = new LatLng();
latLng.setLatitude(app.getToLat());
latLng.setLongitude(app.getToLng());
setDestinationMarkerPosition(latLng);
//destination = Point.fromLngLat(app.getToLat(), app.getToLng());
}
}
}
private void setDestinationMarkerPosition(LatLng position) {
if (mapboxMap != null) {
IconFactory iconFactory = IconFactory.getInstance(this);
Icon icon = iconFactory.fromResource(R.drawable.marker);
MarkerOptions markerOptions = new MarkerOptions()
.position(position)
.setIcon(icon)
.setSnippet("this is the destination location")
.title("Destination");
mapboxMap.addMarker(markerOptions);
}
}
private void setSorceMarker(LatLng position) {
if (mapboxMap != null) {
IconFactory iconFactory = IconFactory.getInstance(this);
Icon icon = iconFactory.fromResource(R.drawable.source1);
MarkerOptions markerOptions = new MarkerOptions()
.position(position)
.setIcon(icon)
.setSnippet("this is the your location")
.title("Source");
mapboxMap.addMarker(markerOptions);
}
}
private void setUserLocation(LatLng position) {
if (mapboxMap != null) {
IconFactory iconFactory = IconFactory.getInstance(this);
Icon icon = iconFactory.fromResource(R.drawable.source1);
MarkerOptions markerOptions = new MarkerOptions()
.position(position)
.setIcon(icon)
.setSnippet("this is the your location")
.title("You");
mapboxMap.addMarker(markerOptions);
}
}
private void fetchRoute() {
if (currentLocation != null && destination != null) {
NavigationRoute.Builder builder = NavigationRoute.builder(this)
.accessToken(Mapbox.getAccessToken())
.origin(currentLocation)
.destination(destination)
.alternatives(true);
setFieldsFromSharedPreferences(builder);
builder.build()
.getRoute(new SimplifiedCallback() {
@Override
public void onResponse(Call<DirectionsResponse> call, Response<DirectionsResponse> response) {
if (validRouteResponse(response)) {
hideLoading();
route = response.body().routes().get(0);
if (route.distance() > 25d) {
btnStart.setEnabled(true);
mapRoute.addRoutes(response.body().routes());
boundCameraToRoute();
} else {
Snackbar.make(mapView, R.string.error_select_longer_route, Snackbar.LENGTH_SHORT).show();
}
}
}
});
loading.setVisibility(View.VISIBLE);
}
}
private void setFieldsFromSharedPreferences(NavigationRoute.Builder builder) {
builder
.language(getLanguageFromSharedPreferences())
.voiceUnits(getUnitTypeFromSharedPreferences());
}
private String getUnitTypeFromSharedPreferences() {
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
String defaultUnitType = getString(R.string.default_unit_type);
String unitType = sharedPreferences.getString(getString(R.string.unit_type_key), defaultUnitType);
if (unitType.equals(defaultUnitType)) {
unitType = localeUtils.getUnitTypeForDeviceLocale(this);
}
return unitType;
}
private Locale getLanguageFromSharedPreferences() {
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
String defaultLanguage = getString(R.string.default_locale);
String language = sharedPreferences.getString(getString(R.string.language_key), defaultLanguage);
if (language.equals(defaultLanguage)) {
return localeUtils.inferDeviceLocale(this);
} else {
return new Locale(language);
}
}
private boolean getShouldSimulateRouteFromSharedPreferences() {
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
return sharedPreferences.getBoolean(getString(R.string.simulate_route_key), false);
}
private String getRouteProfileFromSharedPreferences() {
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
return sharedPreferences.getString(
getString(R.string.route_profile_key), DirectionsCriteria.PROFILE_DRIVING_TRAFFIC
);
}
private void launchNavigationWithRoute() {
if (route == null) {
Snackbar.make(mapView, R.string.error_route_not_available, Snackbar.LENGTH_SHORT).show();
return;
}
NavigationLauncherOptions.Builder optionsBuilder = NavigationLauncherOptions.builder()
.shouldSimulateRoute(getShouldSimulateRouteFromSharedPreferences())
.directionsProfile(getRouteProfileFromSharedPreferences());
CameraPosition initialPosition = new CameraPosition.Builder()
.target(new LatLng(currentLocation.latitude(), currentLocation.longitude()))
.zoom(INITIAL_ZOOM)
.build();
optionsBuilder.initialMapCameraPosition(initialPosition);
optionsBuilder.directionsRoute(route);
NavigationLauncher.startNavigation(this, optionsBuilder.build());
}
private boolean validRouteResponse(Response<DirectionsResponse> response) {
return response.body() != null && !response.body().routes().isEmpty();
}
private void hideLoading() {
if (loading.getVisibility() == View.VISIBLE) {
loading.setVisibility(View.INVISIBLE);
}
}
private void onLocationFound(Location location) {
if (!locationFound) {
animateCamera(new LatLng(location.getLatitude(), location.getLongitude()));
Snackbar.make(mapView, R.string.explanation_long_press_waypoint, Snackbar.LENGTH_LONG).show();
// setSorceMarker(new LatLng(location.getLatitude(), location.getLongitude()));
setUserLocation(new LatLng(location.getLatitude(), location.getLongitude()));
locationFound = true;
hideLoading();
}
}
public void boundCameraToRoute() {
if (route != null) {
List<Point> routeCoords = LineString.fromPolyline(route.geometry(),
Constants.PRECISION_6).coordinates();
List<LatLng> bboxPoints = new ArrayList<>();
for (Point point : routeCoords) {
bboxPoints.add(new LatLng(point.latitude(), point.longitude()));
}
if (bboxPoints.size() > 1) {
try {
LatLngBounds bounds = new LatLngBounds.Builder().includes(bboxPoints).build();
// left, top, right, bottom
// int topPadding = launchBtnFrame.getHeight() * 2;
animateCameraBbox(bounds, CAMERA_ANIMATION_DURATION, new int[]{50, 0, 50, 100});
} catch (InvalidLatLngBoundsException exception) {
Toast.makeText(this, R.string.error_valid_route_not_found, Toast.LENGTH_SHORT).show();
}
}
}
}
private void animateCameraBbox(LatLngBounds bounds, int animationTime, int[] padding) {
CameraPosition position = mapboxMap.getCameraForLatLngBounds(bounds, padding);
mapboxMap.animateCamera(CameraUpdateFactory.newCameraPosition(position), animationTime);
}
private void animateCamera(LatLng point) {
mapboxMap.animateCamera(CameraUpdateFactory.newLatLngZoom(point, DEFAULT_CAMERA_ZOOM), CAMERA_ANIMATION_DURATION);
}
private void setCurrentMarkerPosition(LatLng position) {
if (position != null) {
if (currentMarker == null) {
MarkerViewOptions markerViewOptions = new MarkerViewOptions()
.position(position);
currentMarker = mapboxMap.addMarker(markerViewOptions);
} else {
currentMarker.setPosition(position);
}
}
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == android.R.id.home) {
if (comingFrom != null && comingFrom.equals(getResources().getString(R.string.search))) {
// if(setOn!=null && setOn.length()>0) {
intent = new Intent(this, HomeSearchActivity.class);
intent.putExtra("comingFromActivity", comingFrom);
//intent.putExtra()
// }else{
//}
} else if (comingFrom != null && comingFrom.equals(getResources().getString(R.string.category))) {
intent = new Intent(this, CategoryMapActivity.class);
intent.putExtra("addModel", myaddressModel);
intent.putExtra("id", myaddressModel.getCatId());
intent.putExtra("category", myaddressModel.getCatName());
} else if (comingFrom != null && comingFrom.equals(getResources().getString(R.string.popular_places_near_you))) {
intent = new Intent(this, HomeActivity.class);
} else {
onBackPressed();
}
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
finish();
//onBackPressed();
return true;
}
return super.onOptionsItemSelected(item);
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.btnShare:
break;
case R.id.btnStart:
if (currentLocation != null) {
onRouteLaunchClick();
/* launchNavigationWithRoute();
mapRoute.setOnRouteSelectionChangeListener(this);*/
}
break;
}
}
}
@shrutiWV 👋 thanks for brining this to us, which version of the SDK are you using?
here i am using sdk
implementation 'com.mapbox.mapboxsdk:mapbox-android-navigation:0.23.0' implementation 'com.mapbox.mapboxsdk:mapbox-android-navigation-ui:0.23.0'
i got following errors in layout activity_navigation.xml on preview section of android studio. Hope this will help you find the problem.
1)Missing styles. Is the correct theme chosen for this layout? Use the Theme combo box above the layout to choose a different layout, or fix the theme style references.
2)Failed to find the style corresponding to the id -1 Tip: Try to refresh the layout.
3)Failed to parse file ?attr/navigationViewPrimary (Details) Tip: Try to refresh the layout.
4)Failed to find style 'coordinatorLayoutStyle' in current theme Tip: Try to refresh the layout
5)The following classes could not be instantiated:
- com.mapbox.services.android.navigation.ui.v5.NavigationView (Open Class, Show Exception, Clear Cache)
Tip: Use View.isInEditMode() in your custom views to skip code or show sample data when shown in the IDE. If this is an unexpected error you can also try to build the project, then manually refresh the layout. Exception Details java.lang.ClassCastException: Please ensure that the provided Context is a valid FragmentActivity at com.mapbox.services.android.navigation.ui.v5.NavigationView.initializeNavigationViewModel(NavigationView.java:511) at com.mapbox.services.android.navigation.ui.v5.NavigationView.initializeView(NavigationView.java:489) at com.mapbox.services.android.navigation.ui.v5.NavigationView.
i found the issue actually its my android studio issue my gradle file is not support textAllCaps property inside xml file but programetically it supports so i remove it and the crash is resolved but new issue is arrived
the navigation screen is launched without crash but no action is performed on this activity not even onClick action is performed also map is not loaded.
i don't get the problem why this is happen also no error prints on logs please help me out ASAP.
here is the screen shot
my Log says- com.xyz E/Mbgl-HttpRequest: [HTTP] Unable to parse resourceUrl ?2130968985
@shrutiWV are you setting a custom theme for the NavigationView? It looks like the map isn't able to parse the URL resource for the map style.
@shrutiWV I'm going to go ahead and close here. Please follow up if you still feel you've found a bug with the SDK. I encourage you to double check the URL resource being provide via your style.xml as this looks like a possible issue here.