Pro Android 2: What does system.out.println do in Android?

To the best of my (current) understanding, Android does not have a console for sending messages so that System.out.println messages are lost. Instead, use Log.x (output in LogCat).

However, in the popular Pro Android 2 book, Listing 8-1 does just that:

    in = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));

    StringBuffer sb = new StringBuffer("");
    String line = "";
    String NL = System.getProperty("line.separator");
    while ((line = in.readLine()) != null) {
        sb.append(line + NL);
    }
    in.close();

    String page = sb.toString();
    System.out.println(page);

Does System.out.println really work on Android or is it just a typo?

If the first (i.e. not a typo), what does it really do and where should I expect a conclusion?

+3
source share
4 answers

From android docs :

By default, the Android system sends the stdout and stderr outputs (System.out and System.err) to / dev / null.

, System.out System.err.

+1

System.out.println , "" PrintStream. , , . Log.x.

, , . Android.

+3

System.out.println ( , Android). Android- ( , ). Android, Windows, Mac. :

logcat .

System.out.println( "-" );

Now, of course, it's best to stick with Log.x (). You should probably never rely on undocumented features, especially in the book. This feature may be here today and the tools will be updated next time.

+2
source

If you use Eclipse, System.out will not be displayed on the LogCat tab in the console. You can also try Log.i ("MyLog", "Post here ..."); also displayed on LogCat.

Enjoy it!

0
source

Source: https://habr.com/ru/post/1795899/


All Articles