RxBinding 'clicks()' method not triggering again when coming back from another activity

377 Views Asked by At

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.

0

There are 0 best solutions below