views:

340

answers:

2

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.

A: 
Christopher
If i remove the Main, crash go away but doesn't server the purpose what i want to do. I would like to have two different Icons on application tray so that i can start different activities.Icon only show up in tray if we define the intent with Main and Launcher.e.g. <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> I have seen same type of filter used for DialtactsActivity(android source).
Issue 6579:After downloading an application with two Launcher components from theMarketplace, clicking "Open" will cause a crash http://code.google.com/p/android/issues/detail?id=6579
No, read the Contacts source again. They use an `<activity-alias>`, so only **one** actual `Activity` is the `MAIN` one.
Christopher
Thanks for pointing that. I did try that, but i still see the crash.So i was not sure whether ALIAS is necessary to achieve what i want to do. I want to add more things, looks like space is very limited for adding comments.
<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"> </activity> <activity-alias android:label="@string/app_name" android:name="TestActivity03"android:targetActivity="TestActivity02"android:icon="@drawable/Test2"><intent-filter><action android:name="android.intent.action.MAIN" /><category android:name="android.intent.category.LAUNCHER" /></intent-filter> </activity-alias>
You can edit your original question to provide updates. Your problem there is that you still have two distinct Activities with a `MAIN` action.
Christopher
Thanks. If i remove the MAIN, i don't see the two icons on the application tray. FYI..if i load the application using ADB everything works. So it proves something is broken when we start the application from the market place/app installer.But this is the way how DialtactsContactsEntryActivity defined.<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>
http://developer.android.com/intl/fr/guide/topics/fundamentals.html#acttaskAn activity is set up as the entry point for a task by giving it an intent filter with "android.intent.action.MAIN" as the specified action and "android.intent.category.LAUNCHER" as the specified category. (There's an example of this type of filter in the earlier Intent Filters section.) A filter of this kind causes an icon and label for the activity to be displayed in the application launcher, giving users a way both to launch the task and to return to it at any time after it has been launched.
A: 

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

Felix Jost