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?

Thanks, D.

Answers


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.


Need Your Help

Python Subprocess.Popen from a thread

python multithreading subprocess rsync

I'm trying to launch an 'rsync' using subprocess module and Popen inside of a thread. After I call the rsync I need to read the output as well. I'm using the communicate method to read the output. ...

how to setup svn repository on Xcode 6?

ios svn xcode6

I just started to work with Xcode and trying to add a Subversion repository on remote windows server. When I enter the location path of Subversion repository, it shows following error message: