1. Context
2. Application
3. Activity&Fragment&Intent
3.1 Activity lifecycle and its functions
1).onCreate(): called when the Activity starts for the first time; 2).onstart (): onCreate() is called after it is called; Called after onRestart() when the Activity is visible to the user again; 3).onresume (): call after onStart(); Called after onPause(),onRestart(),onRestoreInstanceState() has been called; Used to handle interactions with users; 4). OnPause (): The Activity is called when it is in the background and has not been killed. It is terminated when the system is out of memory. 5).onStop(): called when the Activity is no longer visible to the user, i.e. a new Activity overwrites the Activity; Called when an Activity is overwritten by a transparent or dialog-like Activity, such as a phone call; After the call is complete, the Activity is still managed by the window manager, visible, unfocused, and unable to interact with the user. 6).onrestart (): the Activity is called when onStop() has been stopped and is visible to the user again, for example, click the back button to return to the Activity; The Activity is terminated when the system needs memory; 7).ondestroy (): Called before the Activity is terminated to finish the final cleanup;Copy the code
3.2 The four basic states of the Activity
1). Running: The activity is at the front end, which is visible and focused by users and can interact with users. OnCreate ()->onStart() -onresume (); 2). Paused state: the activity was placed in the background and was not stopped. The user could see it, lost its focus and could not interact with the user, and its status information would be retained by the system. To return to the running state, call onResume(). 3). Stopped: The activity is overwritten by a new activity, loses focus and becomes invisible, and its status information is retained by the system. To return to the running state, call onRestart()->onStart()->onResume(); 4). Destroyed: The activity is terminated by the system and resources are recovered; You need to create the activity again to return to the running state after calling onDestroyed().Copy the code
3.3 Activity Four startup modes and applications
1). Standard (default): Each request to start an Activity creates a new Activity instance in the stack; Scenarios: Applicable to most scenarios; 2). SingleTop (top of stack reuse mode): If the Activity you want to start already exists at the top of the stack, call onNewIntent() to get an instance of the Activity; 3). SingleTask (in-stack singleTask mode): If the Activity to be started already exists in the task stack, send the instance of the Activity back to the top of the stack and remove all activities before it; Scene: Most app homepage,Webview homepage, TWO-DIMENSIONAL code scanning interface, etc. 4). SingleInstance (single task stack mode): There is only one instance of this Activity in the whole system. The Activity is stored in a separate task stack. Scenario: alarm clock reminder interface, dialing program interface, caller ID interface;Copy the code