Dynamic module stuck at downloaded android

I’m trying to implement dynamic module in my android project. I’ve made one activity with 2 fragments. 1st fragment is install time module and 2nd fragment is downloaded on demand. I’ve written the code by referring to online documents but for some reason my application is not installing the demand module. Following is the code

class MainActivity : AppCompatActivity() {

private lateinit var onInstall : Button
private lateinit var onDemand : Button
private lateinit var progressBar : ProgressBar
private lateinit var status : TextView
private lateinit var splitInstallManager : SplitInstallManager
private var sessionId : Int = 0

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_main)

    onInstall = findViewById(R.id.on_install)
    onDemand = findViewById(R.id.on_demand)
    progressBar = findViewById(R.id.Progress_bar)
    status = findViewById(R.id.status)

    splitInstallManager = SplitInstallManagerFactory.create(this)

    onInstall.setOnClickListener {
        val fragmentName = "com.example.oninstall.OnInstallFragment"
        val fragmentManager = supportFragmentManager
        val fragmentTransaction = fragmentManager.beginTransaction()
        fragmentTransaction.replace(R.id.fragment_layout,instantiateFragment(fragmentName))
        fragmentTransaction.commit()
    }

    onDemand.setOnClickListener {
        startDownloading()
    }

}

private fun instantiateFragment(fragment:String): Fragment {
    return Class.forName(fragment).newInstance() as Fragment
}

private fun startDownloading() {
    val request = SplitInstallRequest.newBuilder().addModule("ondemand").build()

    val listener = SplitInstallStateUpdatedListener() {
        if(it.sessionId() == sessionId){
            when(it.status()){
                SplitInstallSessionStatus.DOWNLOADING -> {
                    progressBar.visibility = View.VISIBLE
                    status.text = "DOWNLOADING"
                }
                SplitInstallSessionStatus.INSTALLED -> {
                    progressBar.visibility = View.GONE
                    progressBar.isShown
                    val fragmentName = "com.example.ondemand.OnDemandFragment"
                    val fragmentManager = supportFragmentManager
                    val fragmentTransaction = fragmentManager.beginTransaction()
                    fragmentTransaction.replace(R.id.fragment_layout,instantiateFragment(fragmentName))
                    fragmentTransaction.commit()
                }
                SplitInstallSessionStatus.INSTALLING -> {
                    progressBar.isShown
                    status.text = "INSTALLING"
                }
                SplitInstallSessionStatus.CANCELED -> {
                    progressBar.visibility = View.GONE
                    status.text = "CANCELLED"
                }
                SplitInstallSessionStatus.CANCELING -> {
                    progressBar.visibility = View.VISIBLE
                    status.text = "CANCELLING"
                }
                SplitInstallSessionStatus.DOWNLOADED -> {
                    progressBar.visibility = View.GONE
                    status.text = "DOWNLOADED"
                }
                SplitInstallSessionStatus.FAILED -> {
                    progressBar.visibility = View.GONE
                    status.text = "FAILED"
                }
                SplitInstallSessionStatus.PENDING -> {
                    progressBar.visibility = View.VISIBLE
                    status.text = "PENDING"
                }
                SplitInstallSessionStatus.REQUIRES_USER_CONFIRMATION -> {
                    progressBar.visibility = View.VISIBLE
                    status.text = "USER CONFIRMATION REQUIRED"
                }
                SplitInstallSessionStatus.UNKNOWN -> {
                    progressBar.visibility = View.VISIBLE
                    status.text = "UNKNOWN"
                }
            }
        }
    }

    splitInstallManager.registerListener(listener)

    splitInstallManager.startInstall(request)
        .addOnFailureListener {
            Toast.makeText(this,it.toString(),Toast.LENGTH_SHORT).show()
        }
        .addOnSuccessListener {
            sessionId = it
        }
       
}

So after clicking on the second fragment button, the status shows downloading and after sometime it shows downloaded. But it isn’t getting installed and showing the second fragment. What am i missing here? I also printed logs file and uploading for reference

27-05-2022 12:39:07 : SplitInstallStateUpdatedListener 
SplitInstallSessionState{sessionId=2, status=1, errorCode=0, bytesDownloaded=0, 
totalBytesToDownload=0, moduleNamesNullable=[ondemand], languagesNullable=null, 
resolutionIntent=null, splitFileIntents=null}

27-05-2022 12:39:07 : SplitInstallStateUpdatedListener - status 1

27-05-2022 12:39:07 : SplitInstallStateUpdatedListener - it sessionId 2

27-05-2022 12:39:07 : SplitInstallStateUpdatedListener - val sessionId 0

27-05-2022 12:39:07 : SplitInstallStateUpdatedListener 
SplitInstallSessionState{sessionId=2, status=1, errorCode=0, bytesDownloaded=0, 
totalBytesToDownload=0, moduleNamesNullable=[ondemand], languagesNullable=null, 
resolutionIntent=null, splitFileIntents=null}

27-05-2022 12:39:07 : SplitInstallStateUpdatedListener - status 1

27-05-2022 12:39:07 : SplitInstallStateUpdatedListener - it sessionId 2

27-05-2022 12:39:07 : SplitInstallStateUpdatedListener - val sessionId 0

27-05-2022 12:39:07 : addOnSuccessListener 2

27-05-2022 12:39:07 : SplitInstallStateUpdatedListener 
SplitInstallSessionState{sessionId=2, status=1, errorCode=0, bytesDownloaded=0, 
totalBytesToDownload=0, moduleNamesNullable=[ondemand], languagesNullable=null, 
resolutionIntent=null, splitFileIntents=null}

27-05-2022 12:39:07 : SplitInstallStateUpdatedListener - status 1

27-05-2022 12:39:07 : SplitInstallStateUpdatedListener - it sessionId 2

27-05-2022 12:39:07 : SplitInstallStateUpdatedListener - val sessionId 2

27-05-2022 12:39:07 : SplitInstallStateUpdatedListener 
SplitInstallSessionState{sessionId=2, status=1, errorCode=0, bytesDownloaded=0, 
totalBytesToDownload=0, moduleNamesNullable=[ondemand], languagesNullable=null, 
resolutionIntent=null, splitFileIntents=null}

27-05-2022 12:39:07 : SplitInstallStateUpdatedListener - status 1

27-05-2022 12:39:07 : SplitInstallStateUpdatedListener - it sessionId 2

27-05-2022 12:39:07 : SplitInstallStateUpdatedListener - val sessionId 2

27-05-2022 12:39:08 : SplitInstallStateUpdatedListener 
SplitInstallSessionState{sessionId=2, status=2, errorCode=0, bytesDownloaded=0, 
totalBytesToDownload=13812896, moduleNamesNullable=[ondemand], languagesNullable=null, 
resolutionIntent=null, splitFileIntents=null}

27-05-2022 12:39:08 : SplitInstallStateUpdatedListener - status 2

27-05-2022 12:39:08 : SplitInstallStateUpdatedListener - it sessionId 2

27-05-2022 12:39:08 : SplitInstallStateUpdatedListener - val sessionId 2

27-05-2022 12:39:09 : SplitInstallStateUpdatedListener 
SplitInstallSessionState{sessionId=2, status=2, errorCode=0, bytesDownloaded=13796103, 
totalBytesToDownload=13812896, moduleNamesNullable=[ondemand], languagesNullable=null, 
resolutionIntent=null, splitFileIntents=null}

27-05-2022 12:39:09 : SplitInstallStateUpdatedListener - status 2

27-05-2022 12:39:09 : SplitInstallStateUpdatedListener - it sessionId 2

27-05-2022 12:39:09 : SplitInstallStateUpdatedListener - val sessionId 2

27-05-2022 12:39:09 : SplitInstallStateUpdatedListener 
SplitInstallSessionState{sessionId=2, status=3, errorCode=0, bytesDownloaded=13796103, 
totalBytesToDownload=13812896, moduleNamesNullable=[ondemand], languagesNullable=null, 
resolutionIntent=null, splitFileIntents=[Intent { act=android.intent.action.VIEW 


dat=content://com.google.android.finsky.FileProvider/dynamicsplits/2/ondemand.config.xxxhdpi typ=application/octet-stream flg=0x1 (has extras) }, Intent { act=android.intent.action.VIEW dat=content://com.google.android.finsky.FileProvider/dynamicsplits/2/ondemand typ=application/octet-stream flg=0x1 (has extras) }]}

27-05-2022 12:39:09 : SplitInstallStateUpdatedListener - status 3

27-05-2022 12:39:09 : SplitInstallStateUpdatedListener - it sessionId 2

27-05-2022 12:39:09 : SplitInstallStateUpdatedListener - val sessionId 2

Leave a Comment