There is a progress in my activity when the activity begins, then I see the value from the second place and progress barr I update. Here is my code:
get last progress barge progress = = (progress bar) get ViewById (RIDprogress bar_detti); Last TextView Progress Text = (TextView) Find VViBID (RID Progress Text) ;; Final Imageview BTN Canal = (Image View) Find VVBID (R.Id.C.Cankel_Dieter); ProgressBar.setVisibility (View.VISIBLE); ProgressText.setVisibility (View.VISIBLE); BtnCancel.setVisibility (View.VISIBLE); Thread T = New Thread () {Public Activity (CTX) (Activity) CTX) .RonOnUtread (New Runnabal) (Public Zero Run) {Int Old Progress = 0; While (progress.get progress () <100) {int value = Downloader.progress.get (gameId + ""); If (value = old progression) {old progress = value; Progressing .Setprogress (value); Progress text .Settest (value + "%");}}}}); }}; T.start (); The value of progress I get from me int value = Downloader.progress.get (gameId) and it's right. But when I run this code, the activity is not responding and showing nothing (but no app crashes). Progress looks like thread to run intact and blocks the UI thread, so the activity is not showing the layout. What's wrong with my code? What is the correct way to update progress in this situation?
While you're running a (in the UI thread (you runOnUiThread ) progress.gate progress () <100> so that the UI thread will be blocked (and nothing is pictured) unless it is a loop finish. You can:
-
Put runOnUiThread inside the loop and, perhaps, runOnUiThread call Insert a sleep inside. However, this is not a favorite sort solution because you are just using a lot of CPUs for price changes. Sleeping approach is a bit ugly but it fixes the problem of the CPU. This will be something like this: threads t = new thread () {running public zero () {int oldprogress = 0; While (progress.gate progress () <100) {(activity) CTX. Aaron Eutthread (new runleball) (public zero run) {int value = Downloader.progress.get (gameId + ""); If (value! = Old progression) {old progress = value; Progress. First progress (value); Progress text .Setetext (value + "%");}}} thread. Sleep (500);}}); }
}
-
Update the progress bar through an event so that you can only (UI threads) In) Call update code Progress change is the preferred method.
Comments
Post a Comment