What is the meaning of Log.i()

You’ll be needing something called “logcat” a lot whenever you’re developing for Android.

Whenever you open Android Studio, you’ll see something like this:

These are different levels of “problem”/information that you’re logging, so that you can understand which code is being run, and if it is working as expected.

Now, you said why does Log.i("key","value") exist, and why you were told to do that.

It simply means, you logged an event, which was just for purposes of logging normal “information”, as “i” in Log.i stands for Info.

There are different levels of severity of an event that you’re trying to log.

So, for example, if you want to log an event that causes your app to crash, you’ll log it with Log.e("key","value");, where “e” signifies and error.

There are different levels of severity which you can find here.

Now, why do you need these different levels?

Simply, because you need to filter those depending on what you’re trying to log. So if for example your application crashes, you’ll be able to see it in “Error” section in the dropdown that is marked in the picture above. So you can say it’s for organizing the data that you/the system is logging.

The first parameter in Logs is the key, so you can search for particular logs belonging to one category quickly through the search bar in logcat, the second parameter is for adding more information.

Example:

void multiply(){
   int a = 3*4;
   Log.i("multiplication","Value of a is:"+String.valueOf(a));
}

In your example, you were told to log stuff because your teacher was trying to teach you lifecycle of an activity, meaning, in which order the functions of activity are executed.

Leave a Comment