Reference: http://1002878825-qq-com.iteye.com/blog/1735356
The situation arises:
1. Use big picture, do not recycle in time.
4.0 after bitmap.option in the inpurgeable memory can be recycled, the previous version must be recycled
Resolution: 1.option Reduce Picture loading 2. Use soft references to recycle in time
The application of 2.listview Convertview and unused holder mechanism
Cause: The Contentview system is already cached
Resolution: 1.holder Determines whether Contentview is empty
2. Improve smoothness ListView Lazy Loading Data-----Reference: API Demo List 13 is not assigned when sliding
Public classList13extendsListactivityImplementsListview.onscrolllistener {PrivateTextView Mstatus; Private BooleanMbusy =false; /*** Won't bind views While the list is scrolling **/ Private classSlowadapterextendsBaseadapter {PrivateLayoutinflater Minflater; PublicSlowadapter (Context context) {Minflater=(Layoutinflater) Context.getsystemservice (Context.layout_inflater_service); } /*** The number of items in the list are determined by the number of speeches * in our array. * * @seeAndroid.widget.listadapter#getcount ()*/ Public intGetCount () {returnmstrings.length; } /*** Since The data comes from an array, just returning the index was * sufficent to get at the data. If we were using a more complex data * structure, we would return whatever object represents one row in the * list. * * @seeandroid.widget.listadapter#getitem (int)*/ PublicObject GetItem (intposition) { returnposition; } /*** Use the array index as a unique ID. * * @seeandroid.widget.listadapter#getitemid (int)*/ Public LongGetitemid (intposition) { returnposition; } /*** Make a view to hold each row. * * @seeandroid.widget.listadapter#getview (int, Android.view.View, * android.view.ViewGroup)*/ PublicView GetView (intposition, View Convertview, ViewGroup parent) {TextView text; if(Convertview = =NULL) {text= (TextView) minflater.inflate (Android. R.layout.simple_list_item_1, parent,false); } Else{text=(TextView) Convertview; } if(!mbusy) {Text.settext (mstrings[position]); //Null tag means the view has the correct dataText.settag (NULL); } Else{Text.settext ("Loading ..."); //non-null tag means the view still needs to load it ' s dataText.settag ( This); } returntext; }} @Override Public voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate); Setcontentview (R.LAYOUT.LIST_13); Mstatus=(TextView) Findviewbyid (r.id.status); Mstatus.settext ("Idle"); //Use a existing listadapter that would map an array//of strings to TextviewsSetlistadapter (NewSlowadapter ( This)); Getlistview (). Setonscrolllistener ( This); } Public voidOnscroll (Abslistview view,intFirstvisibleitem,intVisibleItemCount,intTotalitemcount) { } Public voidOnscrollstatechanged (Abslistview view,intscrollstate) { Switch(scrollstate) { CaseOnScrollListener.SCROLL_STATE_IDLE:mBusy=false; intFirst =view.getfirstvisibleposition (); intCount =View.getchildcount (); for(inti=0; i<count; i++) {TextView T=(TextView) View.getchildat (i); if(T.gettag ()! =NULL) {T.settext (Mstrings[first+i]); T.settag (NULL); }} mstatus.settext ("Idle"); Break; CaseOnScrollListener.SCROLL_STATE_TOUCH_SCROLL:mBusy=true; Mstatus.settext ("Touch Scroll"); Break; CaseOnScrollListener.SCROLL_STATE_FLING:mBusy=true; Mstatus.settext ("Fling"); Break; } }View Code
3. Single page, after switching n times on the screen
Resolution: 1. Remove the relevant settings from the XML and set the background map in the program (in the OnCreate () method):
2. Similar to the above method, directly load the XML configuration file into a View and put it into a container, and then directly invoke the This.setcontentview (view view) method, to avoid the repeated loading of XML
The Android:configchanges attribute was added in 3.Activity to notify the program to call Onconfigurationchanged () when the specified property (Configuration changes) changed. function
To solve a common method:
Use of 1.SoftReference and WeakReference
2. Compress picture Reference resolution bitmap Chapter
3. Modify the virtual machine parameters vmruntime.getruntime (). Settargetheaputilization (0.75);
4. Do not save references for the context long-term (end of life process off)
5. Use ApplicationContext as much as possible
6. The garbage collector does not guarantee the accurate recovery of memory, so that the primary life cycle and the timely release of unwanted objects when using the content you need. As far as possible at the end of the activity's life cycle, release the other objects we reference in OnDestroy, such as: Cursor.close ().
Android Memory Overflow