Pregunta

I've seen this question asked a lot of times but no ways to do it. I have more different sections of code (that sometimes take more than 10 seconds) in main UI thread and want to show some progress to the user. I will NOT redo all code to try to move all various parts of codes in separate thread (is already a very complex app) while also freezing the main thread who needs the code executed before continuing, so don't suggest Thread/Handler/AsyncTask as they wont do.

One thing I have tried is to store the Canvas pointer from onDraw of a custom view I'm using, and draw in it something while running the long code, but the view refreshes only after code finished executing. Any way to force view redraw while executing code?

Another way to display a message/progress to the user will be to open a separate activity above that will not be full-screen so you can still see behind parts of the app, just like when you long-press Home button and Recent Apps Popup appears. How can i do this and how can i communicate between the two Activities?

Thanks in advance!

¿Fue útil?

Solución

Sorry but you can't do that.

Main Thread is only used to manipulate UI and not for long operations... The progress will freeze also as it is part of the UI Thread. Have a look on Google Guidelines and if you really want to do that, have a look on ProgressDialog.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top