0

When I program in JavaScript, I use alert() for easy debugging. In Delphi, I change the Caption of the Form. In Android, I'm trying to do something like:

textView.setText("0");
SystemClock.sleep(2000);
// some programming...
textView.setText("1");
SystemClock.sleep(2000);

but I can't see the "0", as it only refreshes the screen in the end of the function (that's inside a button's onClick). All I see is the "1" after I press the button. In the real program (with numbers from 0 to 9), I see no number at all, it just closes the program. I've read somewhere that the Invalidate function is called automatically by the setText (so no need to call it).

I tried Toast (instead of setText), it didn't work. And I want something simpler/faster than creating popups/dialogs. Also, I don't want to use adb, Log or LogCat, since I'm on Linux and having problems connecting the phone to the PC (I could have lost the cable, for instance). Any help, please?

1 Answer 1

1

The problem is that you're blocking the UI thread, and updates to your UI don't get processed. Don't sleep() in the UI thread.

The app gets automatically killed as "not responding" if your block the UI thread for 5 seconds.

For debugging, consider android.util.Log with adb connection, even if you didn't want to connect your device. You can connect adb also over TCP/IP without a cable.

Sign up to request clarification or add additional context in comments.

7 Comments

Thank you. I tried without the sleep before, and it didn't work either. And as I can see in developer.android.com/reference/android/util/Log.html, all functions are for creating Logs, how can I use this without connecting the device?
It would be much easier if I could just write something on the screen in Android itself, but ok, I'll try TCP/IP. Thanks a lot!
Toast would be the mechanism for on-screen temporary notifications. You cannot block the UI thread with them either. Logging is more reliable in the long run.
TCP/IP needs root, root has its good and bad, etc. Just to be sure: are you telling me it's IMPOSSIBLE to do a EASY debugging like I ask?
Logging is easy. Connecting ADB over USB is easy.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.