1
0
Fork 0
mirror of https://github.com/syncthing/syncthing-android.git synced 2024-12-23 11:21:29 +00:00

Try to fix WindowManager$BadTokenException crashes on Android 7

This commit is contained in:
Felix Ableitner 2017-09-05 00:54:35 +09:00
parent 5741928324
commit 52a7cc5972

View file

@ -1,11 +1,13 @@
package com.nutomic.syncthingandroid.activities;
import android.annotation.SuppressLint;
import android.app.ActivityManager;
import android.app.AlertDialog;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.Build;
import android.os.Bundle;
import android.os.IBinder;
import android.view.LayoutInflater;
@ -128,6 +130,17 @@ public abstract class SyncthingActivity extends ToolbarBindingActivity implement
if (isFinishing() || mLoadingDialog != null)
return;
// Try to fix WindowManager$BadTokenException crashes on Android 7.
// https://stackoverflow.com/q/46030692/1837158
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
ActivityManager.RunningAppProcessInfo myProcess = new ActivityManager.RunningAppProcessInfo();
ActivityManager.getMyMemoryState(myProcess);
boolean isInBackground =
myProcess.importance != ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND;
if (isInBackground)
return;
}
LayoutInflater inflater = getLayoutInflater();
@SuppressLint("InflateParams")
View dialogLayout = inflater.inflate(R.layout.dialog_loading, null);