小编Sus*_*ger的帖子

Android Work Manager与服务?

在我的Android应用我有一个运行一个又一个的第一个目的服务是由广播trigerred多意图服务.几天前我遇到了Work Manager,并且非常喜欢Worker和WorkManager类的简单性.工作管理器对常规意图服务的利弊是什么?我现在应该转换到工作经理,考虑到将来我可能不得不写更多的意向服务吗?还有哪个选项可以帮助我轻松测试代码?

java android intentservice android-jetpack android-workmanager

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

Android 中的 consumer-rules.pro 和 proguard-rules.pro 有什么区别?

我在 Android 中创建了一个模块以在我的主应用程序中使用,并且似乎有两个文件 consumer-rules.pro 和 proguard-rules.pro。

我想知道以下内容

  1. 即使模块没有指定任何规则,所有模块代码都会被主模块亲卫规则的规则混淆吗?
  2. Android 中的 consumer-rules.pro 和 proguard-rules.pro 有什么区别?
  3. 我应该在我的模块中启用 minifyEnabled 吗?
  4. 我注意到我可以在主模块中为我的模块添加 proguard 规则,这是否意味着模块中的 pro-guard 规则在主模块中被覆盖?

请指教。

java android proguard kotlin

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

为什么我应该使用 cronet 而不是 volley/retrofit?

我在这里看到了 cronet 上的一个部分

https://developer.android.com/guide/topics/connectivity/cronet

它指出

Cronet 是 Chromium 网络堆栈,作为库可供 Android 应用程序使用。

有人用过这个库吗?它的用例是什么?

android android-volley retrofit

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

如何将映射函数应用于Kotlin中的数组并更改其值?

我正在使用此代码。

fun main(args : Array<String>){

    val someArray : Array<Int> =  arrayOf(3,53,2,521,51,23,512,34,124);

    println("Original array is ")

    someArray.forEach {print("$it , ")}

    someArray.map({num -> num*2})

    println("Changed array is ")

    println()

    someArray.forEach { print("$it , ") }
}
Run Code Online (Sandbox Code Playgroud)

但是地图功能似乎不起作用。这是它打印的内容

原始数组是3,53,2,521,51,23,512,34,124,更改后的数组是

3、53、2、521、51、23、512、34、124,

我的问题是,为什么数组的值不加倍?我在这里想念什么?

arrays kotlin

6
推荐指数
3
解决办法
9050
查看次数

安卓室。哪种插入方法会更快?

我使用 Room 作为 SQLite 上的抽象层。阅读此页面后,我发现我们可以同时插入多个对象。目前我使用 For 循环来插入对象,即在每个 For 循环迭代中插入一个对象。我目前知道的两种插入方式是:

  1. 使用 For 循环并一次插入一个对象

    @Insert(onConflict = OnConflictStrategy.REPLACE) public void addActivity(Person person);

  2. 插入数组或对象列表。

    @Insert(onConflict = OnConflictStrategy.REPLACE) public void insertUsers(Person ... people);

我在编写插入对象的代码时,不知道第二种插入方式。现在我想知道这两种方式之间的速度是否有明显差异,以便我可以更改代码以提高应用程序的性能。

sqlite android sql-insert android-room android-architecture-components

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

Room数据库是否支持实体中的布尔变量?

我知道sqlite不支持Boolean,我们需要使用int列来模仿Boolean的行为.但Room支持布尔值吗?如果我的实体中有布尔值怎么办?它会按预期工作吗?

sqlite android android-room

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

Kotlin-在整数的ArrayList中获取最大值

我有这个ArrayList

    var amplititudes : ArrayList<Int> = ArrayList()
    amplititudes.add(1)
    amplititudes.add(2)
    amplititudes.add(3)
    amplititudes.add(4)
    amplititudes.add(3)
    amplititudes.add(2)
    amplititudes.add(1)
Run Code Online (Sandbox Code Playgroud)

现在,我想获取最大价值,即4。找到最大元素的最简单方法是什么?我知道max()方法,但是它将强制我使用?返回值,因为它可能为null。有没有比这更好的解决方案了?

java kotlin

4
推荐指数
2
解决办法
1697
查看次数

Kotlin - 创建一个指定长度的随机整数的ArrayList?

我有ArrayList这样的:

var amplititudes : ArrayList<Int> = ArrayList()
Run Code Online (Sandbox Code Playgroud)

我想用随机的Ints来填充它.我怎样才能做到这一点?

java kotlin

4
推荐指数
3
解决办法
2200
查看次数

Kotlin,Android - 如何在 runnable 中发布相同的 runnable?

我想将一个 runnable 发布到一个 runnable 内的视图对象,目前我被困在这里。

 var runnable = Runnable {
        if(numLinesToDraw >= amplititudes.size){

        }
        else
        {
            numLinesToDraw = numLinesToDraw ++
            invalidate()
            postDelayed({

            },2000)
        }
    }

    postDelayed(runnable,2000)
Run Code Online (Sandbox Code Playgroud)

如您所见,postDelayedrunnable 中有一个方法。我想要做的是再次发布相同的 runnable 等等。我应该在这里添加什么?

       postDelayed({

        },2000)
Run Code Online (Sandbox Code Playgroud)

android runnable kotlin

4
推荐指数
2
解决办法
5037
查看次数

如何在约束布局中修改链长?

这是我的代码

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/nav_and_action_bar_color"
 >

<ImageView
    android:id="@+id/some_person"
    android:layout_width="100dp"
    android:layout_height="100dp"
    android:src="@drawable/some_person"
    app:layout_constraintBottom_toTopOf="@+id/et_username"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.5"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />


<EditText
    android:id="@+id/et_username"
    android:layout_width="@dimen/login_page_text_fields_width"
    android:layout_height="wrap_content"
    android:layout_margin="10dp"
    android:background="@android:color/white"
    android:hint="@string/email_hint"
    android:padding="10dp"
    app:layout_constraintBottom_toTopOf="@+id/et_password"
    app:layout_constraintHorizontal_bias="0.5"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/some_person" />

<EditText
    android:id="@+id/et_password"
    android:layout_width="@dimen/login_page_text_fields_width"
    android:layout_height="wrap_content"
    android:layout_margin="10dp"
    android:background="@android:color/white"
    android:hint="@string/password_hint"
    android:inputType="textPassword"
    android:padding="10dp"
    app:layout_constraintBottom_toTopOf="@+id/login_button"
    app:layout_constraintHorizontal_bias="0.5"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toBottomOf="@id/et_username" />

<Button
    android:id="@+id/login_button"
    android:layout_width="@dimen/login_button_width"
    android:layout_height="wrap_content"
    android:layout_margin="10dp"
    android:background="@color/colorAccent"
    android:elevation="5dp"
    android:onClick="clickedOnLogin"
    android:text="@string/login_button"
    android:textColor="@android:color/white"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintHorizontal_bias="0.5"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toBottomOf="@id/et_password" />
</android.support.constraint.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)

结果我似乎得到了这个

模拟器截图

我如何将元素组合在一起?我想让他们靠得很近。

java android android-constraintlayout constraint-layout-chains

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