[android-beginners] Problem with AppWidget Using a Service

2010-06-23 Thread Jake Colman

I am trying to create a simple AppWidget using a service to initialize
the content in the onUpdate() method.  The data is not being refreshed
and logcat shows me the following warning:

AppWidgetService  W  updateAppWidgetProvider: provider doesn't exist:
ComponentInfo{com.jnc.zmanminder/com.jnc.zmanminder.ZMUpdateService}

I must be missing something obvious but I cannot figure it out.

My AppWidget class (edited for brevity) looks as follows:

public class ZmanMinderAppWidget extends AppWidgetProvider {
  public void onUpdate(Context context,
AppWidgetManager appWidgetManager, int[] appWidgetIds) {
context.startService(new Intent(context, ZMUpdateService.class));
  }
}

My Service class (edited for brevity) looks as follows:

public class ZMUpdateService extends Service {
  public void onStart(Intent intent, int startId) {
RemoteViews updateViews = buildUpdate(this);
ComponentName thisWidget = new ComponentName(this, ZMUpdateService.class);
AppWidgetManager manager = AppWidgetManager.getInstance(this);
manager.updateAppWidget(thisWidget, updateViews);
  }

  public IBinder onBind(Intent arg0) {
return null;
  }

  public RemoteViews buildUpdate(Context context) { 
Time time = new Time();
time.setToNow();
RemoteViews views = new 
RemoteViews(context.getPackageName(),R.layout.widget);
views.setTextViewText(R.id.time, time.format(%I:%M%p));
return views;
  }
}

The ZMUpdateService service is defined in my manifest file.

Thanks for any help.

...Jake


-- 
Jake Colman | Director, Software Development
Principia Partners LLC
101 West Elm Street | Conshohocken | PA 19428 | +1 (610) 755 9770
t: +1 (610) 755 9786 | c: +1 (610) 348 2788 | f: +1 (201) 221 8929
e: col...@ppllc.com | w: www.principiapartners.com
Credit technology innovation awards winner 2008 and 2009

-- 
You received this message because you are subscribed to the Google
Groups Android Beginners group.

NEW! Try asking and tagging your question on Stack Overflow at
http://stackoverflow.com/questions/tagged/android

To unsubscribe from this group, send email to
android-beginners+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en


Re: [android-beginners] Problem with AppWidget Using a Service

2010-06-23 Thread Kostya Vasilyev

Jake,

The error is in the way your code instantiates ComponentName.

Instead of:

ComponentName thisWidget = new ComponentName(this, ZMUpdateService.class);


Do this:

ComponentName thisWidget = new ComponentName(this,*ZmanMinderAppWidget*.class);


The error message was trying to convey same thing...

-- Kostya

23.06.2010 17:39, Jake Colman ?:

I am trying to create a simple AppWidget using a service to initialize
the content in the onUpdate() method.  The data is not being refreshed
and logcat shows me the following warning:

AppWidgetService  W  updateAppWidgetProvider: provider doesn't exist:
ComponentInfo{com.jnc.zmanminder/com.jnc.zmanminder.ZMUpdateService}

I must be missing something obvious but I cannot figure it out.

My AppWidget class (edited for brevity) looks as follows:

public class ZmanMinderAppWidget extends AppWidgetProvider {
   public void onUpdate(Context context,
 AppWidgetManager appWidgetManager, int[] appWidgetIds) {
 context.startService(new Intent(context, ZMUpdateService.class));
   }
}

My Service class (edited for brevity) looks as follows:

public class ZMUpdateService extends Service {
   public void onStart(Intent intent, int startId) {
 RemoteViews updateViews = buildUpdate(this);
 ComponentName thisWidget = new ComponentName(this, ZMUpdateService.class);
 AppWidgetManager manager = AppWidgetManager.getInstance(this);
 manager.updateAppWidget(thisWidget, updateViews);
   }

   public IBinder onBind(Intent arg0) {
 return null;
   }

   public RemoteViews buildUpdate(Context context) {
 Time time = new Time();
 time.setToNow();   
 RemoteViews views = new 
RemoteViews(context.getPackageName(),R.layout.widget);
 views.setTextViewText(R.id.time, time.format(%I:%M%p));
 return views;
   }
}

The ZMUpdateService service is defined in my manifest file.

Thanks for any help.

...Jake


   



--
Kostya Vasilev -- WiFi Manager + pretty widget -- http://kmansoft.wordpress.com

--
You received this message because you are subscribed to the Google
Groups Android Beginners group.

NEW! Try asking and tagging your question on Stack Overflow at
http://stackoverflow.com/questions/tagged/android

To unsubscribe from this group, send email to
android-beginners+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en


Re: [android-beginners] Problem with AppWidget Using a Service

2010-06-23 Thread Mark Murphy
On Wed, Jun 23, 2010 at 9:39 AM, Jake Colman col...@ppllc.com wrote:
 I am trying to create a simple AppWidget using a service to initialize
 the content in the onUpdate() method.  The data is not being refreshed
 and logcat shows me the following warning:

 AppWidgetService  W  updateAppWidgetProvider: provider doesn't exist:
 ComponentInfo{com.jnc.zmanminder/com.jnc.zmanminder.ZMUpdateService}

This means you are trying to state that ZMUpdateService is an
AppWidgetProvider, in one or more places in your code.

 public class ZMUpdateService extends Service {
  public void onStart(Intent intent, int startId) {
    RemoteViews updateViews = buildUpdate(this);
    ComponentName thisWidget = new ComponentName(this, ZMUpdateService.class);

Note: you are claiming your AppWidgetProvider is ZMUpdateService, when
it is really ZmanMinderAppWidget.

If it helps, here is a complete app widget example:

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

It assumes you have an identi.ca account you can use.

-- 
Mark Murphy (a Commons Guy)
http://commonsware.com | http://github.com/commonsguy
http://commonsware.com/blog | http://twitter.com/commonsguy

_The Busy Coder's Guide to *Advanced* Android Development_ Version 1.6
Available!

-- 
You received this message because you are subscribed to the Google
Groups Android Beginners group.

NEW! Try asking and tagging your question on Stack Overflow at
http://stackoverflow.com/questions/tagged/android

To unsubscribe from this group, send email to
android-beginners+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en