私は、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)には、このアクティビティからインテントを取得して緯度と経度のポイントを収集することを除いて、コードはありません。ここで意図を行うコードは、私は私の問題は何とかコンテキストであると仮定し
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);
}
}
}
}
});
(ものonCreate内)です。誰かが説明するのに十分な親切な人であれば。
はありがとう
クラスdeclaractionの下で、おかげで – CodeNovice