我在我的应用程序中使用动态功能模块,这是我的 App
类 -
@HiltAndroidApp
class DogApp : SplitCompatApplication() {
override fun attachBaseContext(base: Context?) {
super.attachBaseContext(base)
SplitCompat.install(this)
}
}
这是我的MainActivity
-
private var sessionId: Int = 0
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
fetchModules()
}
private fun fetchModules() {
val splitInstallManager = SplitInstallManagerFactory.create(this)
val request = SplitInstallRequest
.newBuilder()
.addModule("dogProfile")
.build()
val listener =
SplitInstallStateUpdatedListener { splitInstallSessionState ->
if (splitInstallSessionState.sessionId() == sessionId) {
when (splitInstallSessionState.status()) {
SplitInstallSessionStatus.INSTALLED -> {
Log.e("hi", "Installed")
}
SplitInstallSessionStatus.DOWNLOADING -> {
val totalBytes = splitInstallSessionState.totalBytesToDownload()
val progress = splitInstallSessionState.bytesDownloaded()
Log.e("hi", "Downloading$totalBytes...$progress")
}
SplitInstallSessionStatus.INSTALLING -> {
Log.e("hi", "Installing")
}
}
}
}
splitInstallManager.registerListener(listener)
splitInstallManager.startInstall(request)
.addOnFailureListener { e -> Log.e("hi", "Exception: $e") }
.addOnSuccessListener {
Log.e("hi", "Success")
sessionId = it
val navHostFragment =
supportFragmentManager.findFragmentById(R.id.nav_host_fragment) as NavHostFragment
navHostFragment.navController.navigate(R.id.homeView)
}
}
当我构建 apk 并在我的设备/模拟器上运行时,我看到“正在安装模块”永远保留 我看到了日志 -
Installed
Success
这是我永远看到的屏幕 -
我犯了什么错误?
最佳答案
您使用过导航2.3.2
吗?我发现this change之后有问题。回滚到 2.3.1
或使用您自己的进度 UI 而不是 DefaultProgressFragment
将解决此问题。
关于Android 动态功能虽然说已安装,但仍停留在安装 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65174073/