问题
I have an application that contains two Activities with
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
in the manifest. I did this so that there are 2 separate entries in the app drawer. It functions properly with regards to the app drawer as it is.
My question comes during the install. After you install an app with only one MAIN/LAUNCHER activity the last page has an open button that will launch the app that was just installed. With my app this open button is greyed out. I assume it is because it doesn't know which of the two activities I would want it to launch if the open button were pressed. Is there anything I can set in the manifest(or elsewhere) to specify which activity I'd like the open button to launch at the end of the install process? I am thinking there must be something I can set, because when I install the app through adb with eclipse it launches one of the two activities and luckily it is actually the one that I would like it to launch.
回答1:
This question:
After downloading an application with two Launcher components from the Marketplace, clicking "Open" will cause a crash
Helped me to get it working how I wanted. The key was adding:
<activity-alias android:name="com.android.internal.app.ResolverActivity"
android:targetActivity=".Main" android:exported="true">
</activity-alias>
to the manifest and changing ".Main" to reference the activity that you wish to start with the open button at the end of install.
Note that the activity-alias tag must be declared after the activity tag you are referring to (in the xml).
回答2:
It is strongly recommended by the Android docs that if you are going to have multiple Activities launch from the Home screen, that each one be launched within its own task. Take a look at this article for more information.
When doing so, each task will have a separate taskAffinity value. I believe that the task which is set to the same affinity as the application's package is the one that will be picked up by the installer as the one to launch.
回答3:
I would suggest you to have 1 activity which reads preferences and decide to proceed with the current activity or to open another activity.
If you do not wish to start a new activity, try inflating appropriate fragment.
来源:https://stackoverflow.com/questions/8827800/application-with-2-launcher-activities