小编Che*_*eng的帖子

WorkManager的OneTimeWorkRequest的重试策略/机制是什么

我有以下一次性工作人员.

// Create a Constraints that defines when the task should run
Constraints constraints = new Constraints.Builder()
        .setRequiredNetworkType(NetworkType.UNMETERED)
        .setRequiresBatteryNotLow(true)
        // Many other constraints are available, see the
        // Constraints.Builder reference
        .build();

OneTimeWorkRequest oneTimeWorkRequest =
        new OneTimeWorkRequest.Builder(SyncWorker.class)
                .setConstraints(constraints)
                .addTag(SyncWorker.TAG)
                .build();
Run Code Online (Sandbox Code Playgroud)

根据https://developer.android.com/topic/libraries/architecture/workmanager

// (Returning RETRY tells WorkManager to try this task again
// later; FAILURE says not to try again.)
Run Code Online (Sandbox Code Playgroud)

我想知道,如果SyncWorker继续回来RETRY,重试策略是WorkManager什么?例如,最大重试次数是WorkManager多少?文档不清楚.

android android-architecture-components android-workmanager

13
推荐指数
2
解决办法
5803
查看次数

拥有.hgtags的目的是什么?

我可以知道拥有.hgtags的目的是什么?我可以删除它吗?因为它不在.hg文件夹中,并且似乎"污染"我的实际源代码目录.

https://bz.mercurial-scm.org/show_bug.cgi?id=1205

mercurial

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

与"旧"AdMob SDK相比,我们是否应该更喜欢Google Play服务中的AdMob

我刚刚意识到谷歌将AdMob嵌入到最新的Google Play服务中(4+)

我想知道,如果我更喜欢https://developers.google.com/mobile-ads-sdk/docs/#play而不是https://developers.google.com/mobile-ads-sdk/docs/#android?因为我没有看到谷歌的官方立场.

我之所以这么说,我发现Google Play服务中的AdMob还是很麻烦的.

这是我的观察.

  1. 从Java代码创建智能横幅,并将其放在滚动视图的中间.
  2. 每当智能横幅广告从Google服务器成功获取广告时,滚动视图将自动滚动以使智能横幅可见.

从我的角度来看,这似乎是一种不受欢迎的行为.这就是为什么,我仍然不愿意迁移新的Google Play服务.

可以在此处找到演示该错误的完整源代码:Google Play服务的AdMob将执行不需要的自动滚动

android admob google-play-services

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

Google Drive API - 名称不得为空:null(但我已将有效的帐户名称传递给GoogleAccountCredential)

最近,我有Android代码访问Google云端硬盘.我正在使用Google API Client Library for Java而不是Google Play服务客户端库

private static GoogleCloudFile searchFromGoogleDrive(Drive drive, String qString, HandleUserRecoverableAuthIOExceptionable h, PublishProgressable p) {
    try {
        Files.List request = drive.files().list().setQ(qString);

        do {        
            if (p.isCancelled()) {
                return null;
            }

            FileList fileList = request.execute();
Run Code Online (Sandbox Code Playgroud)

如果我使用,代码可以在几年内完成100%罚款targetSdkVersion 21.

最近,我将我的应用迁移到targetSdkVersion 23了Google Drive相关代码的0更改.

但是,代码崩溃了FileList fileList = request.execute();,但有以下异常.

使用1.18.0-rc时出现错误日志

Process: org.yccheok.jstock.gui, PID: 30317
java.lang.RuntimeException: An error occurred while executing doInBackground()
    at android.os.AsyncTask$3.done(AsyncTask.java:309)
    at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:354)
    at java.util.concurrent.FutureTask.setException(FutureTask.java:223)
    at java.util.concurrent.FutureTask.run(FutureTask.java:242)
    at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
    at …
Run Code Online (Sandbox Code Playgroud)

android google-drive-api

12
推荐指数
2
解决办法
8452
查看次数

如何将对话框窗口背景设置为透明,而不影响其边距

目前,我有以下对话框,我将对其项目执行展开/折叠动画.

在此输入图像描述

该对话框通过以下代码创建

import android.support.v7.app.AlertDialog;

final AlertDialog.Builder builder = new AlertDialog.Builder(activity);
final AlertDialog dialog = builder.setView(view).create();
final ViewTreeObserver vto = view.getViewTreeObserver();
vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {

    public void onGlobalLayout() {
        ViewTreeObserver obs = view.getViewTreeObserver();
        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN) {
            obs.removeOnGlobalLayoutListener(this);
        } else {
            obs.removeGlobalOnLayoutListener(this);
        }

        // http://stackoverflow.com/questions/19326142/why-listview-expand-collapse-animation-appears-much-slower-in-dialogfragment-tha
        int width = dialog.getWindow().getDecorView().getWidth();
        int height = dialog.getWindow().getDecorView().getHeight();
        dialog.getWindow().setLayout(width, height);
    }
});
Run Code Online (Sandbox Code Playgroud)

但是,当执行动画时,这是副作用.

在此输入图像描述

请注意,动画后对话框中不需要的额外白色区域不是由我们的自定义视图引起的.它是对话框本身的系统窗口白色背景.

我倾向于使对话框的系统窗口背景变得透明.

final AlertDialog.Builder builder = new AlertDialog.Builder(activity);
final AlertDialog dialog = builder.setView(view).create();
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
Run Code Online (Sandbox Code Playgroud)

虽然不再看到不需要的白色背景,但对话框的原始边距也消失了.(对话框宽度现在是全屏宽度)

在此输入图像描述

如何在不影响保证金的情况下使其透明?

android android-animation android-dialog

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

无法使用RoomDatabase.query更新sqlite_sequence表

