Java
javaTutorial
Detailed explanation of Android programming based on Log demonstration of an activity life cycle instanceThe example in this article describes Android programming that demonstrates an activity life cycle based on Log. Share it with everyone for your reference, the details are as follows:
Use Android Log to demonstrate the life cycle of an activity
Code:
//DemoActivity.java
package uni.activity;
/*
@author octobershiner
2011 7 22
SE.HIT
*/
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
public class ActivityDemoActivity extends Activity {
/** Called when the activity is first created. */
private static final String TAG = "demo";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Log.d("demo", "this is a test string ");
}
protected void onStart(){
super.onStart();
Log.i(TAG, "The activity state---->onStart");
}
protected void onRestart(){
super.onRestart();
Log.i(TAG, "The activity state---->onReatart");
}
protected void onResume(){
super.onResume();
Log.i(TAG, "The activity state---->onResume");
}
protected void onPause(){
super.onPause();
Log.i(TAG, "The activity state---->onPause");
}
protected void onStop(){
super.onStop();
Log.i(TAG, "The activity state---->onStop");
}
protected void onDestroy(){
super.onDestroy();
Log.i(TAG, "The activity state---->onDestroy");
}
}This is the result of the demonstration
Use LOG to display the life cycle of the activity
The annotation indicates that the operations performed in the middle are convenient observation data. You can click on the right side of the LOGCAT window (if not, you can call it up in the show view in the window menu). Click the plus sign to create a filter. In my example, the filter is demo
//开始运行demo 07-22 11:18:19.311: INFO/demo(281): The activity state---->onStart 07-22 11:18:19.311: INFO/demo(281): The activity state---->onResume //按下了back键 返回 activity从stack中弹出 07-22 11:18:34.821: INFO/demo(281): The activity state---->onPause 07-22 11:18:35.090: INFO/demo(281): The activity state---->onStop 07-22 11:18:35.090: INFO/demo(281): The activity state---->onDestroy //再次启动demo 07-22 11:18:45.550: INFO/demo(281): The activity state---->onStart 07-22 11:18:45.550: INFO/demo(281): The activity state---->onResume //按下了HOME键 当前TASK 处于后台转态,系统保存状态 07-22 11:18:53.750: INFO/demo(281): The activity state---->onPause 07-22 11:18:54.820: INFO/demo(281): The activity state---->onStop //再次启动demo 回复原来的TASK activity在栈顶 07-22 11:19:03.550: INFO/demo(281): The activity state---->onReatart 07-22 11:19:03.550: INFO/demo(281): The activity state---->onStart 07-22 11:19:03.550: INFO/demo(281): The activity state---->onResume
In addition, how to filter and view the log:
Example
Log.i("yourDemo","this is my log");Friends who do not have a LOGCAT window can Call up the window in the show view in the window menu

The five circles can filter five different logs
Pay attention to the green plus sign on the right. Click to customize your own filter, just name it whatever you want.
Select the filter rule you want to create in the Log Tag column. For example, if you want to filter out the logs with the tag "yourDemo", You can enter yourDemo in it
I hope this article will be helpful to everyone in Android programming.
For more detailed explanations of Android programming based on Log demonstration of an activity life cycle instance, please pay attention to the PHP Chinese website!
How does IntelliJ IDEA identify the port number of a Spring Boot project without outputting a log?Apr 19, 2025 pm 11:45 PMStart Spring using IntelliJIDEAUltimate version...
How to elegantly obtain entity class variable names to build database query conditions?Apr 19, 2025 pm 11:42 PMWhen using MyBatis-Plus or other ORM frameworks for database operations, it is often necessary to construct query conditions based on the attribute name of the entity class. If you manually every time...
Java BigDecimal operation: How to accurately control the accuracy of calculation results?Apr 19, 2025 pm 11:39 PMJava...
How to use the Redis cache solution to efficiently realize the requirements of product ranking list?Apr 19, 2025 pm 11:36 PMHow does the Redis caching solution realize the requirements of product ranking list? During the development process, we often need to deal with the requirements of rankings, such as displaying a...
How to safely convert Java objects to arrays?Apr 19, 2025 pm 11:33 PMConversion of Java Objects and Arrays: In-depth discussion of the risks and correct methods of cast type conversion Many Java beginners will encounter the conversion of an object into an array...
How do I convert names to numbers to implement sorting and maintain consistency in groups?Apr 19, 2025 pm 11:30 PMSolutions to convert names to numbers to implement sorting In many application scenarios, users may need to sort in groups, especially in one...
E-commerce platform SKU and SPU database design: How to take into account both user-defined attributes and attributeless products?Apr 19, 2025 pm 11:27 PMDetailed explanation of the design of SKU and SPU tables on e-commerce platforms This article will discuss the database design issues of SKU and SPU in e-commerce platforms, especially how to deal with user-defined sales...
How to set the default run configuration list of SpringBoot projects in Idea for team members to share?Apr 19, 2025 pm 11:24 PMHow to set the SpringBoot project default run configuration list in Idea using IntelliJ...


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Zend Studio 13.0.1
Powerful PHP integrated development environment

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Dreamweaver CS6
Visual web development tools





