3

I want to be able to click on a widget and launch a dialog box. I have read the official documentation as some of the unofficial ones. I initially wanted to launch a new activity but even this fails. I get the following in Logcat but I cant really see anything.

11-14 21:28:47.929: INFO/ActivityManager(116): Starting: Intent { flg=0x10000000 cmp=com.android.app/.Execute bnds=[179,89][300,160] } from pid -1

I guess the above means that the intent was passed... But the activity was actually not started. Should the activity to be started be a normal one?

The code used is:

public class ExampleAppWidgetProvider extends AppWidgetProvider {

public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
    final int N = appWidgetIds.length;

    // Perform this loop procedure for each App Widget that belongs to this provider
    for (int i=0; i<N; i++) {
        int appWidgetId = appWidgetIds[i];

        // Create an Intent to launch ExampleActivity
        Intent intent = new Intent(context, ExampleActivity.class);
        PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);

        // Get the layout for the App Widget and attach an on-click listener
        // to the button
        RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.appwidget_provider_layout);
        views.setOnClickPendingIntent(R.id.button, pendingIntent);

        // Tell the AppWidgetManager to perform an update on the current app widget
        appWidgetManager.updateAppWidget(appWidgetId, views);
    }
}
}

Any thoughts?

4
  • Any luck with this? I'm observing it too. I'm seeing this too -when I try to launch an activity with a notification I've put from one of my application. I guess it has something to do with the process id being shown as -1 Generally whenever some other activity is launched via an intent, the process id is not as -1, but some different number as assigned by OS.. Nov 16, 2011 at 8:18
  • My problem has been solved.. The pid being -1 had nothing to do with it.. My actual problem was that I had a typo in my code.. instead of typing as "XYZActivity", I had written "XYZACtivity" (Notice the capital C) and since it was specified as a String, there were no errors thrown by Android.. Maybe there is something similar in your case as well ? Nov 16, 2011 at 11:55
  • So, what was the -1 about? Do you mean the activity you wanted to start was misspelled? I dont see any misspellings. How the activity to be launched on widget click treats the intend? Or is this irrelevant? Nov 17, 2011 at 12:12
  • For first question -No idea.. I think it is alloted to Notification Bar's process..as it always prints -1 for anything launched via Notification bar. Second -Yes I had misspelled the name. I had given the name using setClassName() method, and since it was String, there were no Compile-time errors. And regarding the remaining questions related to the widget part, I'm sorry but I do not have any idea on those.. :( Maybe some knowledgeable person might be able to help you with that :) Nov 21, 2011 at 8:34

1 Answer 1

2

The most likely cause of the problem would be that you haven't declared ExampleActivity in your Manifest.

<UPDATE>

You could also try using a unique number for argument 2 of your PendingIntent creation and also put a sensible flag in argument 4:

    PendingIntent pendingIntent = PendingIntent.getActivity(context, appWidgetId, intent, PendingIntent.FLAG_UPDATE_CURRENT );
2
  • i tried that as well. Nothing changed. Is there is any possibility that the activity that is trying to be executed is not coded as intended? I mean is there is something special that i need to include in the new activity to be launched? Nov 17, 2011 at 12:23
  • Well, you need to handle the Intent that's being added to the PendingIntent. You have properly defined ExampleActivity in your Manifest, haven't you? Nov 18, 2011 at 12:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.