Skip to content Skip to sidebar Skip to footer

Launching An Activity From An Appwidget

How do i launch an activity from an AppWidget? I want to give the user the ability to edit its settings.

Solution 1:

All the AppWidget methods have a Context: you can use that to create an Intent to launch your Activity.

EDIT: strictly speaking, you don't even need the Context (just create an Intent and then call startActivity).

Solution 2:

you can find a lot of examples around the internet this example is excellent courtesy of Mark Murphy

https://github.com/commonsguy/cw-advandroid/tree/master/AppWidget

Solution 3:

You have to do something like this:

Intentintent=newIntent(context, MainWidgetActivity.class);
PendingIntentpendingIntent= PendingIntent.getActivity(context, 0, intent, 0);

// Get the layout for the App Widget and attach an on-click listener// to the buttonRemoteViewsrv=newRemoteViews(context.getPackageName(), R.layout.appwidget);
rv.setOnClickPendingIntent(R.id.button, pendingIntent);

while MainWidgetActivity.class is the Activity you want to launch

Post a Comment for "Launching An Activity From An Appwidget"