나는 onLocationChanged 메서드를 사용하는 액티비티를 가지고 있으며, 구문 분석 쿼리를 수행 할 때 토스트를 만듭니다. 그것은 잘 작동합니다. 그러나 다른 액티비티 (맵 액티비티)로 이동하면 좌표를 변경하면 토스트가 튀어 나옵니다. onLocationChanged 메서드가 아직 실행중인 이유를 알고 싶습니다. 컨텍스트 때문일 수 있다고 생각했지만 컨텍스트 필드에서 활동을 지정했습니다.onLocationChanged 메서드가 여전히 다른 액티비티에서 실행 중임
locationManager = (LocationManager) DriverChoicesActivity.this.getSystemService(Context.LOCATION_SERVICE);
locationListener = new LocationListener() {
@Override
public void onLocationChanged(final Location location) {
final ParseGeoPoint parseGeoPoint = new ParseGeoPoint(location.getLatitude(), location.getLongitude());
ParseQuery<ParseUser> query = ParseUser.getQuery();
query.whereEqualTo("username", ParseUser.getCurrentUser().getUsername());
query.findInBackground(new FindCallback<ParseUser>() {
@Override
public void done(List<ParseUser> objects, ParseException e) {
if (e == null && objects.size() > 0) {
for (ParseObject object : objects) {
object.put("driverLocation", parseGeoPoint);
object.saveInBackground();
Toast.makeText(DriverChoicesActivity.this, "User found", Toast.LENGTH_SHORT).show();
}
}
}
});
updateRequestList(location);
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
}
@Override
public void onProviderEnabled(String provider) {
}
@Override
public void onProviderDisabled(String provider) {
}
};
모든 것은 원래 활동 (DriverChoicesActivity.class)의 onCreate 내에 있습니다. 다른 액티비티 (DriverMapActivity.class)에는이 액티비티의 인 텐트를 얻는 것과 별도로 위도와 경도 점을 수집하는 코드가 없습니다. 다음은 의도를 만드는 코드입니다 (onCreate 내에서도)
requestListView.setAdapter(arrayAdapter);
requestListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
if (requestLatitude.size() > position && requestLongitude.size() > position) {
if (Build.VERSION.SDK_INT < 23 || ContextCompat.checkSelfPermission(DriverChoicesActivity.this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
Location getLastKnownLocation = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
if (getLastKnownLocation != null) {
Intent intent = new Intent(getApplicationContext(), DriverMapActivity.class);
intent.putExtra("requestLatitude", requestLatitude.get(position));
intent.putExtra("requestLongitude", requestLongitude.get(position));
intent.putExtra("driverLatitude", getLastKnownLocation.getLatitude());
intent.putExtra("driverLongitude", getLastKnownLocation.getLongitude());
startActivity(intent);
}
}
}
}
});
필자는 문맥에 문제가 있다고 생각합니다. 누군가가 친절하게 설명 할 수 있다면.
감사합니다
완벽한, 감사 – CodeNovice