How to write an integer value with log.d?

I am very new to Android and try a simple log to get a random background color. I have a code and it returns an integer from 1 to 256, or so I think. I need to register a value to check if everything is ok, but I'm not sure how to register it using Android. I used System.out.println("stuff") to register stuff in the past, but I believe that it is not the way you expect it to be in Android.

I have a class:

 public static int backgroundColorRandomize() 

which returns

 return randomRGB; 

and I'm trying to write it like this:

 Log.d(backgroundColorRandomize(), "value = " + randomRGB); 

but I need to convert the return value from backgroundColorRandomize to String so that it can be logged.

I tried java .toString , but I'm not sure that I am using it correctly .. Any help would be appreciated! Thanks!

+5
source share
4 answers
 Log.d("MYINT", "value: " + randomRGB); 
+10
source
 private static final String TAG = YourClass.class.getSimpleName(); ... android.util.Log.d(TAG, String.format("value = %d. random color = %d", randomRGB, backgroundColorRandomize())); 

Additional Information:

Journal Libraries: https://android-arsenal.com/tag/57

+3
source
 Log.d(backgroundColorRandomize() + "" /* <-- all you need. */, "value = " + randomRGB); 
+1
source

I prefer String.valueOf(value) .

 Log.d(String.valueOf(backgroundColorRandomize()), "value = " + randomRGB); 
+1
source

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


All Articles