標籤:
Intent是Android中各組件跳轉的重要方式,一般可悲用於啟動活動、啟動服務、以及發送廣播等情境。
#顯示Intent
主要主要用於啟動已知的組件
//發送方
Intent intent = new Intent(FirstActivity.this, SecondActivity.class);
intent.putExtra("extra_data", data);
startActivity(intent);
//接收方
Intent intent = getIntent();
String data = intent.getStringExtra("extra_data");
#隱示Intent
(1)action
(2)category
(3)data:scheme、host、path、type
Intent intent = new Intent("com.example.activitytest.ACTION_START");
intent.addCategory("com.example.activitytest.MY_CATEGORY");
//如果不添加Category,那麼預設使用DEFAULT
startActivity(intent);
//AndroidManifest.xml
//用來響應Intent
<activity android:name=".SecondActivity" >
<intent-filter>
<action android:name="com.example.activitytest.ACTION_START" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
##使用Intent啟動瀏覽器
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("http://www.baidu.com"));
startActivity(intent);
Android複習筆記--Intent