应用程序预计在后台定期运行,在500-1000次迭代后崩溃,没有LOGCAT。

huangapple 未分类评论59阅读模式
标题翻译

Application expected to run in background on interval crashes without LOGCAT after 500-1000 iterations

问题

我的应用程序预计由用户运行一次,后台进程将在应用程序运行时无限期运行。后台进程应该以5秒的间隔运行处理程序(我使用了 badoo 的 WeakHandler)。然而,在间隔的 500 到 1000 次迭代后,应用程序将在没有任何日志记录通知的情况下终止自身 (稍后我会提供截屏)。我将我的日志记录设置为 VerboseNo Filter

如何确保应用程序能够可靠运行,不崩溃?

build.gradle(:app)

apply plugin: 'com.android.application';

android {
    compileSdkVersion 29
    buildToolsVersion "29.0.2"
    defaultConfig {
        applicationId "com.example"
        minSdkVersion 21
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation 'com.badoo.mobile:android-weak-handler:1.0'
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.0.2'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.0'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
}

我的应用程序只有一个活动,即 MainActivity.java。以下是我的 Runnable 示例:

private Runnable captureInterval = new Runnable() {
    @RequiresApi(api = Build.VERSION_CODES.O)
    @Override
    public void run() {
        android.os.Process.setThreadPriority(android.os.Process.THREAD_PRIORITY_BACKGROUND);
        if (mMediaRecorder != null) {
            File f = new File(videoPath);
            try {
                mMediaRecorder.stop();
            } catch (RuntimeException e) {
                f.delete();
                e.printStackTrace();
            } finally {
                mMediaRecorder.release();
                mMediaRecorder = null;
            }
        }
        if (mVirtualDisplay != null) {
            mVirtualDisplay.release();
            mVirtualDisplay = null;
        }
        if (!mKeyguardManager.isKeyguardLocked()) {
            initRecorder();
            shareScreen();
        }
        mHandler.postDelayed(this, 5000);
    }
};
英文翻译

My application is expected to be run once by the user and the background process will run indefinitely as the app runs. The background process is supposed to run a handler (I use badoo WeakHandler) on 5s interval.
However, after 500 - 1000 iterations of the interval, the application would terminate itself without any notification on the logcat (I will provide the screenshot later). I set my logcat to Verbose and No Filter.

How can I make sure that the application can run reliably without crashing?

build.gradle(:app)

apply plugin: 'com.android.application'

android {
    compileSdkVersion 29
    buildToolsVersion "29.0.2"
    defaultConfig {
        applicationId "com.example"
        minSdkVersion 21
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation 'com.badoo.mobile:android-weak-handler:1.0'
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.0.2'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.0'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
}

My application only has one activity, which is MainActivity.java.
Here is my Runnable

    private Runnable captureInterval = new Runnable() {
        @RequiresApi(api = Build.VERSION_CODES.O)
        @Override
        public void run() {
            android.os.Process.setThreadPriority(android.os.Process.THREAD_PRIORITY_BACKGROUND);
            if (mMediaRecorder != null) {
                File f = new File(videoPath);
                try {
                    mMediaRecorder.stop();
                } catch (RuntimeException e) {
                    f.delete();
                    e.printStackTrace();
                } finally {
                    mMediaRecorder.release();
                    mMediaRecorder = null;
                }
            }
            if (mVirtualDisplay != null) {
                mVirtualDisplay.release();
                mVirtualDisplay = null;
            }
            if (!mKeyguardManager.isKeyguardLocked()) {
                initRecorder();
                shareScreen();
            }
            mHandler.postDelayed(this, 5000);
        }
    };

huangapple
  • 本文由 发表于 2020年3月16日 18:06:31
  • 转载请务必保留本文链接:https://java.coder-hub.com/60703931.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定