问题
I have implemented the PlacePicker in my app. I have a custom dialog with a pager in it (like 2 tabs). The second pager item has an EditText component. On touch of that, I open the placepicker. The issue is that pressing back on the PlacePicker, shuts the app instead of going back to the activity from where it started.
This is the code from where the PlacePicker starts
public void showPlacePicker() {
try {
PlacePicker.IntentBuilder builder = new PlacePicker.IntentBuilder();
startActivityForResult(builder.build(OrganizerMainActivity.this), PLACE_PICKER_REQUEST);
} catch (GooglePlayServicesNotAvailableException e) {
GoogleApiAvailability.getInstance().getErrorDialog(this, e.errorCode, PLACE_PICKER_REQUEST).show();
e.printStackTrace();
} catch (GooglePlayServicesRepairableException e) {
GoogleApiAvailability.getInstance().getErrorDialog(this, e.getConnectionStatusCode(), PLACE_PICKER_REQUEST).show();
e.printStackTrace();
}
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == PLACE_PICKER_REQUEST) {
if (resultCode == RESULT_OK) {
Place selectedPlace = PlacePicker.getPlace(this, data);
LatLng values = selectedPlace.getLatLng();
String loc = selectedPlace.getAddress().toString();
eventFilters.setLat(values.latitude);
eventFilters.setLon(values.longitude);
eventFilters.setLocation(loc);
eventFilters.setUseLocation(true);
showFilterDialog();
}
}
}
The showPlacePicker function is called from the Location tab in the dialog in this way
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_filter_location, container, false);
mProgressBar = (ProgressBar) view.findViewById(R.id.filter_location_progress);
mInputLocation = (TextInputEditText) view.findViewById(R.id.filter_location_input_text);
mCheckbox = (CheckBox) view.findViewById(R.id.filter_location_checkbox);
mInputLocation.setText(eventFilters.getLocation());
mCheckbox.setChecked(eventFilters.shouldUseLocation());
mCheckbox.setEnabled(!eventFilters.getLocation().equals(""));
inputLocationTouchHandler = new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
mProgressBar.setVisibility(View.VISIBLE);
mInputLocation.setOnTouchListener(null);
mListener.showPlacePicker();
break;
case MotionEvent.ACTION_UP:
break;
}
return false;
}
};
Even when I select a location, the app shuts instead of going back to the activity from where it started.
Could anyone help me out?
来源:https://stackoverflow.com/questions/46176021/android-place-picker-does-not-return-to-activity