我正在开发Android应用程序并使用GoogleMaps。因此,当我点击按钮时,我会加载一个显示谷歌地图的registraPosizioneActivity。所以我注意到这项活动的加载速度很慢。是否有提高此活动加载速度的模式?
这是我的代码:
protected void onCreate(Bundle savedInstanceState) {
try{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_recordposition);
locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
Criteria criteria = new Criteria();
criteria.setAccuracy(Criteria.ACCURACY_FINE);
provider = locationManager.getBestProvider(criteria, false);
locationManager.requestLocationUpdates(provider, 1000, 0, this);
settaMappa();
if(myPosition==null){
pDialog = ProgressDialog.show(this, "Attendere ...", "Localizzazione in corso ...", true);
pDialog.setCancelable(false);
}
}catch(Exception e){
Log.e("Errore onCreate:",e.getMessage());
Utility.generateNoteOnSD(fileName,e.getMessage());
}
}
public void settaMappa(){
mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map2)).getMap();
mMap.setMapType(GoogleMap.MAP_TYPE_TERRAIN);
mMap.setMyLocationEnabled(true);
}
这是activity_recordposition.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:map="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000000"
android:orientation="vertical"
tools:context=".registraPosizioneActivity"
android:gravity="center">
<fragment
android:name="com.google.android.gms.maps.SupportMapFragment"
android:id="@+id/map2"
android:layout_height="0dp"
android:layout_weight="10"
android:layout_width="match_parent"
class="com.google.android.gms.maps.SupportMapFragment"
/>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:orientation="horizontal" >
<Button
android:id="@+id/buttonR"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="0.20"
android:layout_margin="20dp"
android:background="#0080c2"
android:textColor="#FFF"
android:textSize="20sp"
android:onClick="registraPunto"
android:text="@string/registraPunto" />
<Button
android:id="@+id/buttonSava"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="0.20"
android:layout_margin="20dp"
android:background="#0080c2"
android:textColor="#FFF"
android:textSize="20sp"
android:onClick="savaAreaTracciata"
android:text="@string/terminaRegistrazione" />
</LinearLayout>
答案 0 :(得分:0)
对我而言,似乎您在onCreate方法中进行了大量处理。尝试将此处理中的一部分移动到异步线程中。我相信这会增加很多加载时间。
所以,