我们尝试sqlite_sequence使用以下代码进行更新.

WeNoteRoomDatabase weNoteRoomDatabase = WeNoteRoomDatabase.instance();
weNoteRoomDatabase.query(new SimpleSQLiteQuery("UPDATE sqlite_sequence SET seq = 0 WHERE name = 'attachment'"));
Run Code Online (Sandbox Code Playgroud)

但是,它完全没有效果.我sqlite_sequence使用SQLite浏览器检查表内容.计数器未重置为0.

如果我们尝试在同一个SQLite文件上使用SQLite浏览器手动运行相同的查询,它就可以正常工作.

我们的房间数据库非常简单.

@Database(
    entities = {Attachment.class},
    version = 6
)
public abstract class WeNoteRoomDatabase extends RoomDatabase {
    private volatile static WeNoteRoomDatabase INSTANCE;

    private static final String NAME = "wenote";

    public abstract AttachmentDao attachmentDao();

    public static WeNoteRoomDatabase instance() {
        if (INSTANCE == null) {
            synchronized (WeNoteRoomDatabase.class) {
                if (INSTANCE == null) {
                    INSTANCE = Room.databaseBuilder(
                        WeNoteApplication.instance(),
                        WeNoteRoomDatabase.class,
                        NAME
                    )
                        .build(); …
Run Code Online (Sandbox Code Playgroud)

android android-room

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

有没有一种方法可以使RecyclerView requireFadingEdge不受paddingTop和paddingBottom的影响

目前,我需要使用paddingToppaddingBottomRecyclerView,因为我想避免复杂的空间计算,在我的第一RecyclerView项和最后一项。

但是,我注意到requiresFadingEdge效果也会受到影响。

这是我的XML

<androidx.recyclerview.widget.RecyclerView
    android:requiresFadingEdge="vertical"
    android:paddingTop="0dp"
    android:paddingBottom="0dp"

    android:overScrollMode="always"
    android:background="?attr/recyclerViewBackground"
    android:id="@+id/recycler_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:clipToPadding="false" />
Run Code Online (Sandbox Code Playgroud)

当paddingTop和paddingBottom为40dp时

在此处输入图片说明

如您所见,淡入淡出效果下降了40dp,这不是我想要的。


当paddingTop和paddingBottom为0dp时

在此处输入图片说明

褪色效果看起来不错。但是,我需要有非零paddingToppaddingBottom,为我RecyclerView


有没有一种方法,使RecyclerViewrequiresFadingEdge通过影响paddingToppaddingBottom

android android-recyclerview

12
推荐指数
2
解决办法
926
查看次数

为什么Programming Perl使用本地(不是我的)文件句柄?

当我阅读Programming Perl,第2版,第51页时,有些东西让我困惑:

sub newopen {
    my $path = shift;
    local *FH;    #not my!
    open (FH, $path) || return undef;
    return *FH;
}

$fh = newopen('/etc/passwd');
Run Code Online (Sandbox Code Playgroud)

我知道,为什么我们不会重新开始使用我的?到目前为止,如果我们使用my(),我看不出任何问题.

谢谢!

perl filehandle lexical

11
推荐指数
3
解决办法
5889
查看次数

正确的方法来执行区域设置比较

目前,我想知道我的应用程序中正在加载哪个属性文件.

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package example0;

import java.util.Locale;

/**
 *
 * @author yccheok
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        //Locale.setDefault(Locale.SIMPLIFIED_CHINESE);     // Bundle_zh_CH.properties will be loaded.
        //Locale.setDefault(Locale.CHINA);                  // Bundle_zh_CH.properties will be loaded.
        //Locale.setDefault(Locale.TRADITIONAL_CHINESE);    // Bundle.properties will be loaded.
        //Locale.setDefault(Locale.CHINESE);                // Bundle.properties will be loaded.

        String Hello = java.util.ResourceBundle.getBundle("example0/Bundle").getString("HELLO");
        System.out.println(Hello);

        System.out.println("Locale.SIMPLIFIED_CHINESE's language …
Run Code Online (Sandbox Code Playgroud)

java

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

Java SE和Android平台中的不同正则表达式结果

我有以下Java SE代码,它在PC上运行

public static void main(String[] args) {
    // stringCommaPattern will change
    // ","abc,def","
    // to
    // ","abcdef","        
    Pattern stringCommaPattern = Pattern.compile("(\",\")|,(?=[^\"[,]]*\",\")");
    String data = "\"SAN\",\"Banco Santander, \",\"NYSE\"";
    System.out.println(data);
    final String result = stringCommaPattern.matcher(data).replaceAll("$1");
    System.out.println(result);
}
Run Code Online (Sandbox Code Playgroud)

我得到了预期的结果

"SAN","Banco Santander, ","NYSE"
"SAN","Banco Santander ","NYSE"
Run Code Online (Sandbox Code Playgroud)

但是,来到Android时.

Pattern stringCommaPattern = Pattern.compile("(\",\")|,(?=[^\"[,]]*\",\")");
String data = "\"SAN\",\"Banco Santander, \",\"NYSE\"";
Log.i("CHEOK", data);
final String result = stringCommaPattern.matcher(data).replaceAll("$1");
Log.i("CHEOK", result);
Run Code Online (Sandbox Code Playgroud)

我越来越

"SAN","Banco Santander, ","NYSE"
"SAN","Banco Santandernull ","NYSE"
Run Code Online (Sandbox Code Playgroud)

任何建议和解决方法,我如何使这些代码的行为与Java SE相同?


附加说明:

其他模式也产生相同的结果.看来,Android正在为无法匹配的组使用空字符串,而Java SE正在使用空字符串作为不匹配的组. …

java android

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