Android 显示的意图(Intent)的实现活动(Activity)之间的切换

it2026-02-20  12

界面切换及数据传输

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 @Override public void onClick(View v) {       //创建一个用来传递数据intent对象       Intent intent = new Intent();       //调用setclass方法,第一个参数为当前Activity类自身引用,第二个为跳转的Activity       intent.setClass( this , SecondActivity. class );       //获取文本编辑框中用户输入的信息       String username = mEditText1.getText().toString();       String password = mEditText2.getText().toString();       //创建一个封装类Person来封装数据       Person p = new Person(username, password);       //调用putExtra方法,第一个参数为此对象的键,第二个为此对象的值       intent.putExtra( "person" , p);       //启动界面跳转       startActivity(intent );  }

 

在第二个界面代码中获取调用getintent获取信息,并将获取信息的值显示在界面上,代码如下

1 2 3 4 5 6 7 TextView textView = (TextView) findViewById(R.id.textView1);  //获取传递过来的intent对象  Intent intent = getIntent();  //调用intentgetSerializableExtra()方法获取person对象  Person p = (Person) intent.getSerializableExtra( "person" );  //将person封装的数据显示到文本上  textView.setText( "您的姓名是:" +p.mUsername+ ",您的密码是:" +p.mPassword);

隐身意图的使用:  调用系统应用 可以使用setAction的方法

1 2 3 4 5 6 7 8 9 public void click(View view) {          // 隐式意图 激活一个界面 开启界面          Intent intent = new Intent();          intent.setAction(Intent.ACTION_VIEW);          intent.setData(Uri.parse( "http://www.baidu.com" ));          // 激活界面          startActivity(intent);         }

 

 

 

 

 

 

 

来自为知笔记(Wiz)

转载于:https://www.cnblogs.com/feelbest/p/3696245.html

相关资源:数据结构—成绩单生成器
最新回复(0)