Application closed after some time in android -


i create image slide show type application, application used thread.

my application run after time application close.

i used following line of code release memory

system.gc(); runtime.getruntime().gc(); 

without above code same issue occur.

logcat:

03-13 12:45:09.250  /  dalvikvm: @@@ aborting: dalvik: heap memory corruption in internal_bulk_free addr=0x0 20713 20715 f03-13 12:45:09.250  /  libc fatal signal 11 (sigsegv) @ 0xdeadbaad (code=1), thread 20715 (gc)  

how solve problem?

please me.

my code is:

    public class myrunnable implements runnable {            private int delaytime = 0;           private vector<integer> my_playlistrecord_contentids =new vector<integer>();           private vector<integer> delayarray =new vector<integer>();            private vector<long> video_duration_list = new vector<long>();            private vector<integer> relative_ids = new vector<integer>();           private vector<relativelayout> layouts = new vector<relativelayout>();             private relativelayout customrelativelayout ;            private arraylist<string> _idarray;           private arraylist<string> _delayarray;            private int countplus = 0;            private int totalsize = 0;            private arraylist<playlist_record> playlist_records;             private finalplaylist finalplaylist;            private int fullscreenid =0;           private int screenid =0;           private int screenindex =0;            private long videoduration  = 0;             public myrunnable(arraylist<integer> _playlistrrecord_contentids, finalplaylist _finalplaylist, list<integer> delaylists, list<long> videodurationlist) {                finalplaylist = _finalplaylist;                  (integer id : _playlistrrecord_contentids) {                     //system.out.println("content id:"+id);                     my_playlistrecord_contentids.add(id);                 }                 (integer string : delaylists) {                     //system.out.println("delay time :"+string);                     delayarray.add(string);                 }                   (long videoduration : videodurationlist) {                     video_duration_list.add(videoduration);                 }               totalsize = delayarray.size();                iterator<integer> myveryowniterator = layoutmap.keyset().iterator();                 while(myveryowniterator.hasnext()) {                      int key=(integer) myveryowniterator.next();                      system.out.println("key:"+key);                          customrelativelayout = layoutmap.get(key);                         //system.out.println(" test customrelativelayout.getchildcount():"+customrelativelayout.getchildcount());                         layouts.add(customrelativelayout);                         relative_ids.add(key);                 }                   // find screen s                      list<container> containers = appdatabase.getallcotainer();                  (container container : containers) {                      if(container.getname().equals("s")){                             system.out.println("screen invisible index:");                             screenid = container.getcontainer_id();                             system.out.println(" index :"+screenid);                     }                     if(container.getname().equals("fs")){                         fullscreenid = container.getcontainer_id();                     }                 }                 // find index number of screen s container                  (int = 0 ; < relative_ids.size() ; i++) {                       if(screenid == relative_ids.get(i)){                          screenindex = i;                      }                  }                  /* (int = 0 ; < relative_ids.size() ; i++) {                   list<container> containers = appdatabase.getallcotainer();                  (container container : containers) {                       if(container.getname().equals("fs")){                             system.out.println("full screen invisible index:"+i);                             relativelayout relativelayout = layouts.get(i);                             //relativelayout.setvisibility(view.invisible);                             layouts.set(i, relativelayout);                          } else if(container.getname().equals("s")){                              system.out.println("screen invisible index:"+i);                              relativelayout relativelayout = layouts.get(i);                             relativelayout.setvisibility(view.invisible);                             layouts.set(i, relativelayout);                      }                  }              }*/          }          public void run() {                system.out.println("screen container id:"+screenid);                while(is_thread_run){                     if(countplus < totalsize){                      runnable irunnable= new runnable() {                           public void run() {                            //    system.out.println(" ** countplus:"+ countplus);                              // system.out.println(" ** totalsize:"+ totalsize);                             //  system.out.println("my_playlist_ids size:"+my_playlistrecord_contentids.size());                              // system.out.println("my_playlist_ids content:"+my_playlistrecord_contentids.get(countplus));                                 // playlist record                                list<playlist_record> playlist_records =  finalplaylist.getplayerarray();                               playlist_record playlist_record = playlist_records.get(countplus);                                //system.out.println("test run container id:"+playlist_record.getcontainer_id());                                 // ***********************************                               // check playlist_record validation                                 // ***********************************                                //system.out.println("playlist_recordid:"+my_playlist_ids.get(countplus));                                boolean isvalidcontent = false;                              isvalidcontent = appdatabase.isplaycontent(playlist_record.getplaylist_record_id());                              system.out.println("valid content:"+isvalidcontent);                               if(isvalidcontent){                               // hide layout, fetch container data , name equals fs , s relative layout                                 /*                                  (int = 0 ; < relative_ids.size() ; i++) {                                       list<container> containers = appdatabase.getallcotainer();                                      (container container : containers) {                                           if(container.getname().equals("fs")){                                                 system.out.println("full screen invisible index:"+i);                                                 relativelayout relativelayout = layouts.get(i);                                                 //relativelayout.setvisibility(view.invisible);                                                 layouts.set(i, relativelayout);                                              } else if(container.getname().equals("s")){                                                  system.out.println("screen invisible index:"+i);                                                  relativelayout relativelayout = layouts.get(i);                                                 relativelayout.setvisibility(view.invisible);                                                 layouts.set(i, relativelayout);                                          }                                      }                                  }*/                                      //system.out.println(" layouts:"+layouts.tostring());                                      (int = 0 ; < relative_ids.size() ; i++) {                                               if(relative_ids.get(i) == playlist_record.getcontainer_id()){                                                   //system.out.println("countainer id:"+relative_ids.get(i));                                                 // system.out.println("playlist_record.getcontainer_id():"+playlist_record.getcontainer_id());                                                   customrelativelayout = layouts.get(i);                                                 // system.out.println("customrelativelayout.getchildcount():"+customrelativelayout.getchildcount());                                                   // fetch container data , name equals fs , s relative layout visible                                                       if(screenid == playlist_record.getcontainer_id()){                                                          customrelativelayout.setvisibility(view.visible);                                                         //customrelativelayout.bringtofront();                                                     }else {                                                          relativelayout relativelayout = layouts.get(screenindex);                                                         relativelayout.setvisibility(view.invisible);                                                         layouts.set(screenindex, relativelayout);                                                     }                                                      //weather id match                                                          try {                                                             feature_defination feature_defination = appdatabase.getfeaturedefinition(relative_ids.get(i));                                                             if(relative_ids.get(i)==feature_defination.getcontainerid()){                                                                     system.out.println("match");                                                                     displayweatherdata(customrelativelayout,feature_defination.getcontainerid(),feature_defination);                                                             }                                                         } catch (exception e) {                                                             e.printstacktrace();                                                         }                                                    //system.out.println("transition effect:"+playlist_record.gettransition());                                                   //customrelativelayout.setvisibility(view.visible);                                                     setcontent(my_playlistrecord_contentids.get(countplus),customrelativelayout,getanimation(playlist_record.gettransition()),delayarray.get(countplus));                                                 }                                     } // end loop                                        system.out.println("my_playlist_ids:"+my_playlistrecord_contentids.get(countplus));                               // setcontent(my_playlist_ids.get(countplus),customrelativelayout);                               countplus =countplus+1;                                if(countplus >= totalsize){                                   countplus = 0;                               }                         }else{                               countplus =countplus+2;                               if(countplus >= totalsize){                                   countplus = 0;                               }                         }                           } //run method end                        };                       handler.post(irunnable);                    }else{                       countplus = 0;                   }                    //system.out.println("countplus before thread sleep:"+delayarray.get(countplus)+" countplus:"+countplus);                   //system.out.println("countplus sleep  video duration:"+videoduration);                   try {                              long sleeptime = delayarray.get(countplus);                          // system.out.println("sleep delay :"+sleeptime);                           if(sleeptime==0){                              long videotime = video_duration_list.get(countplus);                             if(videotime == 0 ){                                 sleeptime = 1000;                             }else{                                 sleeptime = videotime;                             }                           }else{                              sleeptime = (sleeptime * 1000)+1000;                            }                           /*                           if(videoduration!=0){                               system.out.println("sleep count plus"+countplus);                               countplus = countplus - 1;                               if(countplus<=0){                                   countplus = 0;                               }                               system.out.println("sleep countplus:"+countplus);                              sleeptime = videoduration;                           }*/                          // new displaycontentasync().execute(""+my_playlistrecord_contentids.get(countplus));                           system.out.println("sleep time:"+sleeptime);                          thread.sleep(sleeptime);                             //thread.sleep(2000);                     } catch (interruptedexception e) {                         // todo auto-generated catch block                         e.printstacktrace();                     }               } // run method end            }         }  /*    class displaycontentasync extends asynctask<string, string, string>{          @override         protected string doinbackground(string... params) {                         // video file length                      // check video               // *********************************************************                             string play_filename = "";                              //get record content table                                file confile = new file( util.root_path + "contents/"+play_filename);                                 //check image file                                 imagefilefilter imagefilefilter = new imagefilefilter(confile);                                 videofilefilter videofilefilter = new videofilefilter(confile);                                   content content = appdatabase.getcontenttemp(""+params[0]);                                  system.out.println("content id:"+content.getcontent_id());                                 system.out.println("content path:"+content.getcontent());                                  try {                                     string[] contentarray = null;                                     contentarray = content.getcontent().split("/");                                     play_filename = contentarray[contentarray.length-1];                                 } catch (exception e2) {                                     // todo auto-generated catch block                                     e2.printstacktrace();                                 }                                 string filepath = util.root_path + "contents/"+confile.getname();                                 if(videofilefilter.accept(confile)){                                       system.out.println("video file name:"+play_filename);                                     // video file play duration                                     mediametadataretriever retriever = new mediametadataretriever();                                     retriever.setdatasource(filepath);                                     string time = retriever.extractmetadata(mediametadataretriever.metadata_key_duration);                                     long time1 = long.parselong( time );;                                     system.out.println("video time: "+time1);                                 }                        // setcontent(my_playlist_ids.get(countplus),customrelativelayout);                 return null;         }          @override         protected void onpostexecute(string result) {             super.onpostexecute(result);         }      } */     @suppresslint("newapi")     public void setcontent(int content_id,relativelayout _customrelativelayout,list<animation> _animations, int _videotimeduration){         //system.gc();         //runtime.getruntime().gc();          list<animation> animations = _animations;          relativelayout customrelativelayout = _customrelativelayout;         imageview imageview = null;         videoview videoview = null;         webview webview = null;          int height = customrelativelayout.getheight();         int width = customrelativelayout.getwidth();         final int videotimeduration = _videotimeduration;          animation anim1 = null ;         animation anim2 = null;         animation anim3 = null;          for(int p=0; p<animations.size();p++){              if(p==0){                 anim1 = animations.get(p);                 system.out.println("animation 1");             }else if(p==1){                 anim2 = animations.get(p);                 system.out.println("animation 2");             }else if(p==2){                 anim3 = animations.get(p);                 system.out.println("animation 3");             }         }           //system.out.println("layout height :"+height);         //system.out.println("layout height :"+height);         // find child relative layout         int childcount = customrelativelayout.getchildcount();         //system.out.println("get child:"+childcount);         (int i=0; < childcount; i++){               view view = customrelativelayout.getchildat(i);               if (view instanceof imageview) {                     imageview = (imageview) view;                     // want imageview                 }else if (view instanceof videoview) {                     videoview = (videoview) view;                     // want imageview                 }else if (view instanceof webview) {                     webview = (webview) view;                     // want imageview                 }          }         string play_filename = "";          //get record content table              //system.out.println("content id match with:"+content_id);             content content = appdatabase.getcontent(""+content_id);              //system.out.println("content id:"+content.getcontent_id());             //system.out.println("content path:"+content.getcontent());              try {                 string[] contentarray = null;                 contentarray = content.getcontent().split("/");                 play_filename = contentarray[contentarray.length-1];             } catch (exception e2) {                 // todo auto-generated catch block                 e2.printstacktrace();             }              system.out.println("play file name:"+play_filename);            //toast.maketext(display.this, play_filename, 1000).show();           //system.out.println("play file duration:"+duration);         /*            // set animation              if(animations!=null && animations.size()>=2){                 system.out.println("animation 2 available ");                    final animation endanim = anim2;                 final relativelayout relativelayout = customrelativelayout;                  customrelativelayout.startanimation(anim1);                 anim1.setanimationlistener(new animationlistener() {                      @override                     public void onanimationstart(animation arg0) {                      }                      @override                     public void onanimationrepeat(animation arg0) {                      }                      @override                     public void onanimationend(animation arg0) {                         relativelayout.startanimation(endanim);                      }                 });             }else if(animations!=null && animations.size()==1){                 system.out.println("animation 1 available");                 imageview.setanimation(anim1);             }else {                 system.out.println("animation not available");             }         */                 file confile = new file( util.root_path + "contents/"+play_filename);                 //check image file                 imagefilefilter imagefilefilter = new imagefilefilter(confile);                 videofilefilter videofilefilter = new videofilefilter(confile);                 webfilefilter webfilefilter = new webfilefilter(confile);                  string filepath = util.root_path + "contents/"+confile.getname();                 //check file size 0 or not                 file chkfile = new file(filepath);                 if(chkfile.length()>0){                     if(imagefilefilter.accept(confile)){                         //system.out.println("filter image file name:"+confile.getname());                         videoview.setvisibility(view.gone);                         imageview.setvisibility(view.visible);                         webview.setvisibility(view.gone);                            // check android os                          int currentapiversion = android.os.build.version.sdk_int;                         if (currentapiversion >= android.os.build.version_codes.ice_cream_sandwich){                             //system.out.println("jelly bean");                             drawable drawable = drawable.createfrompath(filepath);                             imageview.setbackground(drawable);                              //imageview.setimagebitmap(decodefile(chkfile, 1000, 1000));                              // set animation                              if(animations!=null && animations.size()>=2){                                 system.out.println("animation 2 available ");                                    final animation endanim = anim2;                                 final imageview finalimage = imageview;                                  imageview.startanimation(anim1);                                 anim1.setanimationlistener(new animationlistener() {                                      @override                                     public void onanimationstart(animation arg0) {                                      }                                      @override                                     public void onanimationrepeat(animation arg0) {                                      } 

you can try this.add below line in android manifest file :

android:largeheap="true" 

thanks.


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

android - Keyboard hides my half of edit-text and button below it even in scroll view -

css - Make div keyboard-scrollable in jQuery Mobile? -