launching mapview from main activity (button)
Posted
by arc
on Stack Overflow
See other posts from Stack Overflow
or by arc
Published on 2010-03-04T16:29:37Z
Indexed on
2010/03/08
3:30 UTC
Read the original article
Hit count: 429
Hi all.
Going round in circles here i think.
I have an activity called Locate;
public class Locate extends Activity {
public static String lat;
public static String lon;
public static String number;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.locate);
final Button buttonMaps = (Button) findViewById(R.id.ButtonMaps);
buttonMaps.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Toast.makeText(getBaseContext(), "Button Pressed", Toast.LENGTH_SHORT).show();
try {
Intent i = new Intent(getBaseContext(), displayMap.class);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(i);
}
catch (ActivityNotFoundException e) {
Toast.makeText(getBaseContext(), "Activity Not Found", Toast.LENGTH_SHORT).show();
}
}});
// Toast.makeText(getBaseContext(), "lat: " + lat + " long: " + lon + " from: " + testname, Toast.LENGTH_LONG).show();
}
If I make the displayMap class into a normal Activity, and just have display a toast message confirming it has loaded - then it works fine.
If i do this though;
public class displayMap extends MapActivity
{
/** Called when the activity is first created. */
public void onCreate()
{
setContentView(R.layout.displaymap);
Toast.makeText(getBaseContext(), "Display Map", Toast.LENGTH_SHORT).show();
}
@Override
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
}
}
Then as soon as I click the Button, I get a force close.
I have the correct 'uses-library' tag in my manifest;
<application android:icon="@drawable/icon" android:label="@string/app_name">
<uses-library android:name="com.google.android.maps" />
I don't get what it just force closes everytime i try and load it.
If I make this my onClick handler then it will fire up a working googlemaps/default mapview
public void onClick(View v) {
Toast.makeText(getBaseContext(), "Button Pressed", Toast.LENGTH_SHORT).show();
Uri uri=Uri.parse("geo:"+Locate.lat+","+Locate.lon);
StartActivity(new Intent(Intent.ACTION_VIEW, uri));
}
But that is not what I am trying to do, I want my own - so that I can add overlays etc to it. But it does prove that the permission are set correctly and that the lib is there.
The logcat error when the app FCs is a Unexpected DEX error.
Can anyone point in the right direction here?
© Stack Overflow or respective owner