Rohit Singla
Rohit Singla

Reputation: 122

APIs to handle the app resume in RecyclerView in android

I have a RecyclerView :

class MyCustomRecyclerView @JvmOverloads constructor(...) : RecyclerView(...)
{
    override fun onSaveInstanceState(): Parcelable? {
        Log.i("MY_TAG", "onSaveInstanceState")
        return super.onSaveInstanceState()
    }

    override fun onRestoreInstanceState(state: Parcelable?) {
        Log.i("MY_TAG", "onRestoreInstanceState")
        super.onRestoreInstanceState(state)
    }

    override fun onDetachedFromWindow() {
        Log.i("MY_TAG", "onDetachedFromWindow")
        super.onDetachedFromWindow()
    }

    override fun onAttachedToWindow() {
        Log.i("MY_TAG", "onAttachedToWindow")
        super.onAttachedToWindow()
    }
}

And I am using this RecyclerView in a Fragment

class MyCustomFragment: Fragment()
{
    override fun onResume()
    {
        super.onResume()
        startSomeWork()
    }

    override fun onPause()
    {
        super.onPause()
        stopSomeWork()
    }
}

On clicking the "home" button and launching the app again from the recent apps, the onPause() and onResume() APIs of the fragment are getting called and I am able to startSomeWork() and stopSomeWork().

But I want to do the same thing from my RecyclerView instead. I tried to capture the logs of some APIs mentioned above. On clicking the "home" button,onSaveInstanceState() is getting called. But when launching the app again from the recent apps, none of these APIs is getting called.

I would like to know if there are any such APIs which I can use for my purpose?

Upvotes: 0

Views: 40

Answers (0)

Related Questions