Android service not working -
i'm trying call service class update value of variable widget doesn't ever seem service class. i've had @ examples , can't figure out i'm doing wrong, , don't know services yet. appreciated.
service class
public class togglemonitoringservice extends service{ @override public ibinder onbind(intent intent) { return null; } @override public void oncreate() { log.d("me","creating service"); super.oncreate(); } @override public int onstartcommand(intent intent, int startid, int something) { // todo auto-generated method stub string toggle = intent.getextras().getstring("toggle"); log.d("me","toggle : " + toggle); if (toggle.equals("app1")) { updatewidgetservice.monitorapp1 = !updatewidgetservice.monitorapp1; } else if (toggle.equals("app2")) { updatewidgetservice.monitorapp2 = !updatewidgetservice.monitorapp2; } super.onstartcommand(intent, startid, something); return 0; } }
where set intent , pending intent handle button click widget
intent monitor1toggle = new intent(this.getapplicationcontext(),togglemonitoringservice.class); monitor1toggle.setaction(appwidgetmanager.action_appwidget_update); monitor1toggle.putextra(appwidgetmanager.extra_appwidget_ids,allwidgetids); monitor1toggle.putextra("toggle","app1"); pendingintent monitor1 = pendingintent.getservice(getapplicationcontext(), 0 , monitor1toggle,0); remoteviews.setonclickpendingintent(r.id.firstappstatus, monitor1);
try start service manually, wihtout using pendingintent
. better way not start service each time need something, start once, bind , use common method calls when need service.
for example simple thread
more appropriate.
Comments
Post a Comment