Skip to content Skip to sidebar Skip to footer

Start Activity By Clicking On Widget

I newbie at programming Android and I try to do a widget which has be able get some data from ISP about my account. There are a lot of unknown things how to do it, but I have did a

Solution 1:

Use this snippet in onUpdate() method of your widget AppWidgetProvider class:

@OverridepublicvoidonUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
    RemoteViewsremoteViews=newRemoteViews(context.getPackageName(), R.layout.widgetlayout);
    IntentconfigIntent=newIntent(context, Activity.class);

    PendingIntentconfigPendingIntent= PendingIntent.getActivity(context, 0, configIntent, 0);

    remoteViews.setOnClickPendingIntent(R.id.widget, configPendingIntent);
    appWidgetManager.updateAppWidget(appWidgetIds, remoteViews);
}     

Here widgetlayout is name of your widget layout and R.id.widget is it's parent layout id.

Edit: Now,I see your code that you added to your question.You would to do:

PendingIntent.getActivity(context, 0, configIntent, 0);

(that start's activity) instead of

PendingIntent.getService(...);

that attempt to starts service.Good luck.

References: doityourselfandroid.com

helloandroid.com

Solution 2:

Intentinet=newIntent(your_action);
inet.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntentpIntentNetworkInfo= PendingIntent.getActivity(context, 2, 
            inet, Intent.FLAG_ACTIVITY_NEW_TASK);
remoteViews.setOnClickPendingIntent(you_component_when_the_user_pressing_this_activity_should_start, pIntentNetworkInfo);

Solution 3:

I don't know about "Creating widget from another widget". This is out of my knowledge but I suggest you to build your own widget.

Apart from that, calling activity from widget should be using PendingIntent

Here is simple example to do it

IntentiSetting=newIntent(this, MyConfig.class);
PendingIntentpiSetting= PendingIntent.getActivity(this, 0, iSetting, 0);
views.setOnClickPendingIntent(R.id.IdComponent, piSetting);

Or you might need to see this link and this link

Post a Comment for "Start Activity By Clicking On Widget"