Intent啓動一個Activity

顯式Intent
Intent intent=new Intent(FirstActivity.this,SecondActivity.class);
startActivity(intent);
其中SecondActivity爲目標活動

隱式Intent
1.爲活動設置抽象的action和category等信息,相當於活動的一個標記
<activity android:name=".SecondActivity" >
     <intent-filter> 
         <action android:name="com.example.activitytest.ACTION_START" />
         <category android:name="android.intent.category.DEFAULT" />
     </intent-filter> 
</activity> 

2.將標籤傳入Intent做參數
Intent intent = new Intent("com.example.activitytest.ACTION_START"); startActivity(intent);
此時category不用傳,因爲設置了DEFAULT屬性

發佈了28 篇原創文章 · 獲贊 18 · 訪問量 6萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章