How to increase download speed activity?

I am developing an Android application and it uses GoogleMaps. Therefore, when I click the Button, I load registraPosizioneActivity, which shows Google maps. Therefore, I noted that the download speed of this activity is slow. Is there a way to increase the download speed of this activity?

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

 <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> 
+6
source share
1 answer

It seems to me that you are processing a lot in the onCreate method. Try moving part of this processing to an Async stream. I believe it will increase load times by a lot.

So,

  • Download the action, inside onCreate run the Async task
  • Asynchronous thread performs the processing necessary after the activity is loaded :)
0
source

Source: https://habr.com/ru/post/976781/


All Articles