I want to display the lifecycle events that occur like onCreate()
, onPause()
etc. on screen of the emulator as and when it occurs. How can I do that. Thanks.
There is a tutorial on this here http://www.tutorialspoint.com/android/android_acitivities.htm As @George Mulligan commented better to use logcat.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Log.d(msg, "The onCreate() event");
}
I tried showing a message in a textview and it works. I @overrided onPause() method in MainActiviy , and called the setContentView() method before setting Text to textview. I called setContentView both in @Override of onCreate() and in @Override of onPause(). Try the following code :
package com.example.secondtest;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.util.Log;
public class MainActivity extends AppCompatActivity {
TextView textView;
String Experiment = " Message in TextView after activity is stopped";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
protected void onPause() {
super.onPause();
setContentView(R.layout.activity_main);
textView = findViewById(R.id.textView);
textView.setText(Experiment);
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.