我试过CommonsWare的答案,但是在没有MapView的情况下,即使是裸露的MapActivity也会出现明显的延迟。
所以,我把另一个活动放在中间,“MapLoading”。我的家庭活动启动MapLoading,然后使用post()立即启动MapActivity。由于滞后,应用程序在MapLoading上停留了几秒钟(这是预期的结果,而不是坚持我的家庭活动)。
MapLoading活动没有历史记录集,所以当从MapActivity单击后退按钮时,它会直接进入主屏幕。 MapActivity的未来发布速度非常快,MapLoading活动仅在屏幕上闪烁。
这里是MapLoading代码(用的MapView在它被称为地图的活动):
public class MapLoading extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.maploading);
new Handler().post(new Runnable() {
public void run()
{
startActivity(new Intent(MapLoading.this, Map.class));
}
});
}
}
下面是它的布局:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="@+id/maploading"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:textSize="14pt"
android:text="Loading map..."
/>
</RelativeLayout>
而且在AndroidManifest.xml中相应的节:
<activity android:label="@string/app_name"
android:name="MapLoading"
android:noHistory="true" />
谢谢,并获得成功,并感谢您的帮助您总是提供有用的答案 – Jason 2010-11-12 13:59:25
@Jason:嘿,很高兴它的工作。出于好奇,是'post()'就够了,还是用'postDelayed()'结束了? – CommonsWare 2010-11-12 14:30:21
这对我有帮助,但我需要使用postDelayed。 – tomwilson 2011-04-11 00:57:37