I don't know what the problem is in here. I'm using the following code:
@Override
protected void onHandleIntent(Intent intent) {
Intent broadcastIntent = new Intent();
int count;
String full_url = URL + intent.getStringExtra(VIDEOS);
// TODO Auto-generated method stub
try {
URL url = new URL(full_url);
URLConnection conexion = url.openConnection();
conexion.connect();
int lenghtOfFile = conexion.getContentLength();
Log.d("ANDRO_ASYNC", "Lenght of file: " + lenghtOfFile);
InputStream input = new BufferedInputStream(url.openStream());
OutputStream output = new FileOutputStream(new File(root.getPath(),intent.getStringExtra(VIDEOS)));
byte data[] = new byte[1024];
long total = 0;
contentView.setTextViewText(R.id.status_text,"Downloading " + intent.getStringExtra(VIDEOS));
while ((count = input.read(data)) != -1) {
total += count;
notification.contentView.setProgressBar(R.id.status_progress, 100,(int)((total*100)/lenghtOfFile), false);
notificationManager.notify(1,notification);
Log.e("INTENT-FLAGS:","Percentage Downloaded: " + (int)((total*100)/lenghtOfFile) + " file: " + intent.getStringExtra(VIDEOS));
output.write(data, 0, count);
}
output.flush();
output.close();
input.close();
} catch (Exception e) {}
}
The buffer is small so that shouldn't be a problem. The first file gets downloaded which is around 140 KB the second file starts downloading and then ends up crashing the whole application and the whole phone session (which loggs off the phone). The other thing is im using a notification bar with a progress bar in it and when the files start downloading it just freezes the notification bar.
This is where it starts crashing:
10-05 17:05:00.101: ERROR/INTENT-FLAGS:(17944): Percentage Downloaded: 52 file: video_name.mp4
10-05 17:05:00.151: ERROR/INTENT-FLAGS:(17944): Percentage Downloaded: 53 file: video_name.mp4
10-05 17:05:00.201: ERROR/INTENT-FLAGS:(17944): Percentage Downloaded: 54 file: video_name.mp4
10-05 17:05:00.511: INFO/dalvikvm-heap(17074): Clamp target GC heap from 33.342MB to 32.000MB
10-05 17:05:00.511: DEBUG/dalvikvm(17074): GC_FOR_MALLOC freed 18480 objects / 688832 bytes in 301ms
10-05 17:05:00.561: ERROR/INTENT-FLAGS:(17944): Percentage Downloaded: 54 file: video_name.mp开发者_JAVA技巧4
10-05 17:05:00.611: ERROR/INTENT-FLAGS:(17944): Percentage Downloaded: 55 file: video_name.mp4
10-05 17:05:00.661: ERROR/INTENT-FLAGS:(17944): Percentage Downloaded: 56 file: video_name.mp4
10-05 17:05:00.991: INFO/dalvikvm-heap(17074): Clamp target GC heap from 33.788MB to 32.000MB
10-05 17:05:00.991: DEBUG/dalvikvm(17074): GC_FOR_MALLOC freed 6172 objects / 221432 bytes in 298ms
10-05 17:05:01.011: ERROR/INTENT-FLAGS:(17944): Percentage Downloaded: 56 file: st1_video_1250.mp4
10-05 17:05:01.341: INFO/dalvikvm-heap(17074): Clamp target GC heap from 33.925MB to 32.000MB
10-05 17:05:01.341: DEBUG/dalvikvm(17074): GC_FOR_MALLOC freed 1754 objects / 63256 bytes in 301ms
10-05 17:05:01.361: ERROR/INTENT-FLAGS:(17944): Percentage Downloaded: 57 file: video_name.mp4
10-05 17:05:01.671: INFO/dalvikvm-heap(17074): Clamp target GC heap from 33.937MB to 32.000MB
10-05 17:05:01.671: DEBUG/dalvikvm(17074): GC_FOR_MALLOC freed 1016 objects / 36536 bytes in 300ms
10-05 17:05:01.671: INFO/dalvikvm-heap(17074): Forcing collection of SoftReferences for 4604-byte allocation
10-05 17:05:01.951: INFO/dalvikvm-heap(17074): Clamp target GC heap from 33.865MB to 32.000MB
10-05 17:05:01.951: DEBUG/dalvikvm(17074): GC_FOR_MALLOC freed 1661 objects / 76536 bytes in 281ms
10-05 17:05:02.261: INFO/dalvikvm-heap(17074): Clamp target GC heap from 33.951MB to 32.000MB
10-05 17:05:02.261: DEBUG/dalvikvm(17074): GC_FOR_MALLOC freed 370 objects / 13552 bytes in 299ms
10-05 17:05:02.591: INFO/dalvikvm-heap(17074): Clamp target GC heap from 33.954MB to 32.000MB
10-05 17:05:02.591: DEBUG/dalvikvm(17074): GC_FOR_MALLOC freed 257 objects / 9328 bytes in 325ms
10-05 17:05:06.141: ERROR/dalvikvm-heap(17074): Out of memory on a 142-byte allocation.
10-05 17:05:06.141: INFO/dalvikvm(17074): "android.server.ServerThread" prio=5 tid=7 RUNNABLE
10-05 17:05:06.141: INFO/dalvikvm(17074): | group="main" sCount=0 dsCount=0 s=N obj=0x461ad7d8 self=0x255e48
10-05 17:05:06.141: INFO/dalvikvm(17074): | sysTid=17085 nice=-2 sched=0/0 cgrp=default handle=2449288
10-05 17:05:06.141: INFO/dalvikvm(17074): | schedstat=( 17625976523 14320526161 15952 )
10-05 17:05:06.141: INFO/dalvikvm(17074): at java.lang.AbstractStringBuilder.setLength(AbstractStringBuilder.java:~584)
10-05 17:05:06.141: INFO/dalvikvm(17074): at java.lang.ClassCache.findAllMethods(ClassCache.java:254)
10-05 17:05:06.141: INFO/dalvikvm(17074): at java.lang.ClassCache.getFullListOfMethods(ClassCache.java:223)
10-05 17:05:06.141: INFO/dalvikvm(17074): at java.lang.ClassCache.getAllPublicMethods(ClassCache.java:204)
10-05 17:05:06.141: INFO/dalvikvm(17074): at java.lang.Class.getMethod(Class.java:984)
10-05 17:05:06.141: INFO/dalvikvm(17074): at android.widget.RemoteViews$ReflectionAction.apply(RemoteViews.java:457)
10-05 17:05:06.141: INFO/dalvikvm(17074): at android.widget.RemoteViews.performApply(RemoteViews.java:955)
10-05 17:05:06.141: INFO/dalvikvm(17074): at android.widget.RemoteViews.reapply(RemoteViews.java:947)
10-05 17:05:06.141: INFO/dalvikvm(17074): at com.android.server.status.StatusBarService.updateNotificationView(StatusBarService.java:1145)
10-05 17:05:06.151: INFO/dalvikvm(17074): at com.android.server.status.StatusBarService.performAddUpdateIcon(StatusBarService.java:853)
10-05 17:05:06.151: INFO/dalvikvm(17074): at com.android.server.status.StatusBarService$H.handleMessage(StatusBarService.java:762)
10-05 17:05:06.151: INFO/dalvikvm(17074): at android.os.Handler.dispatchMessage(Handler.java:99)
10-05 17:05:06.151: INFO/dalvikvm(17074): at android.os.Looper.loop(Looper.java:144)
10-05 17:05:06.151: INFO/dalvikvm(17074): at com.android.server.ServerThread.run(SystemServer.java:600)
10-05 17:05:06.151: ERROR/dalvikvm(17074): Out of memory: Heap Size=30215KB, Allocated=29827KB, Bitmap Size=2584KB
精彩评论