Issue
I'm using Fast-Android-Networking library in my android app to download file through it.
For files less than 15 megabytes
, my code works fine. But, when I try downloading files with more than 20 megabytes
of length, the application and also the target device lags.
When I tested with my old Lenovo A319 which has 512mb of RAM, I've found the problem and thought it must be an hardware problem.
But, after testing the application in Lenovo A6000, Samsung J1 4G, Motorola Moto G Turbo and LYF Water 11, I came to this decision that the application is lagging on all devices and only while the file is being downloaded.
I can't understand why this problem is happening. I've also checked the logcat but found nothing that can help me to understand the root of the problem.
Any idea?
Some of my code :
AndroidNetworking.download(link, Environment.getExternalStorageDirectory().getPath() + "/ABCD", title + "."+fileExtension)
.setTag("Download: " + title)
.setPriority(Priority.HIGH)
.build()
.setDownloadProgressListener(new DownloadProgressListener() {
@Override
public void onProgress(long bytesDownloaded, long totalBytes) {
int percentage = (int) Math.floor(bytesDownloaded * 100.0 / totalBytes);
System.out.println(percentage);
//I'm using Notification to report progress to user.
mBuilder.setProgress(100, percentage, false);
mNotifyManager.notify(id, mBuilder.build());
}
})
.startDownload(new DownloadListener() {
@Override
public void onDownloadComplete() {
if (file.length() < 500000) {
Snackbar.make(mView, "Download Error", Snackbar.LENGTH_LONG).show();
mBuilder.setContentText("Download Error!").setProgress(0, 0, false);
mNotifyManager.notify(id, mBuilder.build());
} else {
Uri path = Uri.fromFile(file);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.setDataAndType(path, getMimeType(path.toString()));
PendingIntent notifyPIntent = PendingIntent.getActivity(mContext.getApplicationContext(), 0, intent, 0);
mBuilder.setContentIntent(notifyPIntent);
mBuilder.setContentTitle("Download Completed")
.setContentText("Download complete! - Click To Play")
.setProgress(0, 0, false);
mNotifyManager.notify(id, mBuilder.build());
Snackbar.make(mView, "Download Completed : " + title + "."+fileExtension, Snackbar.LENGTH_LONG).setAction("Play Now", new View.OnClickListener() {
@Override
public void onClick(View v) {
Uri path = Uri.fromFile(file);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.setDataAndType(path, getMimeType(path.toString()));
mContext.startActivity(intent);
}
}).show();
}
}
@Override
public void onError(ANError error) {
Snackbar.make(mView, "Download Error : " + error.toString(), Snackbar.LENGTH_LONG).show();
error.printStackTrace();
mBuilder.setContentText("Download Error!");
mBuilder.setProgress(0, 0, false);
mNotifyManager.notify(id, mBuilder.build());
}
});
Solution
Based on this issue, library has critical problems in memory usage area.
Answered By - Stas Lelyuk
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.