0

I'm going to load data from internet and show them on custom list view in the fragment with material design (with navigation drawer), now i was searching about lazy loading then i saw things about caching data in cache and internal storage so i confused, because i don't know how to do that, actually i'm scared about it but i have an idea and since its about loading data without saving it, i decided to ask you about it, is there problem to load data into Ram(loading into objects without saving it to internal storage) Objects. i'm afraid if user surf's the application after a while, application will crash

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Ebrahim Karimi
  • 732
  • 8
  • 24
  • If the content you are loading from the internet is not large data, then Android can handle it pretty nicely, otherwise you may want to create a temporary offline reference on your internal or external storage, but the downside is that this is considerably slow than the RAM method. And your fear seems to be of an OOM exception. But I will advise that you try your suggestion first and see the memory usage in the profiler – Clement Osei Tano Jan 06 '18 at 15:54
  • Does your server API support pagination? – OneCricketeer Jan 06 '18 at 16:26
  • Yup, im writing the server too – Ebrahim Karimi Jan 06 '18 at 16:46

2 Answers2

0

1. Use RecyclerView, not ListView for list

2. If data has images, you must use libraries that supporting loading images like Picasso, Glide, ... to prevent crashes due to lack of RAM

3 You should add loadmore function, for example load 30 items first, then you can loadmore and update RecyclerView data

EDIT

You can use background task to download all if data is large

Liar
  • 1,235
  • 1
  • 9
  • 19
0

That's perfectly fine unless data is very huge say 1000s of items in the list. If you do not want to have offline support, you should not save this data on Disk.

Above holds true only for Text, If you have images in your data (assuming image URLs), You should leave it to libraries like Glide, Picasso & UIL, They will take care of In memory(RAM) & Disk cache for you.

Pre-optimization is overkill most of the time, don't get too worried about the problems you don't have.

Akhil
  • 6,667
  • 4
  • 31
  • 61