Service class:
public class KillNotificationsService extends Service {
public static int NOTIFICATION_ID = 1;
private NotificationManager mNM;
private final IBinder mBinder = new KillBinder(this);
public class KillBinder extends Binder {
public final Service service;
public KillBinder(Service service) {
this.service = service;
}
}
@Override
public IBinder onBind(Intent intent) {
return mBinder;
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
return Service.START_STICKY;
}
@Override
public void onCreate() { }
@Override
public void onTaskRemoved(Intent rootIntent){
mNM = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
mNM.cancel(NOTIFICATION_ID);
}
}
Method within the Activity
private void serviceNotification(){
ServiceConnection mConnection = new ServiceConnection() {
public void onServiceConnected(ComponentName className,IBinder binder) {
((KillNotificationsService.KillBinder) binder).service.startService(new Intent
(MontarTimesActivity.this, KillNotificationsService.class));
NotificationManager mNM = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
mNM.notify(KillNotificationsService.NOTIFICATION_ID, notification().getNotification());
}
public void onServiceDisconnected(ComponentName className) {
}
};
bindService(new Intent(MontarTimesActivity.this, KillNotificationsService.class), mConnection, Context.BIND_AUTO_CREATE);
}
What error have you encountered? Does the method simply not work or some exception is thrown? Have any relevant message in logcat?
– Roney Gomes
@Roneygomes It does not even compile, it gets a red trace under the
@Override
with the words Method does not override method from its superclass and, if I take the@Override
syntax errors disappear, but in the execution it does not enter inside the method.– Eduardo