Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

App Crashing when to use obserserver two times #7

Open
burhankhanzada opened this issue Sep 6, 2020 · 1 comment
Open

App Crashing when to use obserserver two times #7

burhankhanzada opened this issue Sep 6, 2020 · 1 comment
Assignees
Labels
error There is an error in the project

Comments

@burhankhanzada
Copy link

Describe the bug
My app is based on single architecture activity so there for only one activity and many fragments so I initialized orb instance in activity a store its reference to ViewModel to use it my all fragments but app gettings crash when I try to add another observer see log cat

Process: com.example.app, PID: 2606
    android.net.ConnectivityManager$TooManyRequestsException
        at android.net.ConnectivityManager.convertServiceException(ConnectivityManager.java:3378)
        at android.net.ConnectivityManager.sendRequestForNetwork(ConnectivityManager.java:3564)
        at android.net.ConnectivityManager.registerNetworkCallback(ConnectivityManager.java:3885)
        at android.net.ConnectivityManager.registerNetworkCallback(ConnectivityManager.java:3866)
        at com.ezralazuardy.orb.OrbEngine.registerNetworkCallback(OrbEngine.kt:125)
        at com.ezralazuardy.orb.OrbEngine.onActive(OrbEngine.kt:62)
        at androidx.lifecycle.LiveData.changeActiveCounter(LiveData.java:390)
        at androidx.lifecycle.LiveData$ObserverWrapper.activeStateChanged(LiveData.java:466)
        at androidx.lifecycle.LiveData$LifecycleBoundObserver.onStateChanged(LiveData.java:425)
        at androidx.lifecycle.LifecycleRegistry$ObserverWithState.dispatchEvent(LifecycleRegistry.java:354)
        at androidx.lifecycle.LifecycleRegistry.addObserver(LifecycleRegistry.java:196)
        at androidx.lifecycle.LiveData.observe(LiveData.java:205)
        at com.ezralazuardy.orb.Orb.observe(Orb.kt:87)
        at com.example.app.fragments.ViewPagerFragment.showNoBundlesNoInternet(ViewPagerFragment.kt:332)

To Reproduce
Steps to reproduce the behavior:
1.Make orb varaible in ViewModel.kt to use it on fragments

class MainViewModel : ViewModel() {
    lateinit var orb: Orb
    var networkState: Boolean = false
}

2.In MainActivity.kt

class MainActivity : AppCompatActivity(R.layout.main_activity) {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        val mainViewModel: MainViewModel by viewModels()
        mainViewModel.orb = Orb.with(this)
        mainViewModel.orb.observe {
            mainViewModel.networkState = it.connected
        }
    }
}
  1. Use in ViewPagerFragment
class ViewPagerFragment : Fragment() {
    private val mainViewModel: MainViewModel by activityViewModels()
    private val orb by lazy { mainViewModel.orb }

    //...

private fun showNoBundlesNoInternet() {
        if (mainViewModel.networkState) showNoBundles()
        else {
            showNoInternet()
            mainViewModel.orb.observe {
                if (it.connected) {
                    //...
                } else {
                    //...
                }
            }
        }
    }

Expected behavior
The expected behavior is adding more than one observer should not crash the app

@ezralazuardy
Copy link
Owner

I'll investigate this issue. thanks for reporting.

@burhankhanzada burhankhanzada changed the title App Crashing when to to use obserserver to times App Crashing when to use obserserver two times Sep 7, 2020
@ezralazuardy ezralazuardy self-assigned this Nov 19, 2020
@ezralazuardy ezralazuardy added bug Something isn't working error There is an error in the project labels Nov 19, 2020
@ezralazuardy ezralazuardy removed the bug Something isn't working label Apr 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
error There is an error in the project
Projects
None yet
Development

No branches or pull requests

2 participants