Sto provando a creare un widget semplice con un pulsante che avvia uno Service
con OnClickPendingIntent()
. Posso iniziare bene, ma non riesco a capire un modo per fermarlo (so che posso farlo con un BroadcastReceiver
o qualcosa di simile, ma vorrei evitare l'hardcode).PendingIntent per avviare e interrompere un servizio
Questo è il mio codice:
Intent intent = new Intent(context, myService.class);
PendingIntent pendingIntent = PendingIntent.getService(context, 0, intent, 0);
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.my_widget);
if (!ismyserviceup(context)) {
views.setOnClickPendingIntent(R.id.my_button, pendingIntent);
} else {
// i need to stop it!!!!
}