问题
Create a sample application with two launcher icons. For example, two components such as:
<application ...>
<activity ... android:name="TestActivity01">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity ... android:name="TestActivity02">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
Either install the application via downloading from the Marketplace, or via AppInstaller. When the message box asks you if you would like to run the application, an exception is thrown:
02-03 16:42:44.270: ERROR/AndroidRuntime(395):
android.content.ActivityNotFoundException: Unable to find explicit activity
class {com.xxx.xxx/com.android.internal.app.ResolverActivity}; have you
declared this activity in your AndroidManifest.xml?
02-03 16:42:44.270: ERROR/AndroidRuntime(395): at
android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1
480)
02-03 16:42:44.270: ERROR/AndroidRuntime(395): at
android.app.Instrumentation.execStartActivity(Instrumentation.java:1454)
02-03 16:42:44.270: ERROR/AndroidRuntime(395): at
android.app.Activity.startActivityForResult(Activity.java:2660)
02-03 16:42:44.270: ERROR/AndroidRuntime(395): at
android.app.Activity.startActivity(Activity.java:2704)
02-03 16:42:44.270: ERROR/AndroidRuntime(395): at
com.android.packageinstaller.InstallAppDone.onClick(InstallAppDone.java:105
)
02-03 16:42:44.270: ERROR/AndroidRuntime(395): at
android.view.View.performClick(View.java:2344)
02-03 16:42:44.270: ERROR/AndroidRuntime(395): at
android.view.View.onTouchEvent(View.java:4133)
02-03 16:42:44.270: ERROR/AndroidRuntime(395): at
android.widget.TextView.onTouchEvent(TextView.java:6504)
02-03 16:42:44.270: ERROR/AndroidRuntime(395): at
android.view.View.dispatchTouchEvent(View.java:3672)
02-03 16:42:44.270: ERROR/AndroidRuntime(395): at
android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:882)
02-03 16:42:44.270: ERROR/AndroidRuntime(395): at
android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:882)
02-03 16:42:44.270: ERROR/AndroidRuntime(395): at
android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:882)
02-03 16:42:44.270: ERROR/AndroidRuntime(395): at
android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:882)
02-03 16:42:44.270: ERROR/AndroidRuntime(395): at
com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEv
ent(PhoneWindow.java:1712)
02-03 16:42:44.270: ERROR/AndroidRuntime(395): at
com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneW
indow.java:1202)
02-03 16:42:44.270: ERROR/AndroidRuntime(395): at
android.app.Activity.dispatchTouchEvent(Activity.java:1987)
02-03 16:42:44.270: ERROR/AndroidRuntime(395): at
com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(P
honeWindow.java:1696)
02-03 16:42:44.270: ERROR/AndroidRuntime(395): at
android.view.ViewRoot.handleMessage(ViewRoot.java:1658)
02-03 16:42:44.270: ERROR/AndroidRuntime(395): at
android.os.Handler.dispatchMessage(Handler.java:99)
02-03 16:42:44.270: ERROR/AndroidRuntime(395): at
android.os.Looper.loop(Looper.java:123)
02-03 16:42:44.270: ERROR/AndroidRuntime(395): at
android.app.ActivityThread.main(ActivityThread.java:4203)
02-03 16:42:44.270: ERROR/AndroidRuntime(395): at
java.lang.reflect.Method.invokeNative(Native Method)
02-03 16:42:44.270: ERROR/AndroidRuntime(395): at
java.lang.reflect.Method.invoke(Method.java:521)
02-03 16:42:44.270: ERROR/AndroidRuntime(395): at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:
791)
02-03 16:42:44.270: ERROR/AndroidRuntime(395): at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:549)
02-03 16:42:44.270: ERROR/AndroidRuntime(395): at
dalvik.system.NativeStart.main(Native Method)
The crash happens because com.android.internal.app.ResolverActivity
is
trying to find a (single) component which resolves the following intent:
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
Please note that this has been tested BOTH with the AppInstaller, and the actual Marketplace on a real device.
回答1:
The workaround solution from Mike worked for me:
Note that the activity-alias tag must be declared after the activity tag you are referring to (n the xml).
see http://code.google.com/p/android/issues/detail?id=6579
Comment 2 by Moussa.Mike, Mar 30, 2010
For a proper workaround add this activity-alias to your manifest:
<activity-alias android:name="com.android.internal.app.ResolverActivity"
android:targetActivity=".Main" android:exported="true">
Replace .Main
with your .ClassName that you want to launch as the default when the
Open button is hit in this one case
回答2:
I would imagine the problem is having two android.intent.action.MAIN
activities. Both cannot be the main Activity
for your task — you need to decide on one.
Otherwise, if you want to have multiple launcher icons, then retaining the android.intent.category.LAUNCHER
categories is fine.
来源:https://stackoverflow.com/questions/2244781/after-downloading-an-application-with-two-launcher-components-from-the-marketpla