I have registered launcher before activity get started but some times when launch is called on listener it gets crashed and reason is mentioned below
Sometimes I am getting this:
java.lang.IllegalStateException: Attempting to launch an unregistered ActivityResultLauncher with contract j.c@ab78423 and input Intent You must ensure the ActivityResultLauncher is registered before calling launch().
any solution?
I am following below approach :
- Creating launcher variable for activityResultLauncher before activity is created
private var launcher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result -> // handling result }
- And launching this after activity is created by using below method: launcher.launch()