I am working my way through oh my first widget (so this is 1.5,
obviously) and I'm stuck. I've poked around a problem involving the
launch of an Activity when clicking on a widget. Scenario: User drags
widget on home screen without prior launch of the Activity in
question. I am following this post:
http://android-developers.blogspot.com/2009/04/introducing-home-screen-widgets-and.html
Instead of launching the browser through ACTION_VIEW, I am trying to
launch an Activity by class. I've toyed around with different Intent
settings, but no luck.

The following snipped shows the launch log
<------------------ Sanitized log launching Activity
---------------------->
05-19 04:28:56.173: INFO/ActivityManager(571): Starting activity:
Intent { action=android.intent.action.MAIN categories=
{android.intent.category.LAUNCHER} flags=0x10200000 comp=
{com.mycompany.myapp/com.mycompany.myapp.MainClass} }
<------------------ Sanitized log ---------------------->
This is identical to a regular launch from the home screen. Below the
code that I use to launch the Activity:

<------------------ Sanitized code snipped from class that extends
AppWidgetProvider (MyWidgetProvider) ------->
@Override
public void onUpdate(Context context, AppWidgetManager
appWidgetManager, int[] appWidgetIds) {

        super.onUpdate(context, appWidgetManager, appWidgetIds);

        Intent defineIntent = new Intent(Intent.ACTION_MAIN);
        defineIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK +
Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
        defineIntent.addCategory("android.intent.category.LAUNCHER");
        defineIntent.setClassName(context, "com.mycompany.myapp.MainClass");

        PendingIntent pendingIntent = PendingIntent.getActivity
(context,
               0 , defineIntent, 0);
        updateViews.setOnClickPendingIntent(R.id.widget,
pendingIntent);

        // Push updates to the home screen
        ComponentName thisWidget = new ComponentName(context,
MyWidgetProvider.class);
        AppWidgetManager manager = AppWidgetManager.getInstance
(context);
        manager.updateAppWidget(thisWidget, updateViews);
}
<------------------ Sanitized code snipped ------->

Here's what happens (I test emulator only at this point): Upon the
first click, the Activity crashes. Dialog box: "Sorry! The application
MyApp (process (com.mycompany.myapp) has stopped unexpectedly. Please
try again."
With the second tap on the widget, the Activity launches. So I assume
I've got the correct intent filter settings. Below the log following
the first tap:

<---------------- Sanitized class not found log ----------------->
05-19 05:03:25.897: ERROR/AndroidRuntime(688): Uncaught handler:
thread main exiting due to uncaught exception
05-19 05:03:25.996: ERROR/AndroidRuntime(688):
java.lang.RuntimeException: Unable to instantiate activity
ComponentInfo{com.mycompany.myapp/com.mycompany.myapp.MainClass}:
java.lang.ClassNotFoundException: com.mycompany.myapp.MainClassin
loader dalvik.system.pathclassloa...@43594610
05-19 05:03:25.996: ERROR/AndroidRuntime(688):     at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:
2194)
05-19 05:03:25.996: ERROR/AndroidRuntime(688):     at
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:
2284)
05-19 05:03:25.996: ERROR/AndroidRuntime(688):     at
android.app.ActivityThread.access$1800(ActivityThread.java:112)
05-19 05:03:25.996: ERROR/AndroidRuntime(688):     at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1692)
05-19 05:03:25.996: ERROR/AndroidRuntime(688):     at
android.os.Handler.dispatchMessage(Handler.java:99)
05-19 05:03:25.996: ERROR/AndroidRuntime(688):     at
android.os.Looper.loop(Looper.java:123)
05-19 05:03:25.996: ERROR/AndroidRuntime(688):     at
android.app.ActivityThread.main(ActivityThread.java:3948)
05-19 05:03:25.996: ERROR/AndroidRuntime(688):     at
java.lang.reflect.Method.invokeNative(Native Method)
05-19 05:03:25.996: ERROR/AndroidRuntime(688):     at
java.lang.reflect.Method.invoke(Method.java:521)
05-19 05:03:25.996: ERROR/AndroidRuntime(688):     at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run
(ZygoteInit.java:782)
05-19 05:03:25.996: ERROR/AndroidRuntime(688):     at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:540)
05-19 05:03:25.996: ERROR/AndroidRuntime(688):     at
dalvik.system.NativeStart.main(Native Method)
05-19 05:03:25.996: ERROR/AndroidRuntime(688): Caused by:
java.lang.ClassNotFoundException: com.mycompany.myapp.MainClassin
loader dalvik.system.pathclassloa...@43594610
05-19 05:03:25.996: ERROR/AndroidRuntime(688):     at
dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
05-19 05:03:25.996: ERROR/AndroidRuntime(688):     at
java.lang.ClassLoader.loadClass(ClassLoader.java:573)
05-19 05:03:25.996: ERROR/AndroidRuntime(688):     at
java.lang.ClassLoader.loadClass(ClassLoader.java:532)
05-19 05:03:25.996: ERROR/AndroidRuntime(688):     at
android.app.Instrumentation.newActivity(Instrumentation.java:1097)
05-19 05:03:25.996: ERROR/AndroidRuntime(688):     at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:
2186)
05-19 05:03:25.996: ERROR/AndroidRuntime(688):     ... 11 more
<---------------- Sanitized class not found log ----------------->

After trying different configurations I've run out of ideas. Thanks in
advance for your help!

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to