Estoy implementando la api de google places en mi aplicación , estoy trabajando con un bottom navigation como menu , por lo cual tengo distintos fragments que son las opciones , ejemplo inicio , buscar, ajustes, etc. Implemente place picker en uno de los fragments , y al ejecutar y seleccionar ese fragment en la app aparece el mapa y todo , pero se sale vuelve al menú principal, no entiendo porque, ¿alguna idea?. Saludos
Como se puede apreciar en la imagen selecciono la opción de buscar se abre el mapa pero se sale , como se puede ver en la imagen que se esta saliendo
package com.example.larra21.myapplication;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;
import com.google.android.gms.common.GooglePlayServicesNotAvailableException;
import com.google.android.gms.common.GooglePlayServicesRepairableException;
import com.google.android.gms.location.places.Place;
import com.google.android.gms.location.places.ui.PlacePicker;
import static android.app.Activity.RESULT_OK;
/**
* A simple {@link Fragment} subclass.
*/
public class BuscarFragment extends Fragment {
int PLACE_PICKER_REQUEST = 1;
public BuscarFragment() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_buscar, container, false);
PlacePicker.IntentBuilder builder = new PlacePicker.IntentBuilder();
Intent intent;
try {
intent = builder.build(getActivity());
startActivityForResult(intent, PLACE_PICKER_REQUEST);
} catch (GooglePlayServicesRepairableException e) {
e.printStackTrace();
} catch (GooglePlayServicesNotAvailableException e) {
e.printStackTrace();
}
return v;
}
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == PLACE_PICKER_REQUEST) {
if (resultCode == RESULT_OK) {
Place place = PlacePicker.getPlace(data, getActivity());
String toastMsg = String.format("Place: %s", place.getName());
Toast.makeText(getActivity(), toastMsg, Toast.LENGTH_LONG).show();
}
}
}
}