Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to persist Marker from Google API Android v2?

Marker does not implement Parcelable, Serializable interfaces, but i need to persist it between Activity onPause/onResume, so how can i persist it? How can i get all current Markers list (can't find getMarkers() method anywhere)?

Imagine the next case: i have added Marker and started AsyncTask to perform long-running task and update view for the Marker. Task is in progress and i change orientation, activity is recreated. How can i update that Marker after Task is finished? Let's imagine i can persist id of the Marker and Markers are saved by fragment automatically (just imagine), then how can i find it using id after activity is recreated?

like image 225
4ntoine Avatar asked Dec 07 '12 11:12

4ntoine


3 Answers

You can persist MarkerOptions objects because they are Parcelable and then recreate Marker objects from them.

like image 74
Tadas Avatar answered Sep 22 '22 13:09

Tadas


Markers are not part of the "UI state" and hence shouldn't be saved/restored on configuration change.

On configuration change, you will simply recreate all Markers using the exact same code you used to populate the GoogleMap the first time it has been displayed.

If you really want to persist them (which is a really bad idea from my point fo view), this is still possible by doing so manually in onSaveInstance(Bundle outState)


Edit: See "Deep Dive Into Android State Restoration"

like image 25
Cyril Mottier Avatar answered Sep 21 '22 13:09

Cyril Mottier


it seems that there is no way to do this now: http://code.google.com/p/gmaps-api-issues/issues/detail?id=4650

like image 23
4ntoine Avatar answered Sep 18 '22 13:09

4ntoine