意图提供了一个一种通用的消息系统,使用意图可以激活android引用的3中组件:活动,服务和广播接受者。
显式意图:intent.setCompont; intent.setClassName; intent.setClass
隐式意图:setAction; getCategory; uri
(在没有数据传递时)只要意图中的action和category都出现在过滤器中,意图就可以匹配。
打电话
权限
<uses-permission android:name="android.permission.CALL_PHONE"/>
try {
m_edt=(EditText)findViewById(R.id.editText1);
String number=m_edt.getText().toString();
Intent intent = new Intent();
//intent.setAction("android.intent.action.CALL");
intent.setAction(Intent.ACTION_CALL);//通过action过滤activity
intent.setData(Uri.parse("tel:"+number));
startActivity(intent);
} catch (Exception e) {
// TODO: handle exception
Log.e("songtag ", e.toString());
}
启动其他activity
// TODO Auto-generated method stub
Intent intent=new Intent();
intent.setClass(LoginActivity.this,RegActivity.class);//通过class过滤activity
Bundle bundle=new Bundle();
bundle.putString("key1","value1");//key1为名,value1为值
bundle.putString("key2","value2");
intent.putExtras(bundle);
//传数据结束
startActivity(intent);
finish();
参考---谢谢作者
Android开发之Intent.Action
Android Intent详解