In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
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!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.