我有 2 个屏幕,它们都有自己的Scaffold
和TopAppBar
。当我使用 Jetpack Navigation Compose 库在它们之间导航时,应用程序栏会闪烁。为什么会发生这种情况以及我该如何摆脱这种情况?
代码:
导航:
@Composable
fun TodoNavHost(
navController: NavHostController,
modifier: Modifier = Modifier
) {
NavHost(
navController = navController,
startDestination = TodoScreen.TodoList.name,
modifier = modifier
) {
composable(TodoScreen.TodoList.name) {
TodoListScreen(
onTodoEditClicked = { todo ->
navController.navigate("${TodoScreen.AddEditTodo.name}?todoId=${todo.id}")
},
onFabAddNewTodoClicked = {
navController.navigate(TodoScreen.AddEditTodo.name)
}
)
}
composable(
"${TodoScreen.AddEditTodo.name}?todoId={todoId}",
arguments = listOf(
navArgument("todoId") {
type = NavType.LongType
defaultValue = -1L
}
)
) {
AddEditTodoScreen(
onNavigateUp = {
navController.popBackStack()
},
onNavigateBackWithResult = { result …
Run Code Online (Sandbox Code Playgroud) android android-jetpack android-jetpack-navigation android-jetpack-compose android-jetpack-compose-scaffold
当我创建一个矢量drawable时,我可以设置它的大小dp
.默认值为24dp x 24dp.
如果我在我的应用程序中使用不同于24dp x 24dp的矢量,那么这些测量在性能方面是否重要?另外关于21岁以下的API(我app:srcCompat
用来显示图像).
当使用较低的API并且系统将其缩小时,矢量大小是否重要?
这些测量对我的使用是否重要,除了我申请时只是默认大小wrap_content
?
我将 Paging 3 与 RemoteMediator 结合使用,它在从网络获取新数据的同时显示缓存的数据。当我刷新我的PagingDataAdapter
(通过调用refresh()
它)时,我希望我的 RecyclerView 在刷新完成后滚动到顶部。在代码实验室loadStateFlow
中,他们尝试通过以下方式处理这个问题:
lifecycleScope.launch {
adapter.loadStateFlow
// Only emit when REFRESH LoadState for RemoteMediator changes.
.distinctUntilChangedBy { it.refresh }
// Only react to cases where Remote REFRESH completes i.e., NotLoading.
.filter { it.refresh is LoadState.NotLoading }
.collect { binding.list.scrollToPosition(0) }
}
Run Code Online (Sandbox Code Playgroud)
这确实会向上滚动,但在 DiffUtil 完成之前。这意味着如果顶部确实插入了新数据,RecyclerView将不会一直向上滚动。
我知道 RecyclerView 适配器有一个AdapterDataObserver
回调,当 DiffUtil 完成比较时我们可以收到通知。但这会导致适配器的各种竞争条件和PREPEND
加载APPEND
状态,这也会导致 DiffUtil 运行(但这里我们不想滚动到顶部)。
一种可行的解决方案是传递PagingData.empty()
到PagingDataAdapter
并重新运行相同的查询(仅调用refresh
是行不通的,因为PagingData
现在是空的并且没有任何内容可以刷新),但我更愿意保持旧数据可见,直到我知道刷新实际上成功了。
paging android android-paging android-paging-library android-paging-3
什么向后兼容性
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
Run Code Online (Sandbox Code Playgroud)
提供我从正常情况下得不到的
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
Run Code Online (Sandbox Code Playgroud)
他们都有一种notify
方法可以在我测试的设备上运行(低至API级别19).
此处的Google示例甚至不使用该Compat
版本一次:
notifications android push-notification android-notifications
我的导航图有一个auth
包含 LoginFragment 和 SignUpFragment 的子图:
<navigation
android:id="@+id/auth"
app:startDestination="@id/loginFragment">
<fragment
android:id="@+id/signUpFragment"
[...]
<fragment
android:id="@+id/loginFragment"
[...]
</fragment>
[...]
</navigation>
Run Code Online (Sandbox Code Playgroud)
我想检查这两个目的地中的任何一个当前是否位于返回堆栈上。但不要单独检查每个目的地,如下所示:
val currentDestId = navController.currentDestination?.id
if (currentDestId != R.id.loginFragment && currentDestId != R.id.signUpFragment) {
navController.navigate(
NavGraphDirections.actionGlobalLogin()
)
}
Run Code Online (Sandbox Code Playgroud)
我认为只检查身份验证图当前是否位于返回堆栈上会更干净。
我目前的方法如下:
val authBackStack = try {
navController.getBackStackEntry(R.id.auth)
} catch (t: Throwable) {
null
}
if (authBackStack == null) {
navController.navigate(
NavGraphDirections.actionGlobalLogin()
)
}
Run Code Online (Sandbox Code Playgroud)
这里的想法是,如果传递的目标(或本例中的图形)当前不在返回堆栈上,则getBackStackEntry
抛出异常。IllegalStateException
我们使用此异常作为指示器来查明我们的图形当前是否位于返回堆栈上。
这是一种有效的方法还是在某些情况下会失败?或者也许有更好的方法来检查返回堆栈是否包含某个子图的目的地?
navigation android android-architecture-components android-architecture-navigation
使用Room AutoMigrations时,它Migration
本身会自动生成。但为了对迁移进行单元测试,我必须将一个Migration
对象传递给runMigrationsAndValidate
. 我应该在这里传递什么?
@RunWith(AndroidJUnit4::class)
class MigrationTest {
private val TEST_DB = "migration-test"
@Rule
val helper: MigrationTestHelper = MigrationTestHelper(
InstrumentationRegistry.getInstrumentation(),
MigrationDb::class.java.canonicalName,
FrameworkSQLiteOpenHelperFactory()
)
@Test
@Throws(IOException::class)
fun migrate1To2() {
var db = helper.createDatabase(TEST_DB, 1).apply {
// db has schema version 1. insert some data using SQL queries.
execSQL(...)
// Prepare for the next version.
close()
}
// Re-open the database with version 2 and provide
// Migration as the migration process.
db …
Run Code Online (Sandbox Code Playgroud) 我陷入困境,因为由于许多不同的待删除操作,我达到了项目配额(我不知道它们计入限制)。
有没有一种方法可以立即删除这些项目,以便我可以立即创建一个新项目?
没有关于如何在自定义Java对象中正确存储Firestore文档的自动生成ID的真实文档。检索ID很容易,但是如何正确存储ID以避免冗余。
这是我的方法:
型号类别:
public class Note {
private String documentId;
private String title;
private String description;
public Note() {
//public no arg constructor necessary
}
public Note(String title, String description) {
this.title = title;
this.description = description;
}
@Exclude
public String getDocumentId() {
return documentId;
}
public void setDocumentId(String documentId) {
this.documentId = documentId;
}
public String getTitle() {
return title;
}
public String getDescription() {
return description;
}
}
Run Code Online (Sandbox Code Playgroud)
加载数据:
public void loadNotes(View v) {
notebookRef.get()
.addOnSuccessListener(new OnSuccessListener<QuerySnapshot>() { …
Run Code Online (Sandbox Code Playgroud) 为什么我必须用它要使用的范围来注释 Dagger 组件?为什么对类本身进行注释还不够?
android ×9
firebase ×2
android-architecture-components ×1
android-architecture-navigation ×1
android-jetpack-compose-scaffold ×1
android-room ×1
androidx ×1
dagger ×1
dagger-2 ×1
navigation ×1
paging ×1
vector ×1