Any tips on how to speed this up in Android?

In one exercise, I do this:

  • Every minute I update the GPS location to the cloud.
  • Then, after updating the location, I upload a list of 10 people and their icons ... and update them in the list. (each icon is 80x80 and about 2Kb)

This is done every minute, again and again.

My problem: does it seem a little slow? Sometimes, when I scroll through the list, does it slow down? And when I click, the answer is not right away ... and may require a little hold.

Do you think I can fix this with a few "threads" or something else? Please advise. Thanks.

Edit: when loading names and custom icons into a list ... this is practically unusable. The list freezes ... and you cannot scroll up or down. And when it does not load ... the list skips very slowly.

+4
source share
3 answers

For activities such as loading material β€œinto” an Activity, it is always useful to have background services to do the work for the Activity, which then remains responsive! If you try to do something similar in the Activity itself, you will probably have problems with responsiveness, I can assure you! So: my answer is yes. Submit help desk for this!

+5
source

Threading and caching are probably good ideas. If your list has only ten people (10 times in 2 Kbytes of memory, 20 kB), consider using a cached list for the user interface and update it after each download. Check out the AsyncTask class that was introduced with Android 1.5 for this. A simple code example might look something like this:

mCachedList; private void onUpdate(Location location) { DownloadTask refresh = new DownloadTask(location); refresh.execute(); } private class DownloadTask extends AsyncTask<Location, void, ArrayList<ListItem> { protected ArrayList<ListItem> doInBackground(Location... params) { final ArrayList<ListItem> refreshlist = new ArrayList<ListItem>; Location location = params[0]; sendToCloud(location); while(!done) { ListItem next = downLoadPerson(); refreshlist.add(next); } return refreshlist; } protected void onPostExecute(ArrayList<ListItem> refreshlist) { mCachedList = refreshlist; } } 

Use the cached list for the user interface until the background task finishes and is updated. There are more complex things you could do to save more memory, like reusing the update list, etc., but I hope the above gives some information on how to do this in the background. Also remember to reuse the conversion on your list to avoid a lot of garbage collection on each item when scrolling through the list.

+2
source

If you fail to download all the information in one request, you will get time by typing it. Also, do I really need to download icons over and over? Maybe you can cache them?

+1
source

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


All Articles