Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Different Map-View sizes between 2 activities

I have 2 activities that contains MapView. In activity A mapview have different size then in activity B. The call hirarchy is Activity A -> Activity B. When I'm returning from Activity B to A the half of the map is black (only Google sign remains in left corner). Moving map has no effect (bottom of the map is still black) only zoom in/out makes map looks properly.

In android manifest I use different ID's, I've tried invalidate() mapview in onResume() method, I've tried to call findViewById(android.R.id.content).requestLayout() on whole layout also in onResume()with no effect. The only solution was to finish() activity onPause() and create it again on keyback in activity B. Is there any other way to fix this?

like image 377
balu Avatar asked Jan 20 '26 20:01

balu


1 Answers

The problem is that Google Maps API won't let you have several instances of MapView active on the same time. When you open Activity B from Activity A, Activity A still stays in stack and its MapView is still working. So when you instantiate another MapView in Activity B, the older one starts to behave abnormally. There are several workarounds, but none of them can be considered stable, so you should go with your solution of destroying and recreating Activity A, or redesign your application such that only one of your Activities uses MapView. Hope this helps.

like image 141
Egor Avatar answered Jan 22 '26 12:01

Egor



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!