首页 > 技术文章 > Activity和Intent基础

aisi-liu 2015-01-16 13:09 原文

1.Conponent name:要启动的名称,如(main.this , second.class)
    Intent不仅可以启动Activity,还可以启动Service、广播接收器(Broadcast Receiver)等内容。。
2.Action:一些动作:ACTION_CALL、ACTION_EDIT
3.Data:传输的数据
4.Extras:可以传输键值对

页面跳转:
新建内部类,实现OnClickListener接口,并重写OnClick抽象方法,里面实现页面跳转
然后,在按钮上设置监听器,new MyButtonListener()
注:没新建一个Activit都要在AndroidManifest里面注册Activity
<activity
android:name=".TheOther"
android:label="the other"></activity>

Intent在两个Activity之间传递数据
 
Intent intent = new Intent();
intent.putExtra("key","this is value from Intent");
intent.setClass(MainActivity.this,TheOther.class);
startActivity(intent);
另一个Activity接收数据
Intent i = getIntent();
String s = i.getStringExtra("key");
textView.setText(s);

Intent的两个Activity之间传数据,可以不在一个程序中,例如,在自己的程序里调用系统发短信的界面,就可以用Intent
Uri uri = Uri.parse("smsto//080000123");
Intent i = new Intent(Intent.ACTION_SENDTO,uri);
i.putExtra("sms_body","The SMS text");
startActivity(i);
就会启动打电话的界面(系统自带)

推荐阅读