Android has returned results jump intent

Source: Internet
Author: User

Android has returned results jump intent:

(1, pay attention to jump when you want to pass the object like user must implement the Serializable interface, 2, login Java code setresult (RESULT_OK, intent); Be sure to call the finish () method )

Main Page layout:layout/activity_main.xml:

<relativelayout xmlns:android= "Http://schemas.android.com/apk/res/android"
Xmlns:tools= "Http://schemas.android.com/tools"
Android:layout_width= "Match_parent"
android:layout_height= "Match_parent"
android:paddingbottom= "@dimen/activity_vertical_margin"
android:paddingleft= "@dimen/activity_horizontal_margin"
android:paddingright= "@dimen/activity_horizontal_margin"
android:paddingtop= "@dimen/activity_vertical_margin"
tools:context= "Com.sxt.main.MainActivity" >
<button
Android:layout_width= "Match_parent"
android:layout_height= "Wrap_content"
Android:id= "@+id/btlogin"
android:text= "Landing"/>
<button
Android:layout_width= "Match_parent"
android:layout_height= "Wrap_content"
android:layout_below= "@id/btlogin"
Android:id= "@+id/btregister"
android:text= "Register"/>

</RelativeLayout>
Main Page Layout Java code:

Package com.sxt.main;


Import android.support.v7.app.ActionBarActivity;
Import android.content.Intent;
Import Android.os.Bundle;
Import Android.util.Log;
Import Android.view.Menu;
Import Android.view.MenuItem;
Import Android.view.View;
Import Android.view.View.OnClickListener;
Import Android.widget.EditText;
Import Android.widget.Toast;


public class Mainactivity extends Actionbaractivity {
private static final int logincode = 0;
private static final int REGISTER = 10;
@Override
protected void OnCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);
Setcontentview (R.layout.activity_main);
Setlistener ();
}


private void Setlistener () {
TODO auto-generated Method Stub
Findviewbyid (R.id.btlogin). Setonclicklistener (New Onclicklistener () {

@Override
public void OnClick (view view) {
TODO auto-generated Method Stub
Intent Intent = new Intent (mainactivity.this,loginactivity.class);
Startactivityforresult (Intent, Logincode);
}
});
}


This is the action to jump back to another layout page
@Override
protected void Onactivityresult (int requestcode, int resultcode, Intent data) {
TODO auto-generated Method Stub
Super.onactivityresult (Requestcode, ResultCode, data);
if (RESULTCODE!=RESULT_OK) {
Return
}
Switch (requestcode) {
Case Logincode:
User user = (user) Data.getserializableextra ("User");
LOG.I ("main", "Registration information is:" +user);
Toast.maketext (This, "registration information is:" +user, 50000). Show ();
Break
Case REGISTER:

Break
}
}






}

jump to the login Registration page layout:

Landing Page layout:layout/activity_login.xml:

<linearlayout xmlns:android= "Http://schemas.android.com/apk/res/android"
Xmlns:tools= "Http://schemas.android.com/tools"
Android:layout_width= "Match_parent"
android:layout_height= "Match_parent"
android:orientation= "Vertical" >
<linearlayout
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
android:orientation= "Horizontal" >
<textview
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
android:text= "Number"/>

<edittext
Android:layout_width= "Match_parent"
android:layout_height= "Wrap_content"
Android:id= "@+id/etuser"
Android:hint= "Please enter 1-10 characters"
/>

</LinearLayout>
<linearlayout
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
android:orientation= "Horizontal" >
<textview
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
android:text= "Password"/>

<edittext
Android:layout_width= "Match_parent"
android:layout_height= "Wrap_content"
Android:id= "@+id/etpassword"
Android:hint= "Please enter 1-10 characters"
Android:password= "true"/>

</LinearLayout>
<linearlayout
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
android:orientation= "Horizontal" >

<button
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
android:visibility= "Invisible"
/>
<button
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
Android:id= "@+id/register"
android:text= "Login"
android:drawableleft= "@drawable/login32x32"
android:background= "@drawable/btn_bg"/>
<button
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
android:visibility= "Invisible"
/>
<button
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
Android:id= "@+id/exit"
android:drawableleft= "@drawable/exit32x32"
android:background= "@drawable/BTN_BG"
android:text= "Exit"/>
<button
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
android:visibility= "Invisible"
/>
</LinearLayout>
</LinearLayout>

Jump to the login registered Java code:

Package com.sxt.main;


Import android.support.v7.app.ActionBarActivity;
Import Android.text.TextUtils;
Import android.content.Intent;
Import Android.os.Bundle;
Import Android.view.Menu;
Import Android.view.MenuItem;
Import Android.view.View;
Import Android.view.View.OnClickListener;
Import Android.widget.EditText;


public class Loginactivity extends Actionbaractivity {
Private EditText Etuser,etpassword;
@Override
protected void OnCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);
Setcontentview (R.layout.activity_login);
Init ();
Setlistener ();
}


private void Setlistener () {
TODO auto-generated Method Stub
Findviewbyid (R.id.register). Setonclicklistener (New Onclicklistener () {

@Override
public void OnClick (view view) {
TODO auto-generated Method Stub
String code = Etuser.gettext (). toString ();
if (Textutils.isempty (code)) {
Etuser.seterror ("Number cannot be empty");
Return
}
String PASSW = Etpassword.gettext (). toString ();
if (Textutils.isempty (PASSW)) {
Etpassword.seterror ("Password cannot be empty");
Return
}
Intent Intent = new Intent (loginactivity.this,mainactivity.class);
Intent.putextra ("User", new User (CODE,PASSW));
Setresult (RESULT_OK, intent);
Finish ();
}
});
Findviewbyid (R.id.exit). Setonclicklistener (New Onclicklistener () {

@Override
public void OnClick (view view) {
TODO auto-generated Method Stub
Finish ();
}
});
}


private void init () {
TODO auto-generated Method Stub
Etuser = (EditText) Findviewbyid (R.id.etuser);
Etpassword = (EditText) Findviewbyid (R.id.etpassword);

}
}
entity class User:

Package com.sxt.main;


Import java.io.Serializable;


public class User implements serializable{
Private String Code;
private String password;
Public String GetCode () {
return code;
}
public void Setcode (String code) {
This.code = code;
}
Public String GetPassword () {
return password;
}
public void SetPassword (String password) {
This.password = password;
}
Public User (string code, string password) {
Super ();
This.code = code;
This.password = password;
}
@Override
Public String toString () {
TODO auto-generated Method Stub
Return this.code+ "," +this.password;
}

}

Effect:

First Click Login:

650) this.width=650; "src=" http://img.blog.csdn.net/20141123202713459 "/>

The second step is to fill in the information:

650) this.width=650; "src=" http://img.blog.csdn.net/20141123202758250 "/>

The 3rd step landing successfully returned to the original layout page:

650) this.width=650; "src=" http://img.blog.csdn.net/20141123202811460 "/>

Android has returned results jump intent

Related Article

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.