android - showing images in an imagview in a loop -
i beginner please bear ,i have images in app on sd card , want show these images user 1 one duration,lets 1 image other 1 after 1 minute 1 after 1 minute this.i using aysnctask in convert image in bitmap , show it.i want show these images in continous loop until user exists app app should show images 1 one using following code it:-
for(i=1;i<z-1;i++) { xc=cont_id.get(1).tostring(); what=environment.getexternalstoragedirectory() + "/playerimages/" + xc + ".jpg"; play_duration=durat.get(1); //s1.execute(what,play_duration); new showtime().execute(what,play_duration); log.i("lenght",string.valueof(i));}
but when try execute in endless loop app crashes:-
for(i=1;i<z-1;i++) { xc=cont_id.get(1).tostring(); what=environment.getexternalstoragedirectory() + "/playerimages/" + xc + ".jpg"; play_duration=durat.get(1); //s1.execute(what,play_duration); new showtime().execute(what,play_duration); log.i("lenght",string.valueof(i)); if(i=z-1){ i=1; }}
my app crashed please suggest how can achieve it.. app not crashing not showing images logcat below
09-04 12:11:31.807: i/dalvikvm-heap(4358): clamp target gc heap 48.002mb 48.000mb 09-04 12:11:31.807: i/dalvikvm-heap(4358): grow heap (frag case) 48.000mb 80-byte allocation 09-04 12:11:32.182: i/dalvikvm-heap(4358): clamp target gc heap 50.002mb 48.000mb 09-04 12:11:32.182: d/dalvikvm(4358): gc_for_alloc freed 0k, 2% free 48571k/49159k, paused 372ms, total 372ms 09-04 12:11:32.182: i/dalvikvm-heap(4358): clamp target gc heap 48.002mb 48.000mb 09-04 12:11:32.182: i/dalvikvm-heap(4358): grow heap (frag case) 48.000mb 20-byte allocation 09-04 12:11:32.182: d/dalvikvm(4358): wait_for_concurrent_gc blocked 8390ms 09-04 12:11:32.557: i/dalvikvm-heap(4358): clamp target gc heap 50.002mb 48.000mb 09-04 12:11:32.557: d/dalvikvm(4358): gc_for_alloc freed 0k, 2% free 48571k/49159k, paused 380ms, total 380ms 09-04 12:11:32.557: i/dalvikvm-heap(4358): clamp target gc heap 48.002mb 48.000mb 09-04 12:11:32.557: i/dalvikvm-heap(4358): grow heap (frag case) 48.000mb 12-byte allocation 09-04 12:11:32.932: i/dalvikvm-heap(4358): clamp target gc heap 50.002mb 48.000mb 09-04 12:11:32.932: d/dalvikvm(4358): gc_concurrent freed 0k, 2% free 48571k/49159k, paused 2ms+3ms, total 371ms 09-04 12:11:32.932: d/dalvikvm(4358): wait_for_concurrent_gc blocked 369ms 09-04 12:11:33.292: i/dalvikvm-heap(4358): clamp target gc heap 50.002mb 48.000mb 09-04 12:11:33.292: d/dalvikvm(4358): gc_for_alloc freed 0k, 2% free 48571k/49159k, paused 362ms, total 362ms 09-04 12:11:33.292: i/dalvikvm-heap(4358): clamp target gc heap 48.002mb 48.000mb 09-04 12:11:33.292: i/dalvikvm-heap(4358): grow heap (frag case) 48.000mb 110-byte allocation 09-04 12:11:33.659: i/dalvikvm-heap(4358): clamp target gc heap 50.002mb 48.000mb 09-04 12:11:33.659: d/dalvikvm(4358): gc_for_alloc freed <1k, 2% free 48571k/49159k, paused 362ms, total 362ms 09-04 12:11:33.659: i/dalvikvm-heap(4358): clamp target gc heap 48.002mb 48.000mb 09-04 12:11:33.659: i/dalvikvm-heap(4358): grow heap (frag case) 48.000mb 24-byte allocation 09-04 12:11:34.026: i/dalvikvm-heap(4358): clamp target gc heap 50.002mb 48.000mb 09-04 12:11:34.026: d/dalvikvm(4358): gc_for_alloc freed <1k, 2% free 48571k/49159k, paused 368ms, total 368ms 09-04 12:11:34.026: i/dalvikvm-heap(4358): clamp target gc heap 48.002mb 48.000mb
and more this
when use loop it's going try whatever you're doing rapidly can. new showtime().execute() not blocking call, so, you're spawning off thousands , thousands of threads loading images , running out of memory.
so... assuming showtime asynctask want fire off next iteration of image display when task completes.
remove for() loop , use task scheduler shows image , waits , shows next one.
also, without seeing stack trace it's impossible know else might doing wrong, i'm taking granted you're loading bitmaps correctly (which may not be).
[edit] don't need async task. can in runnable postdelayed this:
public void oncreate(bundle b){ super.oncreate(b); //load layout //start image rotator new handler().post(shownextimage); } runnable shownextimage = new runnable(){ public void run(){ //draw next image here //now schedule next image new handler().postdelayed(shownextimage, 60000);// show next image in minute } }
Comments
Post a Comment