调用浏览器:
<span style="font-size:18px;">Intent intent=new Intent();
intent.setAction("android.intent.action.VIEW");//显示指定数据
intent.setData(Uri.parse("http://www.baidu.com"));
startActivity(intent);
</span>
调用拨号器:
<span style="font-size:18px;">Intent intent=new Intent();//Intent intent = new Intent(Intent.ACTION_DIAL);
intent.setAction(Intent.ACTION_DIAL);
intent.setData(Uri.parse("tel:10000"));
startActivity(intent);</span>
向下一个活动传递数据:
<span style="font-size:18px;">String data = "Hello SecondActivity";
Intent intent = new Intent(FirstActivity.this, SecondActivity.class);
intent.putExtra("extra_data", data);
startActivity(intent);</span>
返回数据到上一个活动:
firstActivity:
<span style="color:#000000;">Intent intent = new Intent(FirstActivity.this, SecondActivity.class);
startActivityForResult(intent, 1);//1:<span style="font-family:SimSun;color:#000000;font-size:11pt;font-style:normal;font-variant:normal;">请求码</span></span>
secondActivity:
<span style="color:#000000;">Intent intent = new Intent();
intent.putExtra("data_return", "Hello FirstActivity");
setResult(RESULT_OK, intent);
finish();</span>
firstActivity重写onActivityResult()
<span style="font-size:18px;">@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {//<span style="font-family:TimesNewRomanPSMT;color:#000000;font-size:11pt;font-style:normal;font-variant:normal;">requestCode</span>:请求码
switch (requestCode) {
case 1:
if (resultCode == RESULT_OK) {
String returnedData = data.getStringExtra("data_return");
Log.d("FirstActivity", returnedData);
}
break;
default:
}
}
打开一个Intent:
<span style="font-size:18px;">Intent intent=new Intent();
intent.setAction("android.intent.action.BALA");
intent.addCategory("android.intent.action.BALABALA");
startActivity(intent);</span>
目标Activity Androidmanifest.xml
<span style="font-size:18px;"><activity android:name="com.example.aaaasasdd.ActionBala">
<intent-filter>
<action android:name="android.intent.action.BALA" />
<category android:name="android.intent.action.BALABALA" />
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity></span>