RichieSambora
RichieSambora

Reputation: 25

Logs in Android Studio

I am a newbie of Android Studio. I have a problem with display the logs in my app. For example:

String timeStamp = new 
SimpleDateFormat("yyyyMMdd_HHmmss").format(Calendar.getInstance().getTime());
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_cycle);
    TextView textView = (TextView) findViewById(R.id.cykleoncreate);
    Log.d("[ " + timeStamp + "]", "[onCreate]");

I only want to display this log in my app. How can I do it?

Upvotes: 0

Views: 98

Answers (4)

Mohammad Arman
Mohammad Arman

Reputation: 508

Actually Log is not displaying in app , it will display in android studio . For displaying in app , we need to use Toast . your code is working fine you can check it in your android studio , as its shown in image Log in Android Studio We can display like this Log.d("onCreate", timeStamp); and search using TAG as onCreate.

Upvotes: 0

Tanveer Hasan
Tanveer Hasan

Reputation: 267

you can display the logs by Toast or set in textView

Toast.makeText(getApplicationContext(),timeStamp,Toast.LENGTH_SHORT).show();

or

textView.setText(timeStamp);

Upvotes: 1

RichieSambora
RichieSambora

Reputation: 25

Ok, it works well

textView.setText(timeStamp)  

But I don't know why it doesn't work, when I want to build my string:

textView.setText(timeStamp + "my string")  

Upvotes: 0

Swapnil Padaya
Swapnil Padaya

Reputation: 695

What you have done is write but you can get confused as in where's the log, Log has tag and message, Tags are usually Activity or fragment name so that its easier for one to locate from where did a particular error or message came from, and you can include anything in the message part of it.

we have different types of logs this can be found here

You will find a logcat button on bottom side left side of android studio from there you can select depending on which type you want to see? in your case it's debug

Upvotes: 0

Related Questions