我在Firebase中上传/下载文件时使用NotificationCompat.Builder。上传时很正常。但是,当下载系统时,直到下载完成并且log cat显示“应用程序可能在其主线程上做了太多工作”。使用Firebase存储下载文件时 - 应用程序可能在其主线程上做了太多工作
这是.addOnprogresslistner
的代码public void onProgress(FileDownloadTask.TaskSnapshot taskSnapshot) {
double fprogress = (100.0 * taskSnapshot.getBytesTransferred())/taskSnapshot.getTotalByteCount();
String progress = String.format("%.2f", fprogress);
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(getApplicationContext())
.setSmallIcon(android.R.drawable.stat_sys_download)
.setContentTitle("Downloading " + model.getName())
.setContentText(" " + progress + "% completed");
NotificationManager mNotificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(mId, mBuilder.build());
}
如果我删除NotificationCompat.Builder,它工作得很好。
任何解决方法?
'onProgress()'多久调用一次? – Jon
注意,不要忘记你也可以显示一个进度条https://developer.android.com/reference/android/support/v4/app/NotificationCompat.Builder.html#setProgress(int,%20int,%20boolean ) – Jon