How To Save The Onmapclick Intent And Restore Once Activity Returns
I am trying to save my onMapClick intent (the point where the user taps on the map to place a marker, however in my app i take a picture first then return) But it seems on Activit
Solution 1:
The question and comments are very difficult to interpret. I am going to assume that all of this stuff boils down to:
How do I hold onto the
LatLng
that is passed intoonMapLongClick()
, given that taking a picture is causing my process to be terminated and restarted?
First, add a LatLng
data member to your activity. For the purposes of this answer, I will call it:
LatLng theLastPlaceThatTheUserLongClicked;
In onMapLongClick()
, as the very first line, save off the LatLng
that is passed into onMapLongClick()
:
theLastPlaceThatTheUserLongClicked=point;
Create another constant in your class:
privatestaticfinalString EXTRA_PLACE="theLastPlaceThatTheUserLongClicked";
Replace your existing onSaveInstanceState()
and onRestoreInstanceState()
with:
@OverridepublicvoidonSaveInstanceState(Bundle savedInstanceState) {
super.onSaveInstanceState(savedInstanceState);
savedInstanceState.putParcelable(EXTRA_PLACE, theLastPlaceThatTheUserLongClicked);
}
@OverridepublicvoidonRestoreInstanceState(Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);
theLastPlaceThatTheUserLongClicked=(LatLng)savedInstanceState.getParcelable(EXTRA_PLACE);
}
Then, when you need the last place that the user long-clicked, use theLastPlaceThatTheUserLongClicked
.
Post a Comment for "How To Save The Onmapclick Intent And Restore Once Activity Returns"