1

Arg.. This is frustrating:

All of a sudden (March 2012) MyLocationOverlay.enableCompass does not work. It works okay using Google APIs 14, but is leaves the screen all black on Google APIs 7 and Google APIs 8.

I would like to keep the compass functionality but since it is not essential I will just leave it disabled for now. I think this maybe a result of installing Android SDK Tools 16 over SDK Tools 15... Maybe this is a problem with my emulator setup or Eclipse? I have a strong feeling this issue will not occur on a real device.. The next step on my part will be to try it on another install of Eclipse/Android SDK but that's for another day...

Thank you for your help.

Here is my sample code: At first, onResume, I don't enable the compass... Everything works just fine. At second, onResume after onPause [hit the home button then reaccess the app], the black screen occurs. What's going on?

@Override
public void onCreate(Bundle state)
{
    super.onCreate(state);
    setContentView(MAP_LAYOUT);
    MapView mv = (MapView) findViewById(MAP_VIEW);
    mv.setBuiltInZoomControls(true);
    List<Overlay> mapOverlays = mv.getOverlays();
    Context c = getApplicationContext();
    mLocation = new MyLocationOverlay(c,mv);
    mapOverlays.add(mLocation);
}

@Override
public void onPause() {
    super.onPause();
    mLocation.disableCompass();
    mLocation.disableMyLocation();
    mCompassOn = true;
}

boolean mCompassOn = false;

@Override
public void onResume() {
    super.onResume();
    if( mCompassOn ) mLocation.enableCompass();
    mLocation.enableMyLocation();
}

My Manifest Includes:

... <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <application android:icon="@drawable/ic_launcher" android:label="@string/app_name" > <uses-library android:name="com.google.android.maps" /> ... </application> ...

And my layout includes, to match the correct debug-key store:

<com.google.android.maps.MapView
    android:id="@+id/superMapView"
    android:layout_width="fill_parent"
    android:layout_height="0dp"
    android:layout_weight="3"
    android:clickable="true"
    android:apiKey="..." />

Eclipse Platform

Version: 3.7.0.v20110530-9gF7UHNFFt4cwE-pkZDJ7oz-mj4OSEIlu9SEv0f

Build id: I20110613-1736

Android Development Toolkit

Version: 16.0.1.v201112150204-238534

The question is similar to

http://groups.google.com/group/android-developers/browse_thread/thread/8928ffa71ef35f8a

but I would like to continue to use the compass...

Ry-
  • 218,210
  • 55
  • 464
  • 476
JJ Stiff
  • 158
  • 8

1 Answers1

0

Maybe this is a problem with my emulator setup or Eclipse?

The emulator never emulated a compass. The compass rose simply would not appear. That is still what happens for me on an Android 2.1 emulator, with this sample project, even after pressing HOME and returning to the activity.

You could try tapping on the black screen a bit. If you get an ANR dialog, then the problem is that something is tying up the main application thread.

I have a strong feeling this issue will not occur on a real device

That suggests that you do not own an Android device, otherwise you would have tried this already. You need to get one, as you should never rely upon the emulator for things that get too close to hardware (e.g., GPS, magnetic flux sensor for the compass).

Also, replace all occurrences of getApplicationContext() with this. Never use getApplicationContext() for GUI work.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • Okay. Yeah, I don't really have access to an android device, true. However, I was happily suprised to see my app work quite well, even much faster than my emulator, on my friends' devices. Thank you for the insight about getApplicationContext(), I will take note. – JJ Stiff Mar 25 '12 at 19:08