Intent在尋找目標組件的時候有兩種方法:第一,通過組件名稱直接指定;第二,通過Intent Filter過濾指定.
Intent啓動不同組件的方法:
組件名稱 |
方法名稱 |
Activity |
startActivity() startActivityForResult() |
Service |
startService() bindService() |
Broadcasts |
sendBroadcast() sendOrderedBroadcast() sendStickyBroadcast() |
我用到的是調用Activity,並且傳遞數據(對象,對象數組,基本數據類型)
<span style="white-space:pre"> </span>Intent intent=new Intent();
intent.setClass(this,GuideActivity.class);
Bundle bundle=new Bundle();
bundle.putSerializable("shop",shop);//發送對象
bundle.putSerializable("catalogs",(Serializable)catalogs_List);//發送List<Object>
bundle.putSerializable("guide",guide);
intent.putExtras(bundle); //將bundle放到intent中
startActivity(intent);
解釋:見註釋。但是一定要把Model對象實現Serializable接口(序列化),否則傳遞不了。另外就是要通過bundle對象傳遞Model對象。
顯示網頁:
- Uri uri = Uri.parse("http://www.google.com");
- Intent it = new Intent(Intent.ACTION_VIEW,uri);
- startActivity(it);
顯示地圖:
- Uri uri = Uri.parse("geo:38.899533,-77.036476");
- Intent it = new Intent(Intent.Action_VIEW,uri);
- startActivity(it);
調用撥號程序:
- Uri uri = Uri.parse("tel:xxxxxx");
- Intent it = new Intent(Intent.ACTION_DIAL, uri);
- startActivity(it);
撥打電話:
- Uri uri = Uri.parse("tel.xxxxxx");
- Intent it =new Intent(Intent.ACTION_CALL,uri);