public class GrayService extends Service {
private final static int GRAY_SERVICE_ID = 1001 ;
@Override
public int onStartCommand (Intent intent, int flags, int startId) {
if (Build.VERSION.SDK_INT < 18 ) {
startForeground(GRAY_SERVICE_ID, new Notification());
} else {
Intent innerIntent = new Intent(this , GrayInnerService.class);
startService(innerIntent);
startForeground(GRAY_SERVICE_ID, new Notification());
}
return super .onStartCommand(intent, flags, startId);
}
public static class GrayInnerService extends Service {
@Override
public int onStartCommand (Intent intent, int flags, int startId) {
startForeground(GRAY_SERVICE_ID, new Notification());
stopForeground(true );
stopSelf();
return super .onStartCommand(intent, flags, startId);
}
}
}