Q:

How to makes repeated background request to server in android O and above

I have an app doing request to the server every 30 seconds. I makes it using service. After changing the target version to the 26, service stop working in the background. Now I start service using ContextCompat.startForegroundService(context, startIntent) but this approach requires to show notification in the status bar. WorkManager did not help me, because it have a minimum period of 15 min. There is some way to make background requests every 30 sec without showing a notification?

A:

You can use RxJava to do a task repeatedly.
Observable.timer(30, TimeUnit.SECONDS).subscribeOn(Schedulers.io()).repeat()
                    .observeOn(AndroidSchedulers.mainThread()).subscribe(object : Observer<Long> {
                    override fun onComplete() {}

                    override fun onSubscribe(d: Disposable) {}

                    override fun onNext(t: Long) {
                       //do your task
                    }

                    override fun onError(e: Throwable) {}
                })

