SoFunction
Updated on 2025-04-10

Analysis of the difference between onStart and onResume in Android Activity

This article analyzes the difference between onStart() and onResume() in Android Activity. Share it for your reference, as follows:

First of all, you need to knowFour states of activity

Active/Runing After a new activity is launched, it is at the front end of the screen and at the top of the stack. At this time, it is in an active state that is visible and interactive with the user.

Paused state when the activity is overwritten by another transparent or Dialog-style activity. At this time, it remains connected to the window manager, and the system continues to maintain its internal state, so it is still visible, but it has lost its focus and cannot interact with the user

oped Stoped when the activity is covered by another activity and lost focus and is not visible.

Killed Activity is in Killed state when it is killed by the system or is not started

analyze:

protected void onStart() This method is called after the onCreate() method, or when the Activity is converted from the Stop state to the Active state, generally onResume() is executed after the onStart() is executed.

protected void onResume() is called when the Activity transitions from Pause state to Active state.

onResume is the activity that gains user focus and interacts with users

onStart is visible to the activity user, including having an activity on it but not completely overwrite it, the user can see part of the activity but cannot interact with it.

Supplement: Six main functions in Android Activity

An Activity in Android generally requires six functions to be implemented:

onCreate(), onStart(), onResume(),onPause(),onStop(),onDestroy().

1. onCreate function: Register the variables you want to use, such as service and receiver. These variables can be responded to regardless of whether your activity is in the foreground or in the background, and then call the above function to initialize the layout information.

2. onStart function: register some variables. These variables must be responded when the Android Activity class is in the foreground.

3. onResume function: Call some functions that refresh the UI. Whenever Activity is called here, the status of each UI control must be refreshed.

4. onPause function: Generally, some variables are set, because at this time, the Activity will be cut to the background processing immediately, and some variables may be released or the state needs to be adjusted accordingly.

5. onStop function: Unregister variables registered in onStart function.

6. onDestory function: Unregister variables registered in onCreate function.

In Android-Hello,

public class UbiLrnActivity extends Activity {
 /** Called when the activity is first created. */
 @Override
 public void onCreate(Bundle savedInstanceState) {
  (savedInstanceState);
  setContentView();
 }
}

First, an onCreate function is declared. The passed parameter of this function is savedInstanceState. The type is Bundle. Bundle is a data parameter, which is generally used for data transmission between activities. The parameters of onCreate() are all of the Bundle class.

It means calling the parent class onCreate.

setContentView() represents the system's resource loading through loading.

For more information about Android Activity, readers who are interested in view the topic of this site:Android programming activity operation skills summary

I hope this article will be helpful to everyone's Android programming design.