performance - Why memory keeps increasing when you scroll in a List on Android -


i watching monitor on android , notice memory keeps increasing when scroll down , up. using adaper. it's supposed reuse views, seems doesn't work.

as can see in images below memory starts @ 9.94 mb , increase @ 25.82 mb scrolling down , up.

  • pic1 pic2 pic3 pic4

you can see code use.

public class listmainfragment             extends fragment             implements loadermanager.loadercallbacks<list<earthquake>> {      public listmainfragment() {         // required empty public constructor     }     listview listview;      @override     public view oncreateview(final layoutinflater inflater, viewgroup container,                          bundle savedinstancestate) {          view viewroot = inflater.inflate(r.layout.fragment_mainlist, container, false);          final arraylist<earthquake> earthquake =             (arraylist<earthquake>) new earthquakecontroller(new earthquakesjson()).getlistofearthquakes();          listview = (listview)viewroot.findviewbyid(r.id.list_view);         earthquakeadapter noteadapter = new earthquakeadapter(getactivity(), earthquake);         listview.setadapter(noteadapter);         listview.setonitemclicklistener(new adapterview.onitemclicklistener() {             //final string mensaje = notas.get(position).getmag();             @override             public void onitemclick(adapterview<?> parent, view view, int position, long id) {                 intent intent = new intent(intent.action_view);                 intent.setdata(uri.parse(earthquake.get(0).getmapurl()));                 log.w("listview", "se despliega la siguente url " + earthquake.get(0).getmapurl());                 startactivity(intent);             }         });          return viewroot;     } } 

the adapter:

public class earthquakeadapter extends arrayadapter <earthquake> {      public earthquakeadapter(context context, arraylist<earthquake> notas) {         super(context, 0, notas);     }      private static final string location_separator = " of";     view view;      @nonnull     @override     public view getview(int position, view convertview, viewgroup parent) {         /*if(convertview == null){             convertview = layoutinflater.from(getcontext()).inflate(r.layout.list_item,parent,false);         */         if (convertview == null) {             convertview = layoutinflater.from(getcontext()).inflate(r.layout.list_item,parent,false);             log.w("applist", "converview es null");         }          earthquake note = getitem(position);          date dateobject = new date(note.gettimeinmilliseconds());         textview locationoffset = (textview)convertview.findviewbyid(r.id.listitem_tv_locationoffset);         textview place = (textview)convertview.findviewbyid(r.id.listitem_tv_place);         textview date = (textview)convertview.findviewbyid(r.id.lisitem_tv_date);         textview time = (textview)convertview.findviewbyid(r.id.lisitem_tv_time);         textview mag = (textview) convertview.findviewbyid(r.id.listitem_tv_mag);          gradientdrawable magnitudcicle = (gradientdrawable) mag.getbackground();         magnitudcicle.setcolor(getmagnitudcolor(note.getmag()));         string str_locationoffset, str_place;          if (note.getplace().contains(location_separator)) {             string [] locations = note.getplace().split(location_separator);             str_locationoffset = locations[0];             str_place = locations[1];         }         else {             str_place = note.getplace();             str_locationoffset = getcontext().getstring(r.string.near_the);         }          mag.settext( new decimalformat("0.0").format(note.getmag()));         date.settext(formatdate(dateobject));         place.settext(str_place);         time.settext(formattime(dateobject));         locationoffset.settext(str_locationoffset);          /* final string  mensaje = title.gettext().tostring();         convertview.setonclicklistener(new view.onclicklistener() {             @override             public void onclick(view v) {                 toast.maketext(getcontext(),mensaje,toast.length_short).show();             }         });*/          return convertview;     } } 

you should use recycler view better performance.

from: https://developer.android.com/training/material/lists-cards.html


Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -