pwittchen / ReactiveNetwork

Android library listening network connection state and Internet connectivity with RxJava Observables
http://pwittchen.github.io/ReactiveNetwork/docs/RxJava2.x/
Apache License 2.0
2.53k stars 276 forks source link

Delay in getting response #374

Closed VahidGarousi closed 4 years ago

VahidGarousi commented 4 years ago

Why does it take so long?

import android.os. import android.widget. import androidx.appcompat.app. import com.github.pwittchen.reactivenetwork.library.rx2. import com.google.android.material.snackbar. import com.setarehaa.app.seshomareh.exception. import com.teifapp.app.feature.internet_check. import io.reactivex.android.schedulers. import io.reactivex.disposables. import io.reactivex.plugins. import io.reactivex.schedulers.*

abstract class BaseActivity : AppCompatActivity() { protected var compositeDisposable = CompositeDisposable() var single = ReactiveNetwork.checkInternetConnectivity()

fun showError(message: String) {
    Toast.makeText(this, "" + message, Toast.LENGTH_SHORT).show()
}

fun showSnackBar(message: String) {
    Snackbar.make(findViewById(getCoordinatorLayout()), message, Snackbar.LENGTH_LONG).show()
}

abstract fun getCoordinatorLayout(): Int
override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    RxJavaPlugins.setErrorHandler {
        ExceptionMessageFactory.getMessage(it)
    }
}

abstract fun setupViews(savedInstanceState: Bundle?)
fun showToast(message: String) = Toast.makeText(this, message, Toast.LENGTH_SHORT).show()
override fun onStart() {
    super.onStart()
    compositeDisposable.add(
        ReactiveNetwork
            .observeInternetConnectivity()
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe { isConnectedToInternet ->
                if (isConnectedToInternet) {

                } else {
                    DialogInternetConnection.showDialog(supportFragmentManager)
                }
            })
}

}`

pwittchen commented 4 years ago

What do you mean by "so long"? Time of the response depends on your network and internet connection and its speed.

-- Piotr Wittchen, http://wittchen.io

wt., 10 wrz 2019, 18:11 użytkownik Vahid Garousi notifications@github.com napisał:

Why does it take so long?

`package com.teifapp.app.base

import android.os. import android.widget. import androidx.appcompat.app. import com.github.pwittchen.reactivenetwork.library.rx2. import com.google.android.material.snackbar. import com.setarehaa.app.seshomareh.exception. import com.teifapp.app.feature.internet_check. import io.reactivex.android.schedulers. import io.reactivex.disposables. import io.reactivex.plugins. import io.reactivex.schedulers.*

abstract class BaseActivity : AppCompatActivity() { protected var compositeDisposable = CompositeDisposable() var single = ReactiveNetwork.checkInternetConnectivity()

fun showError(message: String) { Toast.makeText(this, "" + message, Toast.LENGTH_SHORT).show() }

fun showSnackBar(message: String) { Snackbar.make(findViewById(getCoordinatorLayout()), message, Snackbar.LENGTH_LONG).show() }

abstract fun getCoordinatorLayout(): Int override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) RxJavaPlugins.setErrorHandler { ExceptionMessageFactory.getMessage(it) } }

abstract fun setupViews(savedInstanceState: Bundle?) fun showToast(message: String) = Toast.makeText(this, message, Toast.LENGTH_SHORT).show() override fun onStart() { super.onStart() compositeDisposable.add( ReactiveNetwork .observeInternetConnectivity() .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe { isConnectedToInternet -> if (isConnectedToInternet) {

            } else {
                DialogInternetConnection.showDialog(supportFragmentManager)
            }
        })

}

}`

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/pwittchen/ReactiveNetwork/issues/374?email_source=notifications&email_token=AAFJYF2S2NPPCQRNME7FIODQI7BJ3A5CNFSM4IVJXU3KYY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4HKPZXFQ, or mute the thread https://github.com/notifications/unsubscribe-auth/AAFJYF4YV2X56522HJ6QRXLQI7BJ3ANCNFSM4IVJXU3A .

VahidGarousi commented 4 years ago

The scenario of my program is that if the Internet was disconnected the phone would display a message box to the user. In this box I redirect the user's message to the Wi-Fi or Mobile Data Settings. But the response time is very long and the user has the opportunity to use the app. I want the box to be displayed quickly.

pwittchen commented 4 years ago

You can configure initial observing interval and observing interval via InternetObservingSettings and decrease default values. It's described in documentation in README.md

-- Piotr Wittchen, http://wittchen.io

wt., 10 wrz 2019, 18:31 użytkownik Vahid Garousi notifications@github.com napisał:

The scenario of my program is that if the Internet was disconnected the phone would display a message box to the user. In this box I redirect the user's message to the Wi-Fi or Mobile Data Settings. But the response time is very long and the user has the opportunity to use the app. I want the box to be displayed quickly.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/pwittchen/ReactiveNetwork/issues/374?email_source=notifications&email_token=AAFJYF3HY4X3HL3SSZUZDYTQI7DVPA5CNFSM4IVJXU3KYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD6LW3KY#issuecomment-530017707, or mute the thread https://github.com/notifications/unsubscribe-auth/AAFJYF4Y2WHOEEQZAEK62MLQI7DVPANCNFSM4IVJXU3A .