Search code examples
androidandroid-activityandroid-lifecycle

How to disable onResume() call if onActivityResult() is called


I have refresh function called inside onResume() if user minimize app and then will come back it will refresh list of data from server. Problem is that same functionality but with different parameters (and different usecase) is used when user come back from another activity. It will refresh list only partially (not all data). Is there a possibility to block onResume() method call if onActivityResult() is called?


Solution

  • There is one way to achieve that,

    onActivityResult
    

    will get called before calling

    onResume
    

    So, you can add a flag there and check the necessary condition. Whether it came other screen or not.

    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)
        if (resultCode == Activity.RESULT_OK && requestCode == 3214) {
    cameFromOtherScreen = true; }
    
    override fun onResume() {
        super.onResume()
    if(!cameFromOtherScreen) {
       //do your thing }
    }