android - ProgressDialog doesn't appear when calling a thread inside AsyncTask -


I have an app that sends a file through a socket, while doing so I want to show progress in the progression. The app sends the file completely, but I am not able to display the dialog.

  increases public activity ProgressDialogActivity {Private ProgressDialog downloadDialog = null; Private string filePath; @ Override Protected Zero (InstanceStat saved from bundle) {// Todo auto-generated method stub super. Connet (Saved Instantstate); FilePath = getIntent (). GetExtras () GetString ("file path"); DownloadingOug = new progression (this); Work myTask = new work (); MyTask.execute (0); } Private Zero Show Message (Last String msg) {this.runOnUiThread (New Runnabal) {@Override Public Zero Run () {// TODO Auto generated method Stub Toast. Make text (getApplicationContext (), msg, 'enter code' toast.LENGTH_SHORT) .show ();}}); } Working in the Private Class Async Task & lt; Integer, integer, boolean & gt; Observer {Private thread t; Applies; @ OverEride Protected Zero on PreExecute () {// TODO Auto generated method stub super.onPreExecute (); DownloadDialog.setTitle ("send"); DownloadDialog.setMessage ("................"); DownloadDialog.setCancelable (wrong); DownloadDialog.setIndeterminate (wrong); // downloadDialog.setMax (100); DownloadDialog.setProgressStyle (ProgressDialog.STYLE_HORIZONTAL); DownloadDialog.show (); } @ Override protected boolean do inbackground (integer ... parameter) {SendFile Send = New SendFile (filePath); DownloadDialog.setMax (0); T = new thread (send); Send.registerObserver (this); // try {// thread Sleep (10000); // Grip (Interrupted E) ect // // TODO auto generated generated blocks // e.printStackTrace (); //} Start (); Back true; } @ Override Protected Zero Progress Update (Integer ... Value) {// TODO Auto generated method stub super.onProgressUpdate (value); Int counter = value [0] .intValue (); DownloadDialog.setProgress (counter); If (filePath! = Null) {downloadDialog.setMessage (filePath + "..."); }} @ Override Public Old Update (subject theme) {// Tudo Auto-Generated Math Stub If (Theme theme of SendFile) {SendFile e = (SendFile) topic; If (efexception ()! = Null) {t.interrupt (); ShowMessage (e.getException ()); } Else {if (! E.isStarted ()) {initializeProgressBar (e.getNumIter ()); } Else {refreshProgressBar (e.getNumIter ()); } If (E.Esent ()) {t.interrupt (); Show Message ("File Sent"); }}}} Public Zero initializeProgressBar (int max) {downloadDialog.setMax (max); } Public Zero Refresh Progressbar (Int.) {Published Progress (downloadDialog.getMax () - Zodiac); } @ Override postx (Boolean results) protected zeros {// Todo auto-generated method stub super.PostXAquate (results); If (downloadDialog! = Null) {downloadDialog.dismiss (); } End(); } @ Override protected void was canceled () {// Todo auto generated method stub super.onCancelled (); t.interrupt (); Show Message ("Task Cancel"); }}; }   

Send file is a class that contains a socket to send the file.

I think the problem is that I am calling the thread inside the Asynca Task because when I am making the thread sleep (10000), for that time I can see progression DL, but I do not know how to fix it.

In addition, when I run a debugger, I can see that the variable 'counter' is called every time I call it, but if I 'DownloadDialog.getProgress ()' , then always 0 is there.

You are creating an asyncTask, which infuses the INFafground () method in the background. In there, you do not do anything, but start a new thread ... now this thread works, but your Asinca task ends, because after starting another thread, there is nothing to do with it. So, your progress has been shown for some milliseconds, then your ASINNA Task ends and progress progresses again from the DLOgh.

Solution: Use either an asyncTask or use a thread.

Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -