I\'m trying to do something which really ought to be quite easy, but it\'s driving me crazy. I\'m trying to launch an activity when a home screen widget is pressed, such as
This worked for me, based on info here, the word widget sample, and the tutorial here
Intent intent = new Intent(Intent.ACTION_MAIN, null);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
// first param is app package name, second is package.class of the main activity
ComponentName cn = new ComponentName("com....","com...MainActivity");
intent.setComponent(cn);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent myPI = PendingIntent.getActivity(context, 0, intent, 0);
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget_word);
views.setOnClickPendingIntent(R.id.widget, myPI);
AppWidgetManager mgr = AppWidgetManager.getInstance(context);
mgr.updateAppWidget(comp, views);