小编pep*_*umo的帖子

使用暗模式时,Android Activity 会被实例化两次

我的启动器活动,即 MainActivity 在使用时被实例化了两次, AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES) 这导致了两次网络调用并做出了奇怪的行为。

有没有可以控制这个并只初始化一次的?我试过使用 launchMode = "singleTop" 和 "singleInstance"

 override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_main)
    AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES)
    mRequestQueue = Volley.newRequestQueue(this)
    Log.e(TAG,"Skillet")
    loadStateData()
    initializeListeners()
}
Run Code Online (Sandbox Code Playgroud)

android android-lifecycle android-activity android-darkmode

6
推荐指数
1
解决办法
1162
查看次数

无法从我的片段中的 ViewModel 观察 LiveData<MutableList<T>>

我的片段.kt:

viewModel.studentsTemp.observe(this, Observer {
    adapter.submitList(it)
})
Run Code Online (Sandbox Code Playgroud)

MyViewModel.kt

private var _studentsTemp = MutableLiveData<MutableList<Student>>()
val studentsTemp: LiveData<MutableList<Student>> get() = _studentsTemp
init {
        _studentsTemp.value = mutableListOf<Student>()
}
Run Code Online (Sandbox Code Playgroud)

仅当应用程序启动时(即创建 ViewModel 时,即当 init 块在 View Model 中运行时)才会调用 Observer。

android mvvm kotlin android-livedata mutablelivedata

3
推荐指数
1
解决办法
1178
查看次数

在miui(小米)中检测暗模式

我已经看到了有关检测暗模式就像许多问题这一个在堆栈溢出,并参观了许多媒体的博客喜欢如何当你使用暗模式编程了解DayNight -添加一个黑暗的主题,你的应用程序,并在所有这些他们执行像这样的支票:

fun isNightModeEnabled(context: Context): Boolean =
    context.resources.configuration.uiMode.and(UI_MODE_NIGHT_MASK) ==
            UI_MODE_NIGHT_YES
Run Code Online (Sandbox Code Playgroud)

这适用于任何手机,甚至运行 Android One 的小米手机,但不适用于运行 MIUI 的小米智能手机。

对于运行 MIUI 的小米设备:

context.resources.configuration.uiMode = 17

context.resources.configuration.uiMode.and(UI_MODE_NIGHT_MASK)=16

相比之下,UI_MODE_NIGHT_YES (32)启用或禁用暗模式时总是返回 false。

是否真的可以检测到此类设备已强制启用暗模式?

android miui xiaomi android-darkmode

2
推荐指数
1
解决办法
720
查看次数

Firebase 应用程序中 Compose 的仪器测试

我试图在撰写中创建测试,但总是收到以下错误:

默认 FirebaseApp 在此过程中未初始化 X. 确保首先调用 FirebaseApp.initializeApp(Context)。

我试图最大限度地简化测试代码:

@get:Rule
val composeTestRule = createComposeRule()

@Test
fun test() {

    composeTestRule.setContent {
        Text("Whatever")
    }
}
Run Code Online (Sandbox Code Playgroud)

但仍然收到该错误。

我尝试过 uiThreadTestRule:

@get:Rule
val composeTestRule = createComposeRule()

@get:Rule
var uiThreadTestRule: UiThreadTestRule = UiThreadTestRule()

@Test
fun test() {
    uiThreadTestRule.runOnUiThread {
        FirebaseApp.initializeApp(InstrumentationRegistry.getInstrumentation().targetContext)
    }

    composeTestRule.setContent {
        Text("Whatever")
    }
}
Run Code Online (Sandbox Code Playgroud)

并且还具有相同的 composeTestRule.runOnUiThread:

@get:Rule
val composeTestRule = createComposeRule()

@Test
fun test() {
    composeTestRule.runOnUiThread {
        FirebaseApp.initializeApp(InstrumentationRegistry.getInstrumentation().targetContext)
    }

    composeTestRule.setContent {
        Text("Whatever")
    }
}
Run Code Online (Sandbox Code Playgroud)

如何FirebaseApp is not initialized修复该错误以便测试该应用程序的可组合项?

更新

这似乎与 createComposeRule() 有关,导致以下测试:

@get:Rule …
Run Code Online (Sandbox Code Playgroud)

android-testing android-jetpack-compose

2
推荐指数
1
解决办法
567
查看次数

Git Merge Feature Branch to Master 与 Master to Feature 相比是否有区别

我打算将新功能(在功能分支中)合并到主分支中。我继续将功能合并到主控中。然而我发现师父少了一行字。但是,如果我将Master合并到Feature中,然后将Feature合并回Master中,则该行将保留在Master中。我的问题是,将Feature合并到Master和Master合并到Feature有区别吗?谢谢

附加信息,在从 Master 检出功能后,将修补程序添加到 Master 中。因此,它将Feature合并到“Master-2”中。

git merge git-flow

1
推荐指数
1
解决办法
809
查看次数