What is the order of page switching and common methods in android?
This article mainly introduces the android page switching and commonly used methods of implementation order is how, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let Xiaobian with you to understand.
Package com.example.android.active;import android.os.Bundle;import android.app.Activity;import android.content.Intent;import android.view.Menu;import android.view.View / * * @ seven methods and four states in the deprecated Activity life cycle * * / public class MainActivity extends Activity {/ * Activity is called when it is created * you can initialize the UI component in this method * the onStart () method * * / @ Override protected void onCreate (Bundle savedInstanceState) {super.onCreate (savedInstanceState) is called when the method is called. SetContentView (R.layout.activity_main); System.out.println ("MainActivity-onCreate ()");} / * * is called by onCreate (), activity courseware, but cannot be operated * this method will call onResume () or onStop () method * * / @ Override protected void onStart () {/ / TODO Auto-generated method stub super.onStart () System.out.println ("MainActivity-onStart ()");} / * when an activity in the stop state regains focus * this method calls the onStart method * / @ Override protected void onRestart () {/ / TODO Auto-generated method stub super.onRestart () System.out.println ("MainActivity-onRestart ()");} / * is called by onStart (), and activity is visible and interactive. * at this time, activity is in Running state * / @ Override protected void onResume () {super.onResume (); System.out.println ("MainActivity-onResume ()") } / * when activity is running and is overwritten by other activity (bit full override call) * activity is paused, lost focus and inoperable * activity can be dropped by kill in this state * if the user returns the activity, then the onResume method will be called Regain focus * * / @ Override protected void onPause () {/ / TODO Auto-generated method stub super.onPause () System.out.println ("MainActivity-onPause ()") } / * is called when the activity is completely overwritten by another activity * at this time the activity is stopped and completely invisible * the activity can be dropped by kill in this state * when the user returns to the changed activity The restart method * / @ Override protected void onStop () {/ / TODO Auto-generated method stub super.onStop () is called System.out.println ("MainActivity-onStop ()");} / * when activity calls the finish method or is destroyed by the system * you can release resources in this method * * / @ Override protected void onDestroy () {/ / TODO Auto-generated method stub super.onDestroy () System.out.println ("MainActivity-onDestory ()");} @ Override public boolean onCreateOptionsMenu (Menu menu) {/ / Inflate the menu; this adds items to the action bar if it is present. GetMenuInflater () .inflate (R.menu.main, menu); return true;} / * jump to the activity2 interface by this method * / public void gotoActivity2 (View v) {/ / create an intentional Intent intent=new Intent (this,MainActivity2.class); / / start another activity startActivity (intent);}} package com.example.android.active Import android.app.Activity;import android.os.Bundle;import android.view.Menu;public class MainActivity2 extends Activity {/ * Activity is called when it is created * you can initialize the UI component in this method * the onStart () method * * / @ Override protected void onCreate (Bundle savedInstanceState) {super.onCreate (savedInstanceState) is called after the method is called. SetContentView (R.layout.activity_main); System.out.println ("MainActivity2-onCreate ()");} / * * is called by onCreate (), activity courseware, but cannot be operated * this method will call onResume () or onStop () method * * / @ Override protected void onStart () {/ / TODO Auto-generated method stub super.onStart () System.out.println ("MainActivity2-onStart ()");} / * when an activity in the stop state regains focus * this method calls the onStart method * / @ Override protected void onRestart () {/ / TODO Auto-generated method stub super.onRestart () System.out.println ("MainActivity2-onRestart ()");} / * is called by onStart (), and activity is visible and interactive. * at this time, activity is in Running state * / @ Override protected void onResume () {super.onResume (); System.out.println ("MainActivity2-onResume ()") } / * when activity is running and is overwritten by other activity (bit full override call) * activity is paused, lost focus and inoperable * activity can be dropped by kill in this state * if the user returns the activity, then the onResume method will be called Regain focus * * / @ Override protected void onPause () {/ / TODO Auto-generated method stub super.onPause () System.out.println ("MainActivity2-onPause ()") } / * is called when the activity is completely overwritten by another activity * at this time the activity is stopped and completely invisible * the activity can be dropped by kill in this state * when the user returns to the changed activity The restart method * / @ Override protected void onStop () {/ / TODO Auto-generated method stub super.onStop () is called System.out.println ("MainActivity2-onStop ()");} / * when activity calls the finish method or is destroyed by the system * you can release resources in this method * * / @ Override protected void onDestroy () {/ / TODO Auto-generated method stub super.onDestroy () System.out.println ("MainActivity2S-onDestory ()");} @ Override public boolean onCreateOptionsMenu (Menu menu) {/ / Inflate the menu; this adds items to the action bar if it is present. GetMenuInflater () .inflate (R.menu.main, menu); return true;}}
File configuration
Run the project
After clicking to start the second activity
After clicking the back button
Thank you for reading this article carefully. I hope the article "what is the order of page switching and common methods in android" shared by the editor will be helpful to you. At the same time, I also hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!