1

I'm using the mapviewballoons from github and it is working up to the point where I'm trying to open another activity from a ballonItemizedOverlay

    private ArrayList<OverlayItem> m_overlays = new ArrayList<OverlayItem>();
private Context c;


public mlgwItemizedOverlay(Drawable defaultMarker,  MapView mapView) {
    super(boundCenter(defaultMarker), mapView);
    c = mapView.getContext();
}

public void addOverlay(OverlayItem overlay) {
    m_overlays.add(overlay);
    populate();
}

@Override
protected OverlayItem createItem(int i) {
    return m_overlays.get(i);
}

@Override
public int size() {
    return m_overlays.size();
}


@Override
protected boolean onBalloonTap(int index, OverlayItem item) {
    Intent Details = new Intent(c, BlogActivity.class); 
    //Details.putExtra("Id", 1327); 
    c.startActivity(Details); 
    return true;
} 

}

Here is my Main Activity

    TapControlledMapView mapView; // use the custom TapControlledMapView
List<Overlay> mapOverlays;
Drawable drawable;
mlgwItemizedOverlay itemizedOverlay;
mlgwItemizedOverlay itemizedOverlay2;

private static final class LatLonPoints extends GeoPoint { 
    public LatLonPoints(double latitude, double longitude) { 
        super((int) (latitude * 1E6), (int) (longitude * 1E6)); 
    } 
} 
@Override
public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);


    mapView = (TapControlledMapView) findViewById(R.id.mapview);
    mapView.setBuiltInZoomControls(true);

    // dismiss balloon upon single tap of MapView (iOS behavior) 
    mapView.setOnSingleTapListener(new OnSingleTapListener() {      
        @Override
        public boolean onSingleTap(MotionEvent e) {
            itemizedOverlay.hideAllBalloons();
            return true;
        }
    });

    mapOverlays = mapView.getOverlays();

    // first overlay
    drawable = getResources().getDrawable(R.drawable.marker);
    itemizedOverlay = new mlgwItemizedOverlay(drawable,  mapView);
    // set iOS behavior attributes for overlay
    itemizedOverlay.setShowClose(false);
    itemizedOverlay.setShowDisclosure(true);
    itemizedOverlay.setSnapToCenter(false);

     GeoPoint StartPoint = new LatLonPoints(35.149534,-90.04898);   
        // first overlay

    GeoPoint point = new LatLonPoints(35.139646,-90.05521);

    OverlayItem overlayItem = new OverlayItem(point, "Hello", "I'm am the first location");                     
    itemizedOverlay.addOverlay(overlayItem);
    mapOverlays.add(itemizedOverlay);

    GeoPoint point2 = new LatLonPoints(35.020922,-90.027045);
    OverlayItem overlayItem2 = new OverlayItem(point2, "Hello", "I'm am the second location"); 
    itemizedOverlay.addOverlay(overlayItem2);
    mapOverlays.add(itemizedOverlay);

    GeoPoint point3 = new LatLonPoints(35.151009,-89.978281);
    OverlayItem overlayItem3 = new OverlayItem(point3, "Hello", "I'm am the third location");       
    itemizedOverlay.addOverlay(overlayItem3);
    mapOverlays.add(itemizedOverlay);

    GeoPoint point4 = new LatLonPoints(35.088971,-89.965608);
    OverlayItem overlayItem4 = new OverlayItem(point4,  "Hello", "I'm am the fourth location");         
    itemizedOverlay.addOverlay(overlayItem4);       
    mapOverlays.add(itemizedOverlay);

    GeoPoint point5 = new LatLonPoints(35.341282,-89.8922298);
    OverlayItem overlayItem5 = new OverlayItem(point5,  "Hello", "I'm am the fifth location");      
    itemizedOverlay.addOverlay(overlayItem5);       
    mapOverlays.add(itemizedOverlay);

    if (savedInstanceState == null) {

        final MapController mc = mapView.getController();
        mc.animateTo(StartPoint);
        mc.setZoom(11);

    } else {

        // example restoring focused state of overlays
        int focused;
        focused = savedInstanceState.getInt("focused_1", -1);
        if (focused >= 0) {
            itemizedOverlay.setFocus(itemizedOverlay.getItem(focused));
        }
        focused = savedInstanceState.getInt("focused_2", -1);
        if (focused >= 0) {
            itemizedOverlay2.setFocus(itemizedOverlay2.getItem(focused));
        }

    }

}
  public void startCustomActivity(){ 
      Intent Details = new Intent(getBaseContext(), BlogActivity.class); 
      Details.putExtra("Id", 1327); 
      startActivity(Details); 
  } 

@Override
protected boolean isRouteDisplayed() {
    return false;
}

@Override
protected void onSaveInstanceState(Bundle outState) {

    // example saving focused state of overlays
    if (itemizedOverlay.getFocus() != null) outState.putInt("focused_1", itemizedOverlay.getLastFocusedIndex());
    if (itemizedOverlay2.getFocus() != null) outState.putInt("focused_2", itemizedOverlay2.getLastFocusedIndex());
    super.onSaveInstanceState(outState);

}

}

and here is blog activity that I trying to open

public class BlogActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    TextView textview = new TextView(this);
    textview.setText("This is the Blog tab");
    setContentView(textview);
}

}

Once I press the overlay the app crashes and the errors that are being returned are:

04-18 04:39:56.465: E/MapActivity(8938): Couldn't get connection factory client 04-18 04:40:03.075: E/AndroidRuntime(8938): FATAL EXCEPTION: main 04-18 04:40:03.075: E/AndroidRuntime(8938): java.lang.RuntimeException: Unable to pause activity {com.mlgw.MlgwMapView/com.mlgw.MlgwMapView.MlgwMapViewActivity}: java.lang.NullPointerException 04-18 04:40:03.075: E/AndroidRuntime(8938): at android.app.ActivityThread.performPauseActivity(ActivityThread.java:2354) 04-18 04:40:03.075: E/AndroidRuntime(8938): at android.app.ActivityThread.performPauseActivity(ActivityThread.java:2311) 04-18 04:40:03.075: E/AndroidRuntime(8938): at android.app.ActivityThread.handlePauseActivity(ActivityThread.java:2291) 04-18 04:40:03.075: E/AndroidRuntime(8938): at android.app.ActivityThread.access$1700(ActivityThread.java:117) 04-18 04:40:03.075: E/AndroidRuntime(8938): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:938) 04-18 04:40:03.075: E/AndroidRuntime(8938): at android.os.Handler.dispatchMessage(Handler.java:99) 04-18 04:40:03.075: E/AndroidRuntime(8938): at android.os.Looper.loop(Looper.java:130) 04-18 04:40:03.075: E/AndroidRuntime(8938): at android.app.ActivityThread.main(ActivityThread.java:3683) 04-18 04:40:03.075: E/AndroidRuntime(8938): at java.lang.reflect.Method.invokeNative(Native Method) 04-18 04:40:03.075: E/AndroidRuntime(8938): at java.lang.reflect.Method.invoke(Method.java:507) 04-18 04:40:03.075: E/AndroidRuntime(8938): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839) 04-18 04:40:03.075: E/AndroidRuntime(8938): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597) 04-18 04:40:03.075: E/AndroidRuntime(8938): at dalvik.system.NativeStart.main(Native Method) 04-18 04:40:03.075: E/AndroidRuntime(8938): Caused by: java.lang.NullPointerException 04-18 04:40:03.075: E/AndroidRuntime(8938): at com.mlgw.MlgwMapView.MlgwMapViewActivity.onSaveInstanceState(MlgwMapViewActivity.java:131) 04-18 04:40:03.075: E/AndroidRuntime(8938): at android.app.Activity.performSaveInstanceState(Activity.java:1037) 04-18 04:40:03.075: E/AndroidRuntime(8938): at android.app.Instrumentation.callActivityOnSaveInstanceState(Instrumentation.java:1181) 04-18 04:40:03.075: E/AndroidRuntime(8938): at android.app.ActivityThread.performPauseActivity(ActivityThread.java:2336) 04-18 04:40:03.075: E/AndroidRuntime(8938): ... 12 more

My main goal is to pass more data about the annotation that they click on to the new activity.

Can you tell me what I'm doing wrong or point me to the right solution. I've searched google for other answers but I haven't found any that work.

3 Answers3

0

Your issue is that you are over-riding onSaveInstanceState but not calling the superclass method: do this.

@Override
protected void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);

    // example saving focused state of overlays
    if (itemizedOverlay.getFocus() != null) outState.putInt("focused_1", itemizedOverlay.getLastFocusedIndex());
    if (itemizedOverlay2.getFocus() != null) outState.putInt("focused_2", itemizedOverlay2.getLastFocusedIndex());
    super.onSaveInstanceState(outState);

}

See if that helps.

Femi
  • 64,273
  • 8
  • 118
  • 148
  • That is the issue as I commented it out last night and it worked. I was already calling the super class but I was using "itemOverlay2" which I took out and was just using "itemOverlay" after removing that it worked – UndercoverGeek Apr 18 '12 at 12:13
0

try this :

protected boolean onBalloonTap(int index, OverlayItem item) {
Intent Details = new Intent(c, BlogActivity.class);
//Details.putExtra("Id", 1327);
((Activity) c).startActivity(Details);
return true;
}
0
  public class BlogActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        TextView textview = new TextView(this);

        Bundle b=getIntent.getExtras();
        if(b!=null)
      {
       String s= b.getString("Id")
      }
        textview.setText("This is the Blog tab");
        setContentView(textview);
    }
QuokMoon
  • 4,387
  • 4
  • 26
  • 50