Android Activity jump

Source: Internet
Author: User

Jumping from one screen to another, one activity jumps to another activity,intent class for passing data and jumps between components, including not only activity.

 Packagecom.sxt.day04_01;Importcom.sxt.day04_01.entity. User;Importandroid.app.Activity;Importandroid.content.Intent;ImportAndroid.os.Bundle;Importandroid.text.TextUtils;ImportAndroid.view.View;ImportAndroid.view.View.OnClickListener;ImportAndroid.widget.EditText; Public classLoginactivityextendsActivity {EditText metid,metpwd; @Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate);        Setcontentview (R.layout.activity_login);        Initview ();    Setlistener (); }    Private voidSetlistener () {Setexitclicklistener ();//set the listener for the exit buttonSetloginclicklistener ();//Set the login button listener    }    //Set the login button listener    Private voidSetloginclicklistener () {Findviewbyid (r.id.btnlogin). Setonclicklistener (NewOnclicklistener () {@Override Public voidOnClick (View v) {String ID=Metid.gettext (). toString (); if(Textutils.isempty (id)) {metid.seterror ("Number cannot be empty"); return ; } String pwd=Metpwd.gettext (). toString (); if(Textutils.isempty (pwd)) {Metpwd.seterror ("Password cannot be empty"); return ; } Intent Intent=NewIntent (loginactivity. This, Mainactivity.class); //reduces the coupling of 2 activity (the degree of tightness), the relationship between 2 classes in Java is less, modifying one class has little impact on another class ,Intent.putextra ("id", id);//The health must be a string, and the value can be any typeIntent.putextra ("Password", PWD); User User=NewUser (Integer.parseint (ID), PWD); Intent.putextra ("User", user);//user to implement Serializable interfacestartactivity (Intent);    }        }); }    //set the listener for the exit button    Private voidSetexitclicklistener () {Findviewbyid (r.id.btnexit). Setonclicklistener (NewOnclicklistener () {@Override Public voidOnClick (View v) {finish ();    }        }); }    Private voidInitview () {Metid= (EditText) Findviewbyid (R.id.etid);//New is out of the objectMetpwd=(EditText) Findviewbyid (R.ID.ETPWD); }}
 Packagecom.sxt.day04_01;Importcom.sxt.day04_01.entity. User;ImportAndroid.os.Bundle;Importandroid.app.Activity;Importandroid.content.Intent;ImportAndroid.util.Log;ImportAndroid.view.Menu; Public classMainactivityextendsActivity {@Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate);        Setcontentview (R.layout.activity_main); Intent Intent=getintent ();//Gets the intent of the last activity passString Id=intent.getstringextra ("id");//gets the data of type string, Getintextra gets the int type dataString Pwd=intent.getstringextra ("Password"); User User= (user) Intent.getserializableextra ("user")); LOG.I ("Main", "id=" +id+ ", Password:" +pwd); LOG.I ("Main", user.tostring ()); }}

Android Activity jump

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.