My app starts out by downloading a number of files from the internet. I'd like to display a line of text that says "Downloading files" while it is doing said downloading. Problem is, the view doesn't seem to update until after all the code has run, so the textview doesn't get displayed. I've tried running invalidate and postInvalidate on the mLayoutView object in between the code for the text view and the code to download the files, and that does not seem to have an effect. What am I missing?
Asked
Active
Viewed 47 times
0
-
1Are you downloading on a separate thread? – Merlevede Feb 18 '14 at 16:30
-
Same thread. This is only my first legitimate android app, I'm not too clear on how threads work. – Marcel Marino Feb 18 '14 at 17:04
1 Answers
1
You need to do the downloading on a separate thread. This is mandatory for several reasons: If your downloading code takes more that 5 seconds, Android will report your application as non responsive and it will crash, and also you won't be able to update the user interface
There are dozens of examples on how to do this, you can use AsyncTask, but also a Thread object, or a Runnable...
See this link for a great example:
Download a file with Android, and showing the progress in a ProgressDialog