-3

I wrote a simple android app using android studio and I just want it to show the message :"what`s up". but when the app runs, it only shows a "Hello world" message in the middle.

Ps: I`m using my real phone, USB debugging enabled, running android 7.0.

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.util.Log;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        Log.i("Hello","What`s up ?");

    }
user13930404
  • 11
  • 1
  • 3
  • 2
    `Log.i` writes to the log, not to the screen. – Henry Jul 17 '20 at 12:08
  • write `What's up ?` in text view of `activity_main` . `Log.i` will only print message in console – Manohar Jul 17 '20 at 12:12
  • 1
    Does this answer your question? [Android Log.v(), Log.d(), Log.i(), Log.w(), Log.e() - When to use each one?](https://stackoverflow.com/questions/7959263/android-log-v-log-d-log-i-log-w-log-e-when-to-use-each-one) – Shoaib Kakal Jul 17 '20 at 12:15

3 Answers3

3

In your Logcat debug dropdown view you have multiple choices , so for you you have picked Log.i , which means in your logcat you have to select info

  • Here a screenshot of what i mean : enter image description here
  • Here are the different choices
Log.v -> Verbose
Log.d -> Debug
Log.i -> info
Log.w -> Warn
Log.a -> Assert
Log.e -> Error

Taki
  • 3,290
  • 1
  • 16
  • 41
0

Log.i: Use this to post useful information to the log. For example: that you have successfully connected to a server. Basically use it to report successes.

Log.d: Use this for debugging purposes. If you want to print out a bunch of messages so you can log the exact flow of your program, use this. If you want to keep a log of variable values, use this.

in your case add Log.i(TAG,"message"); or Log.d(TAG, "message");

Shoaib Kakal
  • 1,090
  • 2
  • 16
  • 32
0

Log.i("Hello","What`s up ?"); is used for showing information in the log but it will not visible in the app screen...

if u want to show a message in textview, do like below

1. define textview in activity_main.xml

<TextView
    android:id="@+id/message"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textSize="20dp"
    android:textStyle="bold"/>

2. Now in your MainActivity.java

public class MainActivity extends AppCompatActivity {
   TextView textview;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    
    textview = findViewById(R.id.message);
    textview.setText("Hello , What`s up ?");
}

That's all enjoy!