_Android Activity Not Launching MapActivity
I have decided to play around with Android and started out using the Google API for Maps. My goal is to create an app that has a tab view that you can tab through some info and on the tabs there will be a button to launch the Google Map to show the location of the point of interest and show where you are and provide directions. I have the tab view working great but when I try to fire off an event for the MapActivity that is where it fails.
If I create my own MapActivity project it works fine, but when I include the class in my tab project it fails.
Here is what I have:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.location_tab);
...
Button btnMap = (Button) findViewById(R.id.btnMapview);
btnMap.setOnClickListener(mMapListener);
...
}
And my Listener
private OnClickListener mMapListener = new OnClickListener() {
public void onClick(View v) {
Intent mapIntent = new Intent(getApplicationContext(),LocationMap.class);
startActivity(mapIntent);
}
};
And here is my Map Class:
public class LocationMap extends MapActivity {
MapView mapView;
MapController mc;
GeoPoint p;
@Override
protected boolean isRouteDisplayed() {
return false;
}
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mapView = (MapView) findViewById(R.id.myMapView);
mapView.setBuiltInZoomControls(true);
mc = mapView.getController();
String coordinates[] = {"40.750386", "-73.976773"};
double lat = Double.parseDouble(coordinates[0]);
double lng = Double.parseDouble(coordinates[1]);
p = new GeoPoint(
(int) (lat * 1E6),
(int) (lng * 1E6));
mc.animateTo(p);
mc.setZoom(17);
mapView.invalidate();
}
}
I get a force close each time I click the button. I have swapped out my LocationMap.class with a standard activity class and that works fine. I have put my LocationMap class in it’s own project and that works fine as well, but together…no dice.
Any thoughts? Here is my StackOverflow post






After 2 freakin hours of work I finally figured out how to solve this.
It seems like there is a security issue if you are trying to switch from a normal Activity to a MapActivity causing the application to crash.
However: If you put into the field of your MapActivity instance in your Manifest file, it works.
Example: I have a class named QMap extends MapActivity. If I try to start QMap from a normal Activity instance, the App crashes.
If I alter the Manifest that it looks like that:
…
…
i am able to call the QMap instance from any other activity.
Hope it helps!
[Reply]
[...] with it the problem described above which is also covered in the following blog entries here, here, here and [...]
@Martin A.
Hi, I’m having the same problem as the original post. I don’t understand your solution to this. What do you mean by “alter the manifest that it looks like that:”? Do you mean by creating the MapActivity as your main activity it works? I tried that and going from a MapActivity to a normal Activity and it also force closes.
I hope you can help me on this. Thanks.
[Reply]
@Din
Of course, sorry, seems like the XML was cropped out of my input by the comments system. Here is a link to my solution on my blog:
http://blog.quentures.com/2010/10/google-maps-on-android/
Hope it helps.
[Reply]
unfortunately the blogentry is offline
[Reply]
I ahd the same problem, Add the following to you manifest file. I DONT KNOW how exactly it worked but it worked. SetupLocation is my maps activity class
[Reply]
yeah it worked put like this in manifest
[Reply]
What do you mean by put like this???
I had the same problem ,,
hope you help me
[Reply]