`

android activity-alias 做多入口程序(多个launch icon)

 
阅读更多
代码
<activity
            android:name=".IconOne"
            android:icon="@drawable/ic_launcher"
            android:label="icon1"
            android:launchMode="singleTask"
            android:clearTaskOnLaunch="true"
            android:screenOrientation="nosensor" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.LAUNCHER" />
                <category android:name="android.intent.category.BROWSABLE" />
            </intent-filter>
        </activity>

        <activity-alias
            android:name="combine"
            android:label="icon2"
            android:targetActivity=".IconOne" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.LAUNCHER" />
                <category android:name="android.intent.category.BROWSABLE" />
            </intent-filter>
        </activity-alias>


protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_icon_one);
		Log.d("debug", "onCreate" +  getIntent().getComponent().getClassName());
	}
	
	@Override
	protected void onNewIntent(Intent intent) {
		// TODO Auto-generated method stub
		super.onNewIntent(intent);
		setIntent(intent);
		Log.d("debug", "onNewIntent" +  intent.getComponent().getClassName());
	}


这里使用activity-alias实现多个launch一起进入了IconOne.
需要注意的是:
1. IconOne中需要使用
            android:launchMode="singleTask"
            android:clearTaskOnLaunch="true"
   否则, 下一次按Home退出后,按另一个icon进入就不会调用onNewIntent();
2. onNewIntent中注意setIntent否则getIntent()会是之前的intent.
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics