update:2020.5.11

fix:优化app内部网页管控
add:
This commit is contained in:
2020-05-11 18:34:39 +08:00
parent fbe3acd02b
commit eaa86225aa
11 changed files with 263 additions and 109 deletions

View File

@@ -5,6 +5,7 @@ import android.content.Context;
import android.content.Intent;
import android.content.res.Configuration;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.support.multidex.MultiDexApplication;
import android.util.Log;
@@ -63,7 +64,9 @@ import uk.co.chrisjenx.calligraphy.CalligraphyConfig;
* Created by Administrator on 2016/2/17 0017.
*/
public class MyApplication extends MultiDexApplication implements Thread.UncaughtExceptionHandler {
//public class MyApplication extends MultiDexApplication implements Thread.UncaughtExceptionHandler {
public class MyApplication extends MultiDexApplication {
public static String userName = null;
private static final String TAG = "--MyApplication--";
public static Context context;
@@ -117,7 +120,7 @@ public class MyApplication extends MultiDexApplication implements Thread.Uncaugh
JPushInterface.init(this);
context = getApplicationContext();
Thread.setDefaultUncaughtExceptionHandler(this);
// Thread.setDefaultUncaughtExceptionHandler(this);
mDateFormat = new SimpleDateFormat("HH:mm");
initOKHttp();
@@ -132,6 +135,7 @@ public class MyApplication extends MultiDexApplication implements Thread.Uncaugh
NetStateChangeReceiver.registerReceiver(this);
ToastUtil.init(this);
catchException();
}
@@ -437,26 +441,51 @@ public class MyApplication extends MultiDexApplication implements Thread.Uncaugh
}
@Override
public void uncaughtException(Thread thread, Throwable ex) {
Log.e(TAG, ex.getMessage(), new Exception(ex));
Utils.showToast(this, "程序出现异常,即将退出。。。");
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
e.printStackTrace();
}
Intent i = getBaseContext().getPackageManager()
.getLaunchIntentForPackage(getBaseContext().getPackageName());
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(i);
//退出程序
android.os.Process.killProcess(android.os.Process.myPid());
System.exit(1);
private void catchException() {
Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
@Override
public void uncaughtException(Thread t, Throwable e) {
Log.d("捕获异常子线程:", Thread.currentThread().getName() +
"在:" + e.getStackTrace()[0].getClassName());
}
}
);
//下面是新增方法!
new Handler(Looper.getMainLooper()).post(new Runnable() {
@Override
public void run() {
while (true) {
try {
Looper.loop(); //会先执行这个方法,然后在执行下面的异常捕获方法!
} catch (Exception e) {
Log.d("捕获异常主线程:", Thread.currentThread().getName() + "在:" + e.getStackTrace()[0].getClassName());
e.printStackTrace();
}
}
}
});
}
// @Override
// public void uncaughtException(Thread thread, Throwable ex) {
//// Log.e(TAG, ex.getMessage(), new Exception(ex));
//// Utils.showToast(this, "程序出现异常,即将退出。。。");
//// try {
//// Thread.sleep(3000);
//// } catch (InterruptedException e) {
//// e.printStackTrace();
//// }
//// Intent i = getBaseContext().getPackageManager()
//// .getLaunchIntentForPackage(getBaseContext().getPackageName());
//// i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
//// startActivity(i);
//// //退出程序
//// android.os.Process.killProcess(android.os.Process.myPid());
//// System.exit(1);
//
// }
@Override
public void onTerminate() {
super.onTerminate();
@@ -464,7 +493,7 @@ public class MyApplication extends MultiDexApplication implements Thread.Uncaugh
NetStateChangeReceiver.unregisterReceiver(this);
}
// static List<FileData> fileList = new ArrayList<>();
// static List<FileData> fileList = new ArrayList<>();
//
//
// static String packageName = "";
@@ -524,7 +553,7 @@ public class MyApplication extends MultiDexApplication implements Thread.Uncaugh
//
// }
// }
boolean isForecDownload = false;
boolean isForecDownload = false;
public boolean isDownloading() {
return isForecDownload;