Android: How to print running text to the screen
I have a back-end process running (AsyncTask). I am interested in printing out System.out.println(); to the screen (something like the console in Eclipse) with information so the user is informed which calculations are running in the back.
What I wish to accomplish is seeing the text running on the screen - something like a dialog on top of the currenly-in-focus activity.
Does anyone got experience with this?
I don't think you can hijack System.out.print() and send it to the screen. But you can make a TextView and send the new lines of text to it as they are ready. Something like this should work.
String outputStr = ""; //Whenever you want to add a line to the TextView do it like this: outputStr += "\n" + [yourNewText]; mTxt.setText(outputStr);
If you were to add lots of lines in this manner would appear to the user as the same sort of situation as the eclipse console.
Since you can do this with a TextView you could then add that TextView to a custom dialog and show it to the user.
I believe you also need to be in the UI thread to update a textview. In an asynctask, you call onProgressUpdate, which is then executed in the UI thread. Otherwise, you can use view.post or you can use a Handler.