0

I just started working with Android and I have a problem with my map. I created a TabActivity and added MapActivity as one of the tabs with:

spec = tabHost.newTabSpec("map").setIndicator("Map");
intent= new Intent().setClass(this, NavisMapActivity.class);
spec.setContent(intent);
tabHost.addTab(spec);

In MapActivity I get MapView from xml layout with findViewById.

     <com.google.android.maps.MapView
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/mapview"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:apiKey="my_key_is_here"
        android:clickable="false" />

When I load the app, everything works perfectly until I switch tabs or call another app. Basically when OnPause/OnStop is called. Then when I return to the map, its tiles start to flicker constantly. Only solution is to force the app to close.

This happens only with satellite tiles and from version 2.3.5 onward(tested it on an actual phone and in the Eclipse emulator).

So far I have tried:

  • using mapView.destroyDrawingCache() command in onPause function
  • adding mapView via code instead of xml layout
  • destroying whole MapActivity with LocalActivityManager when tab is switched and creating a new one

None of this helped. Could anyone please help me? Thank you

Ioras
  • 3
  • 4
  • Have you tried creating a custom tabActivity that extends from MapActivity and then use Fragments for the tabs content frame? This would also reduce the complexity of your main activity, potentially meaning more efficiency . The Google Maps api for Android is a bit lacking, I generally find. – pablisco Mar 13 '12 at 14:21
  • No, the minimal version requirement is Android 2.1 and if I'm not mistaken the fragments were implemented later. So I cant use them. I have not even worked with them yet. – Ioras Mar 13 '12 at 14:51
  • You can still use Fragments with the support package: http://developer.android.com/sdk/compatibility-library.html – pablisco Mar 13 '12 at 21:38
  • Well I transformed the project to use fragments but the result is the same...when OnPause is called the tiles go crazy. – Ioras Mar 25 '12 at 20:01
  • ok it may actually be a deeper issue: http://code.google.com/p/android/issues/detail?id=19154&q=google%20maps%20tiles&colspec=ID%20Type%20Status%20Owner%20Summary%20Stars – pablisco Mar 26 '12 at 00:31
  • Btw, did you put the map in the fragment or in the activity? Because if it was attached to the activity instead of the fragment then onPause will not be called. – pablisco Mar 26 '12 at 00:34
  • Yes, sorry...I found out that OnStop is causing the same problem. Which will happen when user switches to another app or home screen. The issue you posted looks much like my problem (even though some specifics are different) so I guess I cant do much about it... But thank you very much for your help! At least now it partially works. – Ioras Mar 27 '12 at 15:41
  • Glad to help, I want to find an alternative solution for Google Maps API myself since it seems to cause way too many problems. – pablisco Mar 27 '12 at 15:43

1 Answers1

0

As I mentioned in the comments this seems to be a problem with the Google Maps API:

http://code.google.com/p/android/issues/detail?id=19154&q=google%20maps%20tiles&colspec=ID%20Type%20Status%20Owner%20Summary%20Stars

Let's hope that they fix it some time soon.

I want to try some of these alternatives:

Alternatives to google maps api

Will report back if any is worth dealing with :)

This one also seems promising: http://code.google.com/p/mapsforge/

Community
  • 1
  • 1
pablisco
  • 14,027
  • 4
  • 48
  • 70