can you provide me some link how to deal with widget ids?

On Fri, Jun 24, 2011 at 3:11 AM, Kostya Vasilyev <[email protected]> wrote:

> You're almost there with your code.
>
> The pending intent should relate to something in your code which would
> update the widget.
>
> You don't have to wait for onUpdate (which is called by "the system" when
> needed), rather you can get the AppWidgetManager yourself and make an update
> at any time.
>
> You will need to either know the widget Id(s) you're going to update, or
> update all of them by using AppWidgetManager.update that takes a
> ComponentName.
>
> -- Kostya
>
> 2011/6/24 Hitendrasinh Gohil <[email protected]>
>
>> Hi,
>>
>> I have made three classess.
>>
>> MainActivity
>> AppWidgetService
>> AppWidget
>>
>> As i am able to update widget from activity through service.I have one
>> button in wiget.i want to update widget onclick of the button.
>> Here is my code for AppWidgetService.
>> package com.widget.main;
>>
>> import android.app.IntentService;
>> import android.app.PendingIntent;
>> import android.appwidget.AppWidgetManager;
>> import android.content.ComponentName;
>> import android.content.Intent;
>> import android.widget.RemoteViews;
>>
>> public class AppWidgetService extends IntentService {
>>
>>        public AppWidgetService() {
>>                super("AppWidgetService");
>>                // TODO Auto-generated constructor stub
>>        }
>>
>>        @Override
>>        protected void onHandleIntent(Intent intent) {
>>                ComponentName componentName = new ComponentName(this,
>> AppWidget.class);
>>                RemoteViews remoteViews = new
>> RemoteViews("com.widget.main",
>>                                R.layout.appwidget);
>>                AppWidgetManager appWidgetManager =
>> AppWidgetManager.getInstance(this);
>>
>>                remoteViews.setTextViewText(R.id.TextView01,
>>
>>  MainActivity.listarray[MainActivity.currentIndex]);
>>
>>                Intent activityIntent = new Intent(this,
>> MainActivity.class);
>>                PendingIntent pendingIntent = PendingIntent.getActivity(
>>                                getApplicationContext(), 0, activityIntent,
>>                                PendingIntent.FLAG_UPDATE_CURRENT);
>>                remoteViews.setOnClickPendingIntent(R.id.ImageView01,
>> pendingIntent);
>>
>> /*              Intent serviceIntent = new Intent(this,
>> AppWidgetService.class);
>>                PendingIntent pendingserviceIntent =
>> PendingIntent.getService(
>>                                getApplicationContext(), 0,
>> serviceIntent,PendingIntent.FLAG_UPDATE_CURRENT);
>>
>>
>>
>> remoteViews.setOnClickPendingIntent(R.id.ImageButton01,pendingserviceIntent);*/
>>
>>                appWidgetManager.updateAppWidget(componentName,
>> remoteViews);
>>        }
>>
>> }
>> and here is my code for widget class.
>> package com.widget.main;
>>
>> import android.appwidget.AppWidgetManager;
>> import android.appwidget.AppWidgetProvider;
>> import android.content.Context;
>> import android.content.Intent;
>>
>> public class AppWidget extends AppWidgetProvider
>> {
>>        public void onUpdate(Context context,AppWidgetManager
>> appWidgetManager,int[] appWidgetIds)
>>        {
>>                super.onUpdate(context, appWidgetManager, appWidgetIds);
>>                context.startService(new
>> Intent(context,AppWidgetService.class));
>>        }
>> }
>>
>> so how can i update widget when click on widget button?
>>
>> --
>> 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
>
>
>  --
> 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
>



-- 
Regards,
Hitendrasinh Gohil

-- 
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