从主要活动(按钮)启动mapview
问题描述:
在这里我想到了绕圈圈。从主要活动(按钮)启动mapview
我有一个活动叫做定位;
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();
}
如果我做displayMap类成为一个正常的活动,只是有显示敬酒消息,确认已加载 - 然后它工作正常。
如果我这样做,但;
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;
}
}
然后,只要我点击按钮,我就会收到一个力量。
我在我的清单中有正确的'uses-library'标签;
<application android:icon="@drawable/icon" android:label="@string/app_name">
<uses-library android:name="com.google.android.maps" />
我不明白它只是强制关闭每次我尝试并加载它。
如果我让这个我的onClick处理程序,然后它会启动一个工作的GoogleMaps /默认的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));
}
但是那不是我想做的事,我想我自己 - 这样我可以添加覆盖等等。但它确实证明权限设置正确,并且lib在那里。
当应用程序FC是意外的DEX错误时,logcat错误。
任何人都可以在这里指出正确的方向吗?
答
好吧,我发现问题。出于某种原因,我有谷歌apis,然后在eclipse中我的buildpath/lib列出的maps.jar。清理它,现在按预期工作。
答
在你的displayMap您的onCreate,你忘了调用超类
public class displayMap extends MapActivity
{
/** Called when the activity is first created. */
public void onCreate()
{
super.onCreate(icicle); /************* Line to add ********/
setContentView(R.layout.displaymap);
Toast.makeText(getBaseContext(), "Display Map", Toast.LENGTH_SHORT).show();
}
而且不建议getBaseContext()
- 使用getContext()
或this
内其他* post
即便如此做,但它仍然强行关闭。我将在下面添加更多信息。 – Mark 2010-03-07 13:54:33