0

I am using 'RxJava binding APIs for Android UI widgets' to trigger click events on buttons or textview.

PFB code(Edited) that using to trigger the event

class BookAgentActivity : BaseActivity(), BookAgentView {

    @Inject
    @field:Named("activity")
    lateinit var compositeDisposable: CompositeDisposable

    @Inject
    lateinit var bookAgentViewModelFactory: BookAgentViewModelFactory

    private lateinit var bookAgentViewModel: BookAgentViewModel

    private lateinit var cityLocalityJson: CityLocalitiesMO


    override fun getLayoutId(): Int {
        return R.layout.activity_book_agent
    }

    override fun initializeDagger() {
        IleApplication.getRoomComponent().inject(this)
    }

    override fun initializeViewModel() {
        bookAgentViewModel = ViewModelProviders.of(this, bookAgentViewModelFactory).get(BookAgentViewModel::class.java)
        bookAgentViewModel.setView(this)
    }

    override fun setUpUi() {
        gradientStatusBar()
        cityLocalityJson = appPreferences.cityLocalitiesJson

        compositeDisposable.add(bookAgentCityLocationTV.clicks().observeOn(AndroidSchedulers.mainThread()).subscribe {
            startActivity(Intent(this, AreaLocalitiesActivity::class.java)
                .putExtra(AppConstants.COMING_FROM_AGENT_KEY, true))
        })

        compositeDisposable.add(filtersButton.clicks().observeOn(AndroidSchedulers.mainThread()).subscribe {
            startActivity(Intent(this, FiltersMainActivity::class.java)
                .putExtra(AppConstants.FILTER_TYPE_KEY, AppConstants.AGENT_FILTER))
        })

        compositeDisposable.add(searchAgentsButton.clicks()
            .subscribe { startActivity(Intent(this@BookAgentActivity, SearchAgentActivity::class.java)) })

    }

    override fun onSuccess(response: Any) {
        if (response is AgentsDetailAPIResponse) {
            response.let {
                val agentDetailsList = it.data
                if (agentDetailsList != null && agentDetailsList.size > 0) {
                    updateAgentPinsOnMap(agentDetailsList)
                }
            }
        }
    }

    override fun onDestroy() {
        super.onDestroy()
        compositeDisposable.clear()
    }
}

:) Above code works fine for the first time

:( But after coming back from BookAgentActivity (onBackPressed())

Click events are not working for searchAgentsButton as well as for other views too.

Have tried including combinations of other lines of code like below:

.subscribeOn(Schedulers.newThread())
.observeOn(AndroidSchedulers.mainThread())
.share()

But none of the above things are working.

A.R.
  • 2,631
  • 1
  • 19
  • 22
  • Not sure, but could it be because it's a disposable? – ChrisZ Jun 06 '19 at 11:29
  • 1
    Please post a bigger snippet. When are you subscribing, onStart() onCreate()? When are unsubscribing, disposing etc? This sounds like a lifecycle and subscription issue. – Giorgos Neokleous Jun 06 '19 at 11:34
  • 1
    where you used `compositeDisposable.clear()` or `Dispoosable.dispose()` methods in code – rishabh Jun 06 '19 at 11:34
  • @GiorgosNeokleous FYI Subscribing in onCreate() and unsubscribing in onDestroy() {compositeDisposable.clear()} – A.R. Jun 06 '19 at 11:56
  • Is there any particular reason why you're using RxBinding for this, rather than just set an onClickListener? – EpicPandaForce Jun 06 '19 at 13:47
  • @EpicPandaForce : No, there is not any particular reason just wanna try RxBinding. But unfortunately facing the above mentioned issue.. – A.R. Jun 07 '19 at 06:16

0 Answers0