0

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?

a_local_nobody
  • 7,947
  • 5
  • 29
  • 51
  • You have coded it right, you just have to select "Logcat" from the bottom nav menu inside android studio, and select debug in the third drop-down menu from left in the pop up window. After running the app you will be able to see your log. If not, type "onCreate" in the search bar. – Fahad-Android Nov 05 '21 at 11:00

4 Answers4

1

you can display the logs by Toast or set in textView

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

or

textView.setText(timeStamp);
hata
  • 11,633
  • 6
  • 46
  • 69
Tanveer Hasan
  • 247
  • 2
  • 9
  • `timeStamp` is already a string, according to OP's code, so adding `""+timeStamp` is just messy and doesn't do anything – a_local_nobody Nov 05 '21 at 11:01
  • textView.setText(timeStamp) it works well, thank you. But if I wanted add a string to my timeStamp? textView.setText(timeStamp + "myString")? It doesn't work. – RichieSambora Nov 05 '21 at 11:35
0

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

Swapnil Padaya
  • 687
  • 5
  • 14
0

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")  
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Nov 05 '21 at 14:59
0

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.

Mohammad Arman
  • 508
  • 4
  • 13