Two or more Google maps (API v2) in tabs in Android -


does know if it's possible use (and how) mapviews (google maps api v2) on 2 or more tabs in tabhost?

following (quite long) text describes problem 2 or more maps on tabhost , findings this. maybe knows better (cleaner) solution. please if can. or confirm findings.

i have application tabhost , tabs need display map. there activities (and fragments) run in each tab. need display maps using mapview, call mapview's oncreate(), onresume(), ... on appropriate methods of parent activities (fragments resp.). when switch between tabs (activities) first map works. maps on other tabs display first tab map, until remove first tab map parent view group.

i built own test app based on google maps api v2 demo package , have 4 map demos can run either list or in tabs. when run test 1 after each other list, works expected, there oncreate(), onresume(), onpause() , ondestroy() called on mapview , internal gms, opengl or whatever resources released , reinitialized (i suppose).

each activity/fragment has own mapview, each mapview mentioned codes unique respective activity/fragment declares it.

list   click item     activity.oncreate() -> mapview initialized, mapview.oncreate()     activity.onresume() -> mapview.onresume()     map shown , works expcted   click     activity.onsaveinstancestate() -> mapview.onsaveinstancestate()     activity.onpause() -> mapview.onpause()     activity.ondestroy() -> mapview.ondestoy() 

the list displayed , item can selected , works fine.

but when run tests in tabs, first map works, when switch other tab, there no ondestroy() called on first tab activity , no ondestroy() called on mapview. understand (read further) it's not problem.

tab (original version, mapview's methods called respective activity/frag methods)   first tab displayed (ftab)     ftabactivity.oncreate() -> mapview initialized, mapview.oncreate()     ftabactivity.onresume() -> mapview.onresume()     map shown , works expected   click on other tab (otab)     ftabactivity.onsaveinstancestate() -> mapview.onsaveinstancestate()     ftabactivity.onpause() -> mapview.onpause()     // no ftabactivity.ondestroy()     otabactivity.oncreate() -> mapview initialized, mapview.oncreate()     otabactivity.onresume() -> mapview.onresume()     !! first map still visible it's not possible control other map   click first tab     otabactivity.onsaveinstancestate() -> mapview.onsaveinstancestate()     otabactivity.onpause() -> mapview.onpause()     // no otabactivity.ondestroy()     ftabactivity.onresume() -> mapview.onresume()     map on ftab works 

i suspect map first tab still displayed when switch other tab, when pan map on first tab see panned map on other tab. , that's possibly reason why cannon pan or zoom map on other tab. or maybe pan , zoom don't see there map first tab displayed.

when move mapview.ondestroy() activity/fragment onpause() , mapview.oncreate() activity/fragment onresume() still have same problem. still see first tab mapview on other tabs, first tab mapview should destroyed. possibly bug or opengl cached data displayed?

tab (both mapview.oncreate() , mapview.onresume() called activity/fragment onresume())   first tab displayed (ftab)     ftabactivity.oncreate() -> mapview initialized     ftabactivity.onresume() -> mapview.oncreate(), mapview.onresume()     map shown , works expected   click on other tab (otab)     ftabactivity.onsaveinstancestate() -> mapview.onsaveinstancestate()     ftabactivity.onpause() -> mapview.onpause(), mapview.ondestroy();     // no ftabactivity.ondestroy()     otabactivity.oncreate() -> mapview initialized     otabactivity.onresume() -> mapview.oncreate(), mapview.onresume()     !! first map still visible it's not possible control other map   click first tab     otabactivity.onsaveinstancestate() -> mapview.onsaveinstancestate()     otabactivity.onpause() -> mapview.onpause(), mapview.ondestroy();     // no otabactivity.ondestroy()     ftabactivity.onresume() -> mapview.oncreate(), mapview.onresume()     map on ftab works 

the solution found work (but don't much) remove mapview parent viewgroup (setting mapview visibility gone doesn't help). it's possible put mapview oncreate() , ondestroy() respective activity/fragment oncreate() , ondestroy(). first tab mapview disappears , see other tab mapview , can control map.

tab (mapview's methods called respective activity/frag methods)   first tab displayed (ftab)     ftabactivity.oncreate() -> mapview initialized, mapview.oncreate(), remove mapview parent view group     ftabactivity.onresume() -> mapview.onresume(), add mapview parent view group     map shown , works expected   click on other tab (otab)     ftabactivity.onsaveinstancestate() -> mapview.onsaveinstancestate()     ftabactivity.onpause() -> mapview.onpause(), remove mapview parent view group     // no ftabactivity.ondestroy()     otabactivity.oncreate() -> mapview initialized, mapview.oncreate(), remove mapview parent view group     otabactivity.onresume() -> mapview.onresume(), add mapview parent view group     map on otab works   click first tab     otabactivity.onsaveinstancestate() -> mapview.onsaveinstancestate()     otabactivity.onpause() -> mapview.onpause(), remove mapview parent view group     // no otabactivity.ondestroy()     ftabactivity.onresume() -> mapview.onresume(), add mapview parent view group     map on ftab works 

regards, martin


Comments

Popular posts from this blog

sql - VB.NET Operand type clash: date is incompatible with int error -

SVG stroke-linecap doesn't work for circles in Firefox? -

python - TypeError: Scalar value for argument 'color' is not numeric in openCV -