При редиректе из одной активити в другую отображается только карта, всего остального - нет
возникла проблема, у меня 2 активити с ямапам, при редиректе из одной в другую отображается только карта, всего остального - нет, при этом на первой активити все есть и работает, ниже приведу в пример 2 класса, которые использую. Заранее спасибо за помощь.
1
public class HomeActivity extends AppCompatActivity implements UserLocationObjectListener {
private AppBarConfiguration mAppBarConfiguration;
private ActivityMainBinding binding;
private static final String GEOCODER_API_KEY = "123";
private MapView mapView;
private static final int REQUEST_CODE_PERMISSION_INTERNET = 1;
private static final int PERMISSIONS_REQUEST_FINE_LOCATION = 1;
private UserLocationLayer userLocationLayer;
public Point ROUTE_START_LOCATION = null;
public Point ROUTE_END_LOCATION = null;
private MapObjectCollection mapObjects;
private DBClass DBClass = new DBClass();
private DBHelper dbHelper;
@Override
protected void onCreate(Bundle savedInstanceState) {
peremissionInternet();
requestLocationPermission();
super.onCreate(savedInstanceState);
if(!init) {
MapKitFactory.initialize(this);
init = true;
}
setContentView(R.layout.fragment_home);
binding = ActivityMainBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
mapView = findViewById(R.id.mapview);
mapView.getMap().setRotateGesturesEnabled(false);
mapView.getMap().move(new CameraPosition(new Point(0, 0), 14, 0, 0));
//Стили!!!
mapView.getMap().setMapStyle(style);
mapView.getMap().setMapStyle(styleLand);
MapKit mapKit = MapKitFactory.getInstance();
userLocationLayer = mapKit.createUserLocationLayer(mapView.getMapWindow());
userLocationLayer.setVisible(true);
userLocationLayer.setHeadingEnabled(true);
userLocationLayer.setObjectListener(this);
mapView.getMap().addInputListener(il);
mapObjects = mapView.getMap().getMapObjects().addCollection();
setSupportActionBar(binding.appBarMain.toolbar);
binding.appBarMain.fab.setOnClickListener(view -> Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show());
DrawerLayout drawer = binding.drawerLayout;
NavigationView navigationView = binding.navView;
mAppBarConfiguration = new AppBarConfiguration.Builder(
R.id.nav_home,R.id.nav_profile, R.id.nav_gallery, R.id.nav_slideshow, R.id.nav_info, R.id.nav_exit)
.setOpenableLayout(drawer)
.build();
NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment_content_main);
NavigationUI.setupActionBarWithNavController(this, navController, mAppBarConfiguration);
NavigationUI.setupWithNavController(navigationView, navController);
dbHelper = new DBHelper(this);
start = findViewById(R.id.start_bottom);
finish = findViewById(R.id.finish_bottom);
Button go = findViewById(R.id.buttonGoSheet);
go.setOnClickListener(view -> {
DBClass = new DBClass();
String hash = DBClass.getHash(HomeActivity.this);
String url = URL_API_USERS +"/"+hash;
String arg = "active=2";
new Thread(() -> {
if(HttpApi.put(url, arg) == HttpURLConnection.HTTP_OK) {
showToast("Ожидайте пока приймут ваш заказ");
RedirectToDriver();
//вывод всплыувуающего окна
}
}).start();
});
TextView eco = findViewById(R.id.eco);
TextView middle = findViewById(R.id.middle);
TextView business = findViewById(R.id.business);
//добавить в бд класс заказа
eco.setOnClickListener(view -> Class = 1);
middle.setOnClickListener(view -> Class = 2);
business.setOnClickListener(view -> Class = 3);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onSupportNavigateUp() {
NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment_content_main);
return NavigationUI.navigateUp(navController, mAppBarConfiguration)
|| super.onSupportNavigateUp();
}
@Override
protected void onStop() {
mapView.onStop();
MapKitFactory.getInstance().onStop();
super.onStop();
}
@Override
protected void onStart() {
super.onStart();
MapKitFactory.getInstance().onStart();
mapView.onStart();
}
private void requestLocationPermission() {
if (ContextCompat.checkSelfPermission(this,
"android.permission.ACCESS_FINE_LOCATION")
!= PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this,
new String[]{"android.permission.ACCESS_FINE_LOCATION"},
PERMISSIONS_REQUEST_FINE_LOCATION);
}
}
private void peremissionInternet(){
if (ContextCompat.checkSelfPermission(this,
"android.permission.INTERNET")
!= PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this,
new String[]{"android.permission.INTERNET"},
REQUEST_CODE_PERMISSION_INTERNET);
}
}
@Override
public void onObjectAdded(UserLocationView userLocationView) {
userLocationLayer.setAnchor(
new PointF((float)(mapView.getWidth() * 0.5), (float)(mapView.getHeight() * 0.5)),
new PointF((float)(mapView.getWidth() * 0.5), (float)(mapView.getHeight() * 0.83)));
userLocationView.getArrow().setIcon(ImageProvider.fromResource(
this, R.drawable.user_location));
CompositeIcon pinIcon = userLocationView.getPin().useCompositeIcon();
pinIcon.setIcon(
"icon",
ImageProvider.fromResource(this, R.drawable.user_location),
new IconStyle().setAnchor(new PointF(0f, 0f))
.setRotationType(RotationType.ROTATE)
.setZIndex(0f)
.setScale(1f)
);
userLocationView.getAccuracyCircle().setFillColor(Color.BLUE & 0x99ffffff);
}
@Override
public void onObjectRemoved(UserLocationView view) {
}
@Override
public void onObjectUpdated(UserLocationView view, ObjectEvent event) {
}
private final InputListener il = new InputListener() {
@Override
public void onMapTap(@NonNull Map map, @NonNull Point point) {
}
@Override
public void onMapLongTap(@NonNull Map map, @NonNull Point point) {
}
};
public void showToast(final String toast)
{
runOnUiThread(() -> Toast.makeText(HomeActivity.this, toast, Toast.LENGTH_LONG).show());
}
}
2
public class GoActivityUser extends AppCompatActivity implements UserLocationObjectListener, DrivingSession.DrivingRouteListener {
private String hash;
private DBClass dbClass = new DBClass();
private UserLocationLayer userLocationLayer;
private MapView mapView;
private HashMap<String, Object> geolocation;
public DBClass DBClass;
private DrivingRouter drivingRouter;
private MapObjectCollection mapObjects;
private DrivingSession drivingSession;
private static final int REQUEST_CODE_PERMISSION_INTERNET = 1;
private static final int PERMISSIONS_REQUEST_FINE_LOCATION = 1;
private Point ROUTE_START_LOCATION = new Point(59.945933, 30.320045);
private Point ROUTE_END_LOCATION = new Point(59.945933, 30.320045);
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
peremissionInternet();
requestLocationPermission();
super.onCreate(savedInstanceState);
setContentView(R.layout.go_activity_user);
mapView = findViewById(R.id.mapviewUserGo);
mapView.getMap().setRotateGesturesEnabled(false);
mapView.getMap().move(new CameraPosition(new Point(0, 0), 14, 0, 0));
MapKit mapKit = MapKitFactory.getInstance();
userLocationLayer = mapKit.createUserLocationLayer(mapView.getMapWindow());
userLocationLayer.setVisible(true);
userLocationLayer.setHeadingEnabled(true);
userLocationLayer.setObjectListener(this);
drivingRouter = DirectionsFactory.getInstance().createDrivingRouter();
mapObjects = mapView.getMap().getMapObjects().addCollection();
try {
hash = dbClass.getHash(this);
} catch (Exception e){
Log.d("hash", e.getMessage());
}
submitRequest();
}
@Override
protected void onStop() {
super.onStop();
}
@Override
public void onObjectAdded(@NonNull UserLocationView userLocationView) {
HashMap<String, Object> geo = new HashMap<>();
userLocationLayer.setAnchor(
new PointF((float)(mapView.getWidth() * 0.5), (float)(mapView.getHeight() * 0.5)),
new PointF((float)(mapView.getWidth() * 0.5), (float)(mapView.getHeight() * 0.83)));
userLocationView.getArrow().setIcon(ImageProvider.fromResource(
this, R.drawable.user_location));
CompositeIcon pinIcon = userLocationView.getPin().useCompositeIcon();
pinIcon.setIcon(
"icon",
ImageProvider.fromResource(this, R.drawable.user_location),
new IconStyle().setAnchor(new PointF(0f, 0f))
.setRotationType(RotationType.ROTATE)
.setZIndex(0f)
.setScale(1f)
);
userLocationView.getAccuracyCircle().setFillColor(Color.BLUE & 0x99ffffff);
}
@Override
public void onObjectRemoved(@NonNull UserLocationView userLocationView) {
}
@Override
public void onObjectUpdated(@NonNull UserLocationView userLocationView, @NonNull ObjectEvent objectEvent) {
}
private void submitRequest() {
DrivingOptions drivingOptions = new DrivingOptions();
VehicleOptions vehicleOptions = new VehicleOptions();
ArrayList<RequestPoint> requestPoints = new ArrayList<>();
requestPoints.add(new RequestPoint(
ROUTE_START_LOCATION,
RequestPointType.WAYPOINT,
null));
requestPoints.add(new RequestPoint(
ROUTE_END_LOCATION,
RequestPointType.WAYPOINT,
null));
drivingSession = drivingRouter.requestRoutes(requestPoints, drivingOptions, vehicleOptions, this);
}
@Override
public void onDrivingRoutes(@NonNull List<DrivingRoute> list) {
for (DrivingRoute route : list) {
mapObjects.addPolyline(route.getGeometry()).setStrokeColor(17466623);
}
}
@Override
public void onDrivingRoutesError(@NonNull Error error) {
String errorMessage = getString(R.string.unknown_error_message);
if (error instanceof RemoteError) {
errorMessage = getString(R.string.remote_error_message);
} else if (error instanceof NetworkError) {
errorMessage = getString(R.string.network_error_message);
}
Toast.makeText(this, errorMessage, Toast.LENGTH_SHORT).show();
}
private void requestLocationPermission() {
if (ContextCompat.checkSelfPermission(this,
"android.permission.ACCESS_FINE_LOCATION")
!= PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this,
new String[]{"android.permission.ACCESS_FINE_LOCATION"},
PERMISSIONS_REQUEST_FINE_LOCATION);
}
}
private void peremissionInternet(){
if (ContextCompat.checkSelfPermission(this,
"android.permission.INTERNET")
!= PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this,
new String[]{"android.permission.INTERNET"},
REQUEST_CODE_PERMISSION_INTERNET);
}
}
}
ВОЗМОЖНЫ СИНТАКСИЧЕСКИЕ ОШИБКИ, У МЕНЯ ИХ В КОДЕ НЕТ, СОКРАЩАЛ КАК МОГ, ЧТОБЫ БЫЛО ПРОЩЕ ПОНЯТЬ СУТЬ ПРОБЛЕМЫ