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