android - OutofMemory Error in frame animation -
i have developed tour guide app. of classes have frame animation. 3 activities frame animation work well. if similar activity clicked, gives memory leak error. images loaded drawables folder. whole drawable folder contains 3.58 mb. can't understand why it's giving error. please this. in advance.
this logcat.
08-18 10:45:14.585: e/dalvikvm-heap(9523): out of memory on 6444816-byte allocation.
prio=5 tid=1 runnable 08-18 10:45:14.585: i/dalvikvm(9523): | group="main" scount=0 dscount=0 obj=0x41e46578 self=0x41cc9938 08-18 10:45:14.585: i/dalvikvm(9523): | systid=9523 nice=-16 sched=0/0 cgrp=apps handle=1074774012 08-18 10:45:14.585: i/dalvikvm(9523): | state=r schedstat=( 4068370710 523035518 4253 ) utm=308 stm=98 core=0
08-18 10:45:14.585: i/dalvikvm(9523): @ android.graphics.bitmapfactory.nativedecodeasset(native method) android.graphics.bitmapfactory.decodestream(bitmapfactory.java:596)
08-18 10:45:14.585: i/dalvikvm(9523): @ android.graphics.bitmapfactory.decoderesourcestream(bitmapfactory.java:444)
08-18 10:45:14.585: i/dalvikvm(9523): @ android.graphics.drawable.drawable.createfromresourcestream(drawable.java:832)
08-18 10:45:14.585: i/dalvikvm(9523): @ android.content.res.resources.loaddrawable(resources.java:2988) android.content.res.typedarray.getdrawable(typedarray.java:602) 08-18
android.widget.imageview.(imageview.java:131) 08-18
android.widget.imageview.(imageview.java:121) 08-18
java.lang.reflect.constructor.constructnative(native method) 08-18
java.lang.reflect.constructor.newinstance(constructor.java:417) 08-18
android.view.layoutinflater.createview(layoutinflater.java:600) 08-18 10:45:14.585: i/dalvikvm(9523): @ com.android.internal.policy.impl.phonelayoutinflater.oncreateview(phonelayoutinflater.java:56) 08-18 10:45:14.585: i/dalvikvm(9523): @ android.view.layoutinflater.oncreateview(layoutinflater.java:675)
android.view.layoutinflater.createviewfromtag(layoutinflater.java:700)
android.view.layoutinflater.rinflate(layoutinflater.java:761) 08-18
android.view.layoutinflater.rinflate(layoutinflater.java:769) 08-18
android.view.layoutinflater.inflate(layoutinflater.java:498) 08-18
android.view.layoutinflater.inflate(layoutinflater.java:398) 08-18
android.view.layoutinflater.inflate(layoutinflater.java:354) 08-18
com.android.internal.policy.impl.phonewindow.setcontentview(phonewindow.java:361) 08-18 10:45:14.585: i/dalvikvm(9523): at
d/androidruntime(9523): shutting down vm 08-18 10:45:14.590: w/dalvikvm(9523): threadid=1: thread exiting uncaught exception (group=0x41e45700) 08-18 10:45:14.595: e/androidruntime(9523): fatal exception: main 08-18 10:45:14.595: e/androidruntime(9523): java.lang.runtimeexception: unable start activity componentinfo{com.isuru.allaboutkataragama/com.isuru.allaboutkataragama.kabiliththa_dewalaya}: android.view.inflateexception: binary xml file line #53: error inflating class 08-18 10:45:14.595: e/androidruntime(9523):
com.android.internal.policy.impl.phonelayoutinflater.oncreateview(phonelayoutinflater.java:56)
android.view.layoutinflater.oncreateview(layoutinflater.java:675) @ android.view.layoutinflater.createviewfromtag(layoutinflater.java:700) @ android.view.layoutinflater.rinflate(layoutinflater.java:761) 08-18 @ android.view.layoutinflater.rinflate(layoutinflater.java:769) 08-18 @ android.view.layoutinflater.inflate(layoutinflater.java:498) 08-18 @ android.view.layoutinflater.inflate(layoutinflater.java:398) 08-18 @ android.view.layoutinflater.inflate(layoutinflater.java:354) 08-18 @ com.android.internal.policy.impl.phonewindow.setcontentview(phonewindow.java:361) @ android.app.activity.setcontentview(activity.java:1956) 08-18 @ com.isuru.allaboutkataragama.kabiliththa_dewalaya.oncreate(kabiliththa_dewalaya.java:57) @ android.app.activity.performcreate(activity.java:5372) 08-18 @ android.app.instrumentation.callactivityoncreate(instrumentation.java:1104) @ android.app.activitythread.performlaunchactivity(activitythread.java:2257)
10:45:14.595: e/androidruntime(9523): caused by: java.lang.reflect.invocationtargetexception 08-18 10:45:14.595: e/androidruntime(9523): @ java.lang.reflect.constructor.constructnative(native method) 08-18 @ java.lang.reflect.constructor.newinstance(constructor.java:417) 08-18 @ android.view.layoutinflater.createview(layoutinflater.java:600) 08-18
e/androidruntime(9523): caused by: java.lang.outofmemoryerror 08-18
android.graphics.bitmapfactory.nativedecodeasset(native method) 08-18
android.graphics.bitmapfactory.decodestream(bitmapfactory.java:596)
android.graphics.bitmapfactory.decoderesourcestream(bitmapfactory.java:444)
android.graphics.drawable.drawable.createfromresourcestream(drawable.java:832)
android.content.res.resources.loaddrawable(resources.java:2988) 08-18
android.content.res.typedarray.getdrawable(typedarray.java:602) 08-18
android.widget.imageview.(imageview.java:131) 08-18
android.widget.imageview.(imageview.java:121)
this code
public class kabiliththa_dewalaya extends fragmentactivity implements locationlistener{ googlemap mgooglemap; arraylist<latlng> mmarkerpoints; double mlatitude=0; double mlongitude=0; imageview iv1,iv2,iv3; button contact_kebiliththa; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.kebiliththa); bitmapfactory.options options = new bitmapfactory.options(); options.injustdecodebounds = true; bitmapfactory.decoderesource(getresources(), r.id.imageview1_kabiliththa, options); bitmapfactory.decoderesource(getresources(), r.id.imageview1_kebimap, options); bitmapfactory.decoderesource(getresources(), r.id.imageview1_kabiliththa2, options); int imageheight = options.outheight; int imagewidth = options.outwidth; string imagetype = options.outmimetype; iv1.setimagebitmap(decodesampledbitmapfromresource(getresources(), r.id.imageview1_kabiliththa, 100, 100)); iv2.setimagebitmap(decodesampledbitmapfromresource(getresources(), r.id.imageview1_kebimap, 100, 100)); iv2.setimagebitmap(decodesampledbitmapfromresource(getresources(), r.id.imageview1_kabiliththa2, 100, 100)); contact_kebiliththa=(button) findviewbyid(r.id.button_contactkebiliththa); contact_kebiliththa.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { intent callintent = new intent(intent.action_call); callintent.setdata(uri.parse("tel:"+"0773539292")); startactivity(callintent); } }); // getting google play availability status int status = googleplayservicesutil.isgoogleplayservicesavailable(getbasecontext()); if(status!=connectionresult.success){ // google play services not available int requestcode = 10; dialog dialog = googleplayservicesutil.geterrordialog(status, this, requestcode); dialog.show(); }else { // google play services available // initializing mmarkerpoints = new arraylist<latlng>(); // getting reference supportmapfragment of activity_main supportmapfragment fm = (supportmapfragment)getsupportfragmentmanager().findfragmentbyid(r.id.map_kabiliththa); // getting map supportmapfragment mgooglemap = fm.getmap(); cameraposition cameraposition = new cameraposition.builder().target(new latlng( 6.418266, 81.324671)).zoom(8).build(); mgooglemap.animatecamera(cameraupdatefactory.newcameraposition(cameraposition)); double kabiliththalatitude =6.513917; double kabiliththalongitude =81.691930; final latlng kabiliththa=new latlng(kabiliththalatitude, kabiliththalongitude ); marker kabiliththa_marker=mgooglemap.addmarker(new markeroptions().title("kabiliththa dewalaya").icon(bitmapdescriptorfactory.defaultmarker(bitmapdescriptorfactory.hue_rose)).position(kabiliththa)); kabiliththa_marker.showinfowindow(); // enable mylocation button in map mgooglemap.setmylocationenabled(true); // getting locationmanager object system service location_service locationmanager locationmanager = (locationmanager) getsystemservice(location_service); // creating criteria object retrieve provider criteria criteria = new criteria(); // getting name of best provider string provider = locationmanager.getbestprovider(criteria, true); // getting current location gps location location = locationmanager.getlastknownlocation(provider); if(location!=null){ onlocationchanged(location); } locationmanager.requestlocationupdates(provider, 20000, 0, this); mgooglemap.setonmarkerclicklistener(new onmarkerclicklistener() { @override public boolean onmarkerclick(marker m) { mgooglemap.movecamera(cameraupdatefactory.newlatlngzoom(m.getposition(), 17)); m.remove(); toast.maketext(getapplicationcontext(), "tap again in location", toast.length_long).show(); // setting onclick event listener map mgooglemap.setonmapclicklistener(new onmapclicklistener() { @override public void onmapclick(latlng point) { // map contain destination location if(mmarkerpoints.size()>1){ fragmentmanager fm = getsupportfragmentmanager(); mmarkerpoints.clear(); mgooglemap.clear(); latlng startpoint = new latlng(mlatitude, mlongitude); drawmarker(startpoint); } drawmarker(point); // checks, whether start , end locations captured if(mmarkerpoints.size() >= 2){ latlng origin = mmarkerpoints.get(0); latlng dest = mmarkerpoints.get(1); // getting url google directions api string url = getdirectionsurl(origin, dest); downloadtask downloadtask = new downloadtask(); // start downloading json data google directions api downloadtask.execute(url); } } }); return false; } }); } } private string getdirectionsurl(latlng origin,latlng dest){ // origin of route string str_origin = "origin="+origin.latitude+","+origin.longitude; // destination of route string str_dest = "destination="+dest.latitude+","+dest.longitude; // sensor enabled string sensor = "sensor=false"; // building parameters web service string parameters = str_origin+"&"+str_dest+"&"+sensor; // output format string output = "json"; // building url web service string url = "https://maps.googleapis.com/maps/api/directions/"+output+"?"+parameters; return url; } /** method download json data url */ private string downloadurl(string strurl) throws ioexception{ string data = ""; inputstream istream = null; httpurlconnection urlconnection = null; try{ url url = new url(strurl); // creating http connection communicate url urlconnection = (httpurlconnection) url.openconnection(); // connecting url urlconnection.connect(); // reading data url istream = urlconnection.getinputstream(); bufferedreader br = new bufferedreader(new inputstreamreader(istream)); stringbuffer sb = new stringbuffer(); string line = ""; while( ( line = br.readline()) != null){ sb.append(line); } data = sb.tostring(); br.close(); }catch(exception e){ log.d("exception while downloading url", e.tostring()); }finally{ istream.close(); urlconnection.disconnect(); } return data; } /** class download data google directions url */ private class downloadtask extends asynctask<string, void, string>{ // downloading data in non-ui thread @override protected string doinbackground(string... url) { // storing data web service string data = ""; try{ // fetching data web service data = downloadurl(url[0]); }catch(exception e){ log.d("background task",e.tostring()); } return data; } // executes in ui thread, after execution of // doinbackground() @override protected void onpostexecute(string result) { super.onpostexecute(result); parsertask parsertask = new parsertask(); // invokes thread parsing json data parsertask.execute(result); } } /** class parse google directions in json format */ private class parsertask extends asynctask<string, integer, list<list<hashmap<string,string>>> >{ // parsing data in non-ui thread @override protected list<list<hashmap<string, string>>> doinbackground(string... jsondata) { jsonobject jobject; list<list<hashmap<string, string>>> routes = null; try{ jobject = new jsonobject(jsondata[0]); directionsjsonparser parser = new directionsjsonparser(); // starts parsing data routes = parser.parse(jobject); }catch(exception e){ e.printstacktrace(); } return routes; } // executes in ui thread, after parsing process @override protected void onpostexecute(list<list<hashmap<string, string>>> result) { arraylist<latlng> points = null; polylineoptions lineoptions = null; // traversing through routes for(int i=0;i<result.size();i++){ points = new arraylist<latlng>(); lineoptions = new polylineoptions(); // fetching i-th route list<hashmap<string, string>> path = result.get(i); // fetching points in i-th route for(int j=0;j<path.size();j++){ hashmap<string,string> point = path.get(j); double lat = double.parsedouble(point.get("lat")); double lng = double.parsedouble(point.get("lng")); latlng position = new latlng(lat, lng); points.add(position); } // adding points in route lineoptions lineoptions.addall(points); lineoptions.width(6); lineoptions.color(color.red); } // drawing polyline in google map i-th route mgooglemap.addpolyline(lineoptions); } } private void drawmarker(latlng point){ mmarkerpoints.add(point); // creating markeroptions markeroptions options = new markeroptions(); // setting position of marker options.position(point); /** * start location, color of marker green , * end location, color of marker red. */ if(mmarkerpoints.size()==1){ options.icon(bitmapdescriptorfactory.defaultmarker(bitmapdescriptorfactory.hue_green)); }else if(mmarkerpoints.size()==2){ options.icon(bitmapdescriptorfactory.defaultmarker(bitmapdescriptorfactory.hue_red)); } // add new marker google map android api v2 mgooglemap.addmarker(options); } @override public void onlocationchanged(location location) { // draw marker, if destination location not set if(mmarkerpoints.size() < 2){ mlatitude = location.getlatitude(); mlongitude = location.getlongitude(); latlng point = new latlng(mlatitude, mlongitude); mgooglemap.movecamera(cameraupdatefactory.newlatlng(point)); mgooglemap.animatecamera(cameraupdatefactory.zoomto(8)); drawmarker(point); } } public static int calculateinsamplesize( bitmapfactory.options options, int reqwidth, int reqheight) { // raw height , width of image final int height = options.outheight; final int width = options.outwidth; int insamplesize = 1; if (height > reqheight || width > reqwidth) { // calculate ratios of height , width requested height , width final int heightratio = math.round((float) height / (float) reqheight); final int widthratio = math.round((float) width / (float) reqwidth); // choose smallest ratio insamplesize value, guarantee // final image both dimensions larger or equal // requested height , width. insamplesize = heightratio < widthratio ? heightratio : widthratio; } return insamplesize; } public static bitmap decodesampledbitmapfromresource(resources res, int resid, int reqwidth, int reqheight) { // first decode injustdecodebounds=true check dimensions final bitmapfactory.options options = new bitmapfactory.options(); options.injustdecodebounds = true; bitmapfactory.decoderesource(res, resid, options); // calculate insamplesize options.insamplesize = calculateinsamplesize(options, reqwidth, reqheight); // decode bitmap insamplesize set options.injustdecodebounds = false; return bitmapfactory.decoderesource(res, resid, options); } @override public void onproviderdisabled(string provider) { // todo auto-generated method stub } @override public void onproviderenabled(string provider) { // todo auto-generated method stub } @override public void onstatuschanged(string provider, int status, bundle extras) { // todo auto-generated method stub } }
my xml layout
<?xml version="1.0" encoding="utf-8"?> <scrollview xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:id="@+id/rootview" > <linearlayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" > <textview android:id="@+id/textview_kebilithta" android:layout_width="wrap_content" android:layout_height="wrap_content" android:paddingbottom="10dp" android:paddingleft="65dp" android:paddingtop="10dp" android:text="@string/kebiliththa_header" android:textcolor="#000033" android:textsize="18sp" android:textstyle="bold" /> <imageview android:id="@+id/imageview1_kabiliththa" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1" android:adjustviewbounds="true" android:contentdescription="@string/imagevw" android:src="@drawable/kabi5" /> <textview android:id="@+id/textview_kebilithta1" android:layout_width="wrap_content" android:layout_height="122dp" android:paddingleft="5dp" android:paddingtop="10dp" android:text="@string/kebiliththa_description1" android:textsize="15sp" android:textstyle="bold" /> <textview android:id="@+id/textview_kebilithta2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:paddingleft="5dp" android:paddingtop="5dp" android:text="@string/kebiliththa_decrip2" android:textsize="15sp" android:textstyle="bold" /> <imageview android:id="@+id/imageview1_kabiliththa2" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1" android:adjustviewbounds="true" android:contentdescription="@string/imagevw" android:src="@drawable/kabi1" /> <textview android:id="@+id/textview_kebilithta4" android:layout_width="wrap_content" android:layout_height="99dp" android:paddingleft="5dp" android:paddingtop="5dp" android:text="@string/kebiliththa_descrip4" android:textsize="15sp" android:textstyle="bold" /> <imageview android:id="@+id/imageview1_kebimap" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1" android:adjustviewbounds="true" android:contentdescription="@string/imagevw" android:paddingtop="5dp" android:src="@drawable/kebiliththa_map" /> <textview android:id="@+id/textview_kebilithta41" android:layout_width="wrap_content" android:layout_height="wrap_content" android:paddingleft="5dp" android:paddingtop="12dp" android:text="@string/kebiliththa_troute_1_header" android:textsize="17sp" android:textstyle="bold" /> <textview android:id="@+id/textview_kebilithta42" android:layout_width="wrap_content" android:layout_height="wrap_content" android:paddingleft="5dp" android:paddingtop="2dp" android:text="@string/kebiliththa_route1" android:textsize="15sp" /> <textview android:id="@+id/textview_kebilithta43" android:layout_width="wrap_content" android:layout_height="wrap_content" android:paddingleft="5dp" android:paddingtop="13dp" android:text="@string/kebiliththa_troute_2_header" android:textsize="17sp" android:textstyle="bold" /> <textview android:id="@+id/textview_kebilithta44" android:layout_width="wrap_content" android:layout_height="wrap_content" android:paddingleft="5dp" android:paddingtop="2dp" android:text="@string/kebiliththa_route2" android:textsize="15sp" /> <textview android:id="@+id/textview_kebilithta45" android:layout_width="wrap_content" android:layout_height="wrap_content" android:paddingleft="5dp" android:paddingtop="13dp" android:text="@string/kebiliththa_troute_3_header" android:textsize="17sp" android:textstyle="bold" /> <textview android:id="@+id/textview_kebilithta46" android:layout_width="wrap_content" android:layout_height="wrap_content" android:paddingleft="5dp" android:paddingtop="2dp" android:text="@string/kebiliththa_route3" android:textsize="15sp" /> <linearlayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal" android:padding="12dp" > <imageview android:id="@+id/imageview_contactkabi" android:layout_width="54dp" android:layout_height="match_parent" android:contentdescription="@string/imagevw" android:paddingtop="6dp" android:src="@drawable/phone" /> <button android:id="@+id/button_contactkebiliththa" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="#000033" android:text="@string/kebiliththa_tours" android:textcolor="#ffffff" android:textstyle="bold" /> </linearlayout> <textview android:id="@+id/textview_dire" android:layout_width="wrap_content" android:layout_height="wrap_content" android:paddingleft="5dp" android:paddingtop="25dp" android:text="@string/getdirections1" android:textstyle="bold" /> <textview android:id="@+id/textview_markerdire" android:layout_width="wrap_content" android:layout_height="wrap_content" android:paddingbottom="10dp" android:paddingleft="5dp" android:text="@string/markertap" android:textcolor="#ff0000" /> <fragment android:id="@+id/map_kabiliththa" android:layout_width="match_parent" android:layout_height="470dp" android:layout_weight="0.50" class="com.google.android.gms.maps.supportmapfragment" /> </linearlayout> </scrollview>
animation list
<?xml version="1.0" encoding="utf-8"?> <animation-list xmlns:android="http://schemas.android.com/apk/res/android" > <item android:drawable="@drawable/kiri2" android:duration="10000"/> <item android:drawable="@drawable/kiri10" android:duration="8500"/> <item android:drawable="@drawable/kiriwehera8" android:duration="8500"/> <item android:drawable="@drawable/kiri9" android:duration="8500"/> <item android:drawable="@drawable/kiriwehera5" android:duration="8500"/> <item android:drawable="@drawable/kiriwehera6" android:duration="8500"/> <item android:drawable="@drawable/kiriwehera7" android:duration="9000"/> </animation-list>
Comments
Post a Comment