android Intent 意图 常用属性

Intent表示意图,一般用来进行跳转内容,实现组件之间的跳转。

六大属性:

ComponentName (组件名)

Action(定义动作)

为了区别当前的intent对象进行使用的,类型是字符串。

Category(分类)

进一步筛选需要处理的内容

<category android:name="android.intent.category.DEFAULT" />隐式启动Category

<category android:name="android.intent.category.LAUNCHER" />入口Category

Extra(额外内容)

  intent.putExtra(键值对)键是字符串类型。

  intent.putExtras(bundle类型对象)可以放置很多数据。

传递数据:

Intent intent= new Intent(当前.this,目标.class);

intent.putExtra("info","天气不错~");

StartActivity(intent);

 

获取数据:

if(getIntent()!=null){

  Intent intent = getIntent();

  String info = intent.getStringExtra("info");

}

 

传递大量数据:

Intent intent= new Intent(当前.this,目标.class);

Bundle bundle = new Bundle();

bundle.putString("info",input.getText().toString());

intent.putExtras(bundle);

StartActivity(intent);

 

获取大量数据:

if(getIntent()!=null){

  Intent intent = getIntent();

  Bundle bundle = intent.getExtras();

  String info = bundle.getString("info"); API版本12以上

}

 

 

启动一个Activity一般有两种形式,分别是显式启动和隐式启动

显式启动:

Intent i=new Intent(当前Activity.this,目标Activity.class);

startActivity(i);

隐式启动:

Intent i=new Intent();

i.setAction("com.sxt.testintent.MainActivity.action");

startActivity(i);

如果需要实现隐式启动,一般使用action和data活着action和category结合。

 

源自:bjsxt.android.jyq

posted @ 2017-03-02 10:37  cqutwangyu  阅读(290)  评论(0编辑  收藏  举报