android activity-alias 做多入口程序(多个launch icon)
16lz
2021-12-04
代码
这里使用activity-alias实现多个launch一起进入了IconOne.
需要注意的是:
1. IconOne中需要使用
android:launchMode="singleTask"
android:clearTaskOnLaunch="true"
否则, 下一次按Home退出后,按另一个icon进入就不会调用onNewIntent();
2. onNewIntent中注意setIntent否则getIntent()会是之前的intent.
<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());}@Overrideprotected void onNewIntent(Intent intent) {// TODO Auto-generated method stubsuper.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.
更多相关文章
- radio button 旁边放图片以及强制程序本地化以及string含有参数
- Android——SQLite/数据库 相关知识总结贴
- android中searchable的使用
- Android日历控件
- Android(安卓)Studio中Gradle使用详解
- 用HTML5开发Android应用程序
- Android(安卓)之使用Android(安卓)Studio(AS)命令打release包
- [置顶] Android(安卓)使用Android(安卓)Studio + Gradle 或 命令
- Android(安卓)项目优化(七):阿里巴巴Android开发手册整理总结