coder_For_Life22
coder_For_Life22

Reputation: 26971

How to reference widget inside of a Service?

How to i i set the TextView and ProgressBar to their findViewById views from inside a service?>

 ProgressBar dialog;

TextView Titletext;


@Override
public IBinder onBind(Intent intent) {
    // TODO Auto-generated method stub
    return null;
}
@Override
public void onCreate(){
    super.onCreate();
    Log.e("StackWidgetService", "Inside of onCreate in Widget Service");

    getter fethcer = new getter();
    fethcer.execute();

}

Upvotes: 1

Views: 133

Answers (1)

user658042
user658042

Reputation:

Just get a reference to the AppWidgetManager and update the layout.

AppWidgetManager awm = AppWidgetManager.getInstance(context);
int[] appWidgetIds = awm.getAppWidgetIds(yourProviderComponentName);
RemoteViews rv = new RemoteViews(context.getPackageName(), R.layout.thelayout);
// Construct the remote views here ...

awm.updateAppWidget(appWidgetIds[0], rv);

This example only updates the layout of the first widget instance (appWidgetIds[0]) or probably even crashes if there is no widget. Usually you have to loop over the appWidgetIds-array and update each one individually; or skip the loop if no widget instance is present.

Upvotes: 2

Related Questions