I am developing an Android application and it uses GoogleMaps. So when I click on a Button, I load a registraPosizioneActivity that shows the google maps. So I have noted that the loading speed of this activity is slow. Is there a mode for increasing the speed of loading this activity?
我正在开发一个Android应用程序,它使用GoogleMaps。因此,当我点击按钮时,我会加载一个显示谷歌地图的registraPosizioneActivity。所以我注意到这项活动的加载速度很慢。是否有提高此活动加载速度的模式?
This is my code:
这是我的代码:
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);
}
This is activity_recordposition.xml
这是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>
1 个解决方案
#1
0
To me it seems like you're doing a lot of processing in the onCreate method. Try moving some of this processing into an Async thread. I believe that will increase load times by a lot.
对我而言,似乎你在onCreate方法中进行了大量处理。尝试将此处理中的一部分移动到异步线程中。我相信这会增加很多加载时间。
So,
- Load up the activity, within the onCreate start an Async task
- Async thread does the processing required after the activity has loaded :)
加载活动,在onCreate中启动异步任务
异步线程执行活动加载后所需的处理:)
#1
0
To me it seems like you're doing a lot of processing in the onCreate method. Try moving some of this processing into an Async thread. I believe that will increase load times by a lot.
对我而言,似乎你在onCreate方法中进行了大量处理。尝试将此处理中的一部分移动到异步线程中。我相信这会增加很多加载时间。
So,
- Load up the activity, within the onCreate start an Async task
- Async thread does the processing required after the activity has loaded :)
加载活动,在onCreate中启动异步任务
异步线程执行活动加载后所需的处理:)