惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
W
WeLiveSecurity
O
OpenAI News
N
News and Events Feed by Topic
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Webroot Blog
Webroot Blog
Google Online Security Blog
Google Online Security Blog
云风的 BLOG
云风的 BLOG
N
News | PayPal Newsroom
H
Hacker News: Front Page
博客园_首页
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
The Last Watchdog
The Last Watchdog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
H
Heimdal Security Blog
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
S
Schneier on Security
宝玉的分享
宝玉的分享
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Y
Y Combinator Blog
Cyberwarzone
Cyberwarzone
Microsoft Security Blog
Microsoft Security Blog
C
CXSECURITY Database RSS Feed - CXSecurity.com
GbyAI
GbyAI
Cloudbric
Cloudbric
TaoSecurity Blog
TaoSecurity Blog
人人都是产品经理
人人都是产品经理
P
Palo Alto Networks Blog
M
MIT News - Artificial intelligence
G
GRAHAM CLULEY
C
Check Point Blog
Apple Machine Learning Research
Apple Machine Learning Research
Last Week in AI
Last Week in AI
T
Troy Hunt's Blog
L
Lohrmann on Cybersecurity
www.infosecurity-magazine.com
www.infosecurity-magazine.com
P
Proofpoint News Feed
Blog — PlanetScale
Blog — PlanetScale
量子位
博客园 - 聂微东
S
Securelist
博客园 - 三生石上(FineUI控件)
F
Full Disclosure
G
Google Developers Blog
L
LINUX DO - 热门话题
P
Proofpoint News Feed
AI
AI
PCI Perspectives
PCI Perspectives

WMI

How to Activate MySQL for Multiple Devices - WMI ESLint Flat Config for JS, TS, React, and Prettier - WMI Yarn NPM Registry Configuration - WMI Yarn Guides - WMI Set Up ADB Wireless Debugging on Android: A Full Guide - WMI How to Fill Tax Information on Google Adsense - WMI Migrate ESLint v9 for prettier typescript javascript - WMI PySide6 button click open new window - WMI PySide6 autocomplete input text - WMI Mobile Legends To The Stars Event Clue - WMI [PHP] generate random proxy IP:PORT from CIDR - WMI [PHP] generate big text file for testing purpose - WMI List of Chrome Driver command line arguments - WMI Happy eid mubarak - WMI Install markdown engine on vite ESM typescript - WMI OkHttp cookie handling on android (webview supported) - WMI Turn git log history into markdown - WMI enable automatic memory heap resizing of android studio - WMI is defining screen density can reduce build time ? - WMI
Android Activity lifecycle - WMI
Dimas Lanjaka · 2024-03-25 · via WMI

is onStart or onCreate first will be triggered in android activity?

In the Android Activity lifecycle, onCreate() is triggered before onStart(). Here's a brief overview of the sequence of method calls when an Activity is created:

  1. onCreate(): This method is called when the activity is first created. It is where you typically perform one-time initialization such as setting up the user interface, binding data to lists, or initializing variables.

  2. onStart(): This method is called after onCreate() (if the activity is being started for the first time) or when the activity is being brought back to the foreground from a stopped state. It is where the activity becomes visible to the user, but it may not yet be in the foreground and interactive.

So, onCreate() is always triggered before onStart() in the Android Activity lifecycle.

Basic ifecycle of android activity

Here's the basic lifecycle of an Android Activity:

  1. onCreate(): This method is called when the activity is first created. Here, you typically perform initialization of the activity, such as setting up the user interface with setContentView() and initializing variables.

  2. onStart(): This method is called when the activity becomes visible to the user. It prepares the activity to enter the foreground and become interactive.

  3. onResume(): This method is called when the activity is about to start interacting with the user. It signals that the activity is now in the foreground and ready to receive user input.

  4. onPause(): This method is called when the activity is going into the background but is still partially visible to the user. It indicates that the activity is no longer in the foreground and may be paused or stopped.

  5. onStop(): This method is called when the activity is no longer visible to the user. It typically happens when the activity is being covered by another activity or when the user navigates away from it.

  6. onDestroy(): This method is called when the activity is being destroyed. It is the final callback that the activity receives before it is removed from memory. Here, you release any resources or unregister any listeners that were associated with the activity.

Additionally, there are two other methods that are important for handling configuration changes:

  • onRestart(): This method is called when the activity is being restarted after being stopped. It is called after onStop() and before onStart().

  • onSaveInstanceState() and onRestoreInstanceState(): These methods are called when the activity is being temporarily destroyed and recreated due to a configuration change (such as screen rotation). They allow you to save and restore the state of your activity's UI and data.

Understanding these lifecycle methods is crucial for properly managing the state and behavior of your Android activities.

Graph of android lifecycle

here's a graphical representation of the Android Activity lifecycle:

       +-------------------+
       |                   |
       |      onCreate()   |
       |                   |
       +---------+---------+
                 |
                 v
       +-------------------+
       |                   |
       |      onStart()    |
       |                   |
       +---------+---------+
                 |
                 v
       +-------------------+
       |                   |
       |      onResume()   |
       |                   |
       +---------+---------+
                 |
                 v
+-------------------------+
|                         |
| User interacts with the |
|       Activity          |
|                         |
+------------+------------+
             |
             v
       +-------------------+
       |                   |
       |      onPause()    |
       |                   |
       +---------+---------+
                 |
                 v
       +-------------------+
       |                   |
       |      onStop()     |
       |                   |
       +---------+---------+
                 |
                 v
       +-------------------+
       |                   |
       |      onDestroy()  |
       |                   |
       +-------------------+

Android activity lifecycle graph

is I can extends superclass activity which superclass extends AppCompatActivity?

Yes, you can certainly extend a superclass that extends AppCompatActivity in your Android application. In fact, it's a common practice to create a custom base activity that extends AppCompatActivity and then have your other activities in the application extend this custom base activity.

For example, you might create a custom base activity like this:

java

import androidx.appcompat.app.AppCompatActivity;

public class MyBaseActivity extends AppCompatActivity {
    // Common functionality or configurations can be implemented here
}

And then your other activities can extend this base activity:

java

public class MyActivity extends MyBaseActivity {
    // Your activity-specific code goes here
}

This approach allows you to centralize common functionality or configurations in one place, making it easier to maintain and manage your activities.