Предполагается, что мое приложение будет запущено пользователем один раз, а фоновый процесс будет выполняться неограниченное время при запуске приложения. Предполагается, что фоновый процесс запускает обработчик (я использую badoo WeakHandler) с интервалом 5 с.
Однако после 500–1000 итераций этого интервала приложение завершает работу без уведомления на logcat (я буду предоставьте скриншот позже) . Я установил свой logcat на Verbose
и No 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);
}
};