PS: когда я удаляю CustomersPicked прямо из Firebase, карта не перезагружается.Я создаю приложение для пула автомобилей.Когда клиент заканчивает поездку, фрагмент карты Google перезагружается, и моя активность теряет данные.Я также использую Firebase RecyclerView.
Я попытался отредактировать свою функцию завершения поездки, отладки и т. Д. Я также изменил значение ValueEventListeners на ListenerForSingleValueEvents.Последовательность такова: водитель устанавливает свой пункт назначения и нажимает на переключатель, чтобы показать, что он доступен, гонщик может видеть это на своей карте, если он задает то же направление.
на автобусной остановке, когда водитель выбираетРайдер сканирует свой qr, а затем добавляется в свою таблицу CustomerPicked, которая вызывает RecyclerView, чтобы показать пользователю.Моя проблема: когда пользователь заканчивает поездку, активность водителя и карта перезагружаются.
CustomerMap Activty:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_costumer_map);
// Obtain the SupportMapFragment and get notified when the map is //ready to be used.
context = this;
mFusedLocationClient = LocationServices.getFusedLocationProviderClient(this);
mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
init();
}
private int radius = 1;
private Boolean driverFound = false;
private String driverFoundID;
GeoQuery geoQuery;
//used to pick the closest driver
private void getClosestDriver(){
DatabaseReference driverLocation = FirebaseDatabase.getInstance().getReference().child("driversWorking").child(destination);
GeoFire geoFire = new GeoFire(driverLocation);
geoQuery = geoFire.queryAtLocation(new GeoLocation(mLastLocation.getLongitude(), mLastLocation.getLatitude()), radius);
geoQuery.removeAllListeners();
geoQuery.addGeoQueryEventListener(new GeoQueryEventListener() {
@Override
public void onKeyEntered(String key, GeoLocation location) {
if (!driverFound){
DatabaseReference mCustomerDatabase = FirebaseDatabase.getInstance().getReference().child("Users").child(key);
mCustomerDatabase.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
if (dataSnapshot.exists() && dataSnapshot.getChildrenCount()>0){
if (driverFound){
return;
}
if(!driverFound){
driverFound = true;
driverFoundID = dataSnapshot.getKey();
getDriverLocation();
//getDriverInfo();
Toast.makeText(getApplicationContext(),"Looking for Driver Location....", Toast.LENGTH_SHORT).show();
}
}
}
});
}
}
@Override
public void onGeoQueryReady() {
if (!driverFound)
{
radius++;
getClosestDriver();
}
}
});
}
****private void endRide(){
recordRide();
geoQuery.removeAllListeners();
dest.setVisibility(View.GONE);
destinationTextview.setText("Welcome to Sole");
driverFound = false;
radius = 1;
String userId = FirebaseAuth.getInstance().getCurrentUser().getUid();
DatabaseReference refq = FirebaseDatabase.getInstance().getReference("customerPicked").child(driverFoundID).child(userId);
refq.removeValue();
DatabaseReference ref = FirebaseDatabase.getInstance().getReference("driversWorking").child(destination).child("customerRequest");
GeoFire geoFire = new GeoFire(ref);
geoFire.removeLocation(userId);
if (mDriverMarker != null){
mDriverMarker.remove();
}
if (rideDistance > 0){
rideDistance = 0;
}
}****
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
mMap.setOnMarkerClickListener(this);
mLocationRequest = new LocationRequest();
mLocationRequest.setInterval(1000);
mLocationRequest.setFastestInterval(1000);
mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
boolean success = googleMap.setMapStyle(new MapStyleOptions(getResources()
.getString(R.string.style_json)));
if (!success) {
Log.e("styling", "Style parsing failed.");
}
if(android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.M){
if(ContextCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED){
mFusedLocationClient.requestLocationUpdates(mLocationRequest, mLocationCallback, Looper.myLooper());
mMap.setMyLocationEnabled(true);
}else{
checkLocationPermission();
}
}
}
LatLng latLng;
LocationCallback mLocationCallback = new LocationCallback(){
@Override
public void onLocationResult(LocationResult locationResult) {
for(Location location : locationResult.getLocations()){
if(getApplicationContext()!=null){
mLastLocation = location;
if (onTrip && mLastLocation != null && location != null) {
rideDistance += mLastLocation.distanceTo(location) / 1000;
}
latLng = new LatLng(location.getLatitude(),location.getLongitude());
mMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
mMap.animateCamera(CameraUpdateFactory.zoomTo(11));
}
}
}
};
DriverMap активность
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_driver_map);
context = this;
//location services
mFusedLocationClient = LocationServices.getFusedLocationProviderClient(this);
mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
init();
}
};
recyclerView = findViewById(R.id.recyclerView);
manager = new LinearLayoutManager(DriverMapActivity.this);
recyclerView.setLayoutManager(manager);
recyclerView.setAdapter(recyclerAdapter);
recyclerAdapter.startListening();
}
@Override
protected void onStart(){
super.onStart();
recyclerAdapter.startListening();
}
@Override
protected void onStop() {
super.onStop();
recyclerAdapter.stopListening();
}
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
mLocationRequest = new LocationRequest();
mLocationRequest.setInterval(1000);
mLocationRequest.setFastestInterval(1000);
mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
} else {
checkLocationPermission();
}
}
boolean success = googleMap.setMapStyle(new MapStyleOptions(getResources()
.getString(R.string.style_json)));
if (!success) {
Log.e("styling", "Style parsing failed.");
}
}
LocationCallback mLocationCallback = new LocationCallback() {
@Override
public void onLocationResult(LocationResult locationResult) {
for (Location location : locationResult.getLocations()) {
if (getApplicationContext() != null) {
mLastLocation = location;
latLng = new LatLng(location.getLatitude(), location.getLongitude());
mMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
mMap.animateCamera(CameraUpdateFactory.zoomTo(11));
if(connect && driver_destination!= "") {
//sets the driver as working when he switches on
String userId = FirebaseAuth.getInstance().getCurrentUser().getUid();
DatabaseReference refWorking2 = FirebaseDatabase.getInstance().getReference("driversWorking").child(driver_destination);
GeoFire geoFireWorking = new GeoFire(refWorking2);
geoFireWorking.setLocation(userId, new GeoLocation(location.getLatitude(), location.getLongitude()));
}
}
}
}
};
}
Когда моя последняя поездка связана с работой с клиентами, она удаленно перезапускает драйвер, вот журнал драйверов
05-21 13:15:33.247 9159-10290/com.aderoju.sole D/libEGL: eglTerminate EGLDisplay = 0x7f47fbdac8
05-21 13:15:33.247 9159-10290/com.aderoju.sole D/libEGL: eglTerminate EGLDisplay = 0x7f47fbdac8
05-21 13:15:33.267 9159-9159/com.aderoju.sole W/ResourcesManager: getTopLevelResources: /data/app/com.aderoju.sole-1/base.apk / 1.0 running in com.aderoju.sole rsrc of package com.aderoju.sole
05-21 13:15:33.287 9159-14446/com.aderoju.sole D/FA: Logging event (FE): user_engagement(_e), Bundle[{firebase_event_origin(_o)=auto, engagement_time_msec(_et)=378069, firebase_screen_class(_sc)=DriverMapActivity, firebase_screen_id(_si)=-3114034998008447800}]
05-21 13:15:33.287 9159-9159/com.aderoju.sole I/Google Maps Android API: Google Play services package version: 17122019
05-21 13:15:33.377 9159-9159/com.aderoju.sole D/AbsListView: Get MotionRecognitionManager
05-21 13:15:33.397 9159-9159/com.aderoju.sole D/ClipboardExManager: no knox
05-21 13:15:33.397 9159-9159/com.aderoju.sole D/TextView: setTypeface with style : 0
05-21 13:15:33.397 9159-9159/com.aderoju.sole I/InjectionManager: dispatchOnViewCreated > Target : com.google.android.gms.location.places.ui.PlaceAutocompleteFragment isFragment :true
05-21 13:15:33.397 9159-10263/com.aderoju.sole I/System.out: (HTTPLog)-Static: isSBSettingEnabled false
05-21 13:15:33.397 9159-10263/com.aderoju.sole I/System.out: (HTTPLog)-Static: isSBSettingEnabled false
05-21 13:15:33.397 9159-9159/com.aderoju.sole I/Switch: Immediately mode attached=false laidOut=false
05-21 13:15:33.397 9159-9159/com.aderoju.sole I/Switch: Immediately mode attached=false laidOut=false
05-21 13:15:33.407 9159-10265/com.aderoju.sole I/System.out: (HTTPLog)-Static: isSBSettingEnabled false
05-21 13:15:33.407 9159-10265/com.aderoju.sole I/System.out: (HTTPLog)-Static: isSBSettingEnabled false
05-21 13:15:33.407 9159-9159/com.aderoju.sole D/TextView: setTypeface with style : 0
05-21 13:15:33.407 9159-9159/com.aderoju.sole D/TextView: setTypeface with style : 0
05-21 13:15:33.407 9159-9159/com.aderoju.sole D/TextView: setTypeface with style : 0
05-21 13:15:33.407 9159-9159/com.aderoju.sole D/TextView: setTypeface with style : 0
05-21 13:15:33.407 9159-9159/com.aderoju.sole D/TextView: setTypeface with style : 0
05-21 13:15:33.407 9159-9159/com.aderoju.sole D/TextView: setTypeface with style : 0
05-21 13:15:33.417 9159-9159/com.aderoju.sole D/TextView: setTypeface with style : 0
05-21 13:15:33.417 9159-10263/com.aderoju.sole I/qtaguid: Tagging socket 20 with tag 3000110100000000{805310721,0} uid -1, pid: 9159, getuid(): 10171
05-21 13:15:33.417 9159-9159/com.aderoju.sole D/TextView: setTypeface with style : 0
05-21 13:15:33.417 9159-10265/com.aderoju.sole I/qtaguid: Tagging socket 70 with tag 3000110100000000{805310721,0} uid -1, pid: 9159, getuid(): 10171
05-21 13:15:33.427 9159-9159/com.aderoju.sole D/Activity: performCreate Call Injection manager
05-21 13:15:33.427 9159-9159/com.aderoju.sole I/InjectionManager: dispatchOnViewCreated > Target : com.aderoju.sole.DriverMapActivity isFragment :false
05-21 13:15:33.427 9159-9159/com.aderoju.sole D/SecWifiDisplayUtil: Metadata value : SecSettings2
05-21 13:15:33.427 9159-9159/com.aderoju.sole D/ViewRootImpl: #1 mView = com.android.internal.policy.PhoneWindow$DecorView{29fe9e I.E...... R.....ID 0,0-0,0}
05-21 13:15:33.427 9159-14446/com.aderoju.sole D/FA: Logging event (FE): screen_view(_vs), Bundle[{firebase_event_origin(_o)=auto, firebase_previous_class(_pc)=DriverMapActivity, firebase_previous_id(_pi)=-3114034998008447800, firebase_screen_class(_sc)=DriverMapActivity, firebase_screen_id(_si)=-3114034998008447799}]
05-21 13:15:33.467 9159-9250/com.aderoju.sole D/mali_winsys: new_window_surface returns 0x3000, [1440x2560]-format:1
05-21 13:15:33.487 9159-14452/com.aderoju.sole D/libEGL: eglInitialize EGLDisplay = 0x7f466a7f08
05-21 13:15:33.487 9159-14452/com.aderoju.sole D/mali_winsys: new_window_surface returns 0x3000, [1440x2476]-format:2
05-21 13:15:33.507 9159-9159/com.aderoju.sole D/ViewRootImpl: MSG_RESIZED_REPORT: ci=Rect(0, 84 - 0, 0) vi=Rect(0, 84 - 0, 0) or=1
05-21 13:15:33.537 9159-14446/com.aderoju.sole D/FA: Connected to remote service
05-21 13:15:33.537 9159-9159/com.aderoju.sole D/libEGL: eglTerminate EGLDisplay = 0x7fe15ff528
05-21 13:15:33.577 9159-9159/com.aderoju.sole I/Timeline: Timeline: Activity_idle id: android.os.BinderProxy@408b32e time:13317841
05-21 13:15:33.577 9159-10264/com.aderoju.sole I/System.out: (HTTPLog)-Static: isSBSettingEnabled false
05-21 13:15:33.577 9159-10264/com.aderoju.sole I/System.out: (HTTPLog)-Static: isSBSettingEnabled false
05-21 13:15:33.577 9159-10264/com.aderoju.sole I/qtaguid: Tagging socket 49 with tag 3000110100000000{805310721,0} uid -1, pid: 9159, getuid(): 10171
05-21 13:15:33.797 9159-9250/com.aderoju.sole D/libEGL: eglInitialize EGLDisplay = 0x7f6552ef08
05-21 13:15:34.307 9159-10265/com.aderoju.sole I/qtaguid: Tagging socket 128 with tag 3000110100000000{805310721,0} uid -1, pid: 9159, getuid(): 10171
05-21 13:15:34.307 9159-10264/com.aderoju.sole I/qtaguid: Tagging socket 129 with tag 3000110100000000{805310721,0} uid -1, pid: 9159, getuid(): 10171
05-21 13:15:34.307 9159-10263/com.aderoju.sole I/qtaguid: Tagging socket 131 with tag 3000110100000000{805310721,0} uid -1, pid: 9159, getuid(): 10171
05-21 13:15:34.757 9159-10263/com.aderoju.sole I/qtaguid: Untagging socket 20
05-21 13:15:34.757 9159-10265/com.aderoju.sole I/qtaguid: Untagging socket 70
05-21 13:15:35.777 9159-10264/com.aderoju.sole I/qtaguid: Untagging socket 49
05-21 13:15:35.887 9159-9250/com.aderoju.sole D/libEGL: eglInitialize EGLDisplay = 0x7f6552ef08
05-21 13:15:35.957 9159-9250/com.aderoju.sole D/libEGL: eglInitialize EGLDisplay = 0x7f6552ef08
05-21 13:15:36.487 9159-10262/com.aderoju.sole I/System.out: (HTTPLog)-Static: isSBSettingEnabled false
05-21 13:15:36.497 9159-10262/com.aderoju.sole I/System.out: (HTTPLog)-Static: isSBSettingEnabled false
05-21 13:15:36.517 9159-10262/com.aderoju.sole I/qtaguid: Tagging socket 104 with tag 3000110100000000{805310721,0} uid -1, pid: 9159, getuid(): 10171
```