3

I am able to start Activity class on click of widget button, but when try same for start service it's not working, let me know how can i call start service here.

thanks

CoDe
  • 11,056
  • 14
  • 90
  • 197

2 Answers2

0

Use this line of code

startService(new Intent(this, YOUR_SERVICE_CLASS_NAME.class)); 
Sherif elKhatib
  • 45,786
  • 16
  • 89
  • 106
-1

Try this code man

Intent i = new Intent(this, MyWidget.class);
PendingIntent pi = PendingIntent.getBroadcast(context,0, i,0);
RemoteViews updateView = new RemoteViews(context.getPackageName(),R.layout.n);
updateViews.setOnClickPendingIntent(R.id.update_button,pi);
kannappan
  • 2,250
  • 3
  • 25
  • 35
  • it's for simple activity button, but let me know how can we do this using widget Button – CoDe Aug 02 '11 at 10:19
  • 1
    @Shubh, have u find solution ? I am facing similar issue, my event for widget button lost as service is not started. – JRC Jan 09 '12 at 10:27
  • @JRC It's long back but not remember correctly but you can check [button widget click not working](http://stackoverflow.com/a/9243146/2624806), [Start Stop Service from Widget](http://stackoverflow.com/a/17515418/2624806), OR from [this](http://stackoverflow.com/a/2957442/2624806). – CoDe Aug 10 '16 at 05:26