Jumps between pages can be achieved through the intent class. This is not the same as the As/egret, as well as the HTML front end, this article explains the A interface jumps to the B interface, and a bounds for the B interface to pass a parameter.
One: interface design
①, A (activity.main.xml)
Important CONTROLS:
1 ' (TextView) Txt_infos: Used to get the information the user needs to send, with a value of xxxxxx
2 ' (button) Btn_go_a: Jump to the B-interface button
Such as:
②,b (Activity_b2.xml)
②-1:
1 ' Create a new activity method: Right-click on the Layout folder------activity---------empty activity (this time select Blank template)
Such as
2 ' in the Create Panel that pops up, note the activity name (class name), and keep the suffix activity. Such as:
②-2: Important controls
1 ' (TextView) Txt_getinfo: Used to display information obtained from the A interface
Two: Interface code
①,a Interface Code
Package Com.example.kayer.aas;import Android.content.intent;import android.support.v7.app.AppCompatActivity; Import Android.os.bundle;import android.view.view;import android.widget.button;import Android.widget.TextView; Import Android.widget.toast;public class Mainactivity extends Appcompatactivity {private TextView Txt_infos = null; Private Button btn_go_a = null; @Override protected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (R.layout.activity_main); This.init (); } private void Init () {This.txt_infos = (TextView) Findviewbyid (R.id.txt_infos); This.btn_go_a = (Button) Findviewbyid (r.id.btn_go_a); This.btn_go_A.setOnClickListener (New View.onclicklistener () {@Override public void OnClick (View v) {String $info = MainActivity.this.txt_infos.getText (). toString (). Trim (); if ($info. Length () > 0) {Intent $goto = New Intent (Mainactivity.this, B2activity.class); $goto. PutExtra ("info", $info); MainActivity.this.startActivity ($goto); }else{Toast.maketext (mainactivity.this, "Please enter information", Toast.length_short). Show (); } } }); }}
①,b Interface Code
package com.example.kayer.aas;import android.content.Intent;import android.support.v7.app.AppCompatActivity;import android.os.Bundle;import android.widget.TextView;public class B2Activity extends AppCompatActivity { private TextView txt_getInfo = null; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_b2); this.init(); } private void init(){ this.txt_getInfo = (TextView)findViewById( R.id.txt_getInfo ); Intent $getA = getIntent(); String $info = $getA.getStringExtra("info"); this.txt_getInfo.setText( $info ); }}
Android Intent (i)