Why is there an extra onPause onResume when launching action call?

30 Views Asked by At

I have a simple setup that launches the dialer to make a call using ACTION_CALL


   override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_launch_dialer)
        Log.d("TAG", "onCreate")
        findViewById<Button>(R.id.btn_launch).setOnClickListener {
            Log.d("TAG", "Launching Call")
            val uri = Uri.parse("tel:3332223333")
            val intent = Intent(Intent.ACTION_CALL, uri)
            startActivity(intent)
        }
    }

    override fun onResume() {
        super.onResume()
        Log.d("TAG", "onResume")
    }
    
    override fun onPause() {
        super.onPause()
        Log.d("TAG", "onPause")
    }

I'm logging each lifecycle and seeing weird behavior. There seems to be an extra onPause onResume once the user clicks the launch button.

I get the following log output when clicking the launch button above.

Launching Call
onPause
onResume <-- This is unexpected
onPause
onStop

I am unable to figure out why the lifecycle transitions back to onResume after the initial onPause. Is there any way to prevent this?

Additional context: I'm trying to do some work in onPause but it is getting duplicated because of the unexpected onResume call

1

There are 1 best solutions below

0
Md Eusuf Uddin On

You can not avoid to call onResume() when back within App. Because Activity lifecycle Working with this behaviour. I think, this link will help you

Android activity life cycle - what are all these methods for?