2017-08-16 5 views
2

J'utilise Fast-Android-Networking bibliothèque dans mon application Android pour télécharger le fichier à travers elle.Android app retards alors qu'un gros fichier est téléchargé

Pour les fichiers de moins de 15 megabytes, mon code fonctionne correctement. Mais, lorsque j'essaie de télécharger des fichiers de longueur supérieure à 20 megabytes, l'application et le périphérique cible sont en retard.

Lorsque j'ai testé avec mon ancien Lenovo A319 qui a 512 Mo de RAM, j'ai trouvé le problème et j'ai pensé qu'il devait s'agir d'un problème matériel.

Mais, après avoir testé l'application Lenovo A6000, Samsung J1 4G, Motorola Moto G Turbo et LYF eau 11, je suis arrivé à cette décision que l'application est en retard sur tous les appareils et seulement pendant le fichier est être téléchargé.

Je n'arrive pas à comprendre pourquoi ce problème se produit. J'ai également vérifié le logcat mais n'ai rien trouvé qui puisse m'aider à comprendre la racine du problème.

Une idée?

Certains de mon 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()); 
       } 
      }); 

Répondre

0

Basé sur this question, la bibliothèque a des problèmes critiques dans la zone d'utilisation de la mémoire.

+0

Pouvez-vous me donner quelques suggestions? (Sans l'ion de Koush) –

+0

@Exploit Bien sûr, vous devez absolument éviter d'utiliser exactement cette bibliothèque. –

+0

Bien qu'il y ait eu quelques problèmes, je suis passé à l'ion au moins. –