报错详情见https://www.bbsmax.com/A/x9J2DXZVd6/:
java.lang.RuntimeException: createContext failed: EGL_BAD_CONFIG
at android.opengl.GLSurfaceView$EglHelper.throwEglException(GLSurfaceView.java:)
at android.opengl.GLSurfaceView$EglHelper.throwEglException(GLSurfaceView.java:)
at android.opengl.GLSurfaceView$EglHelper.start(GLSurfaceView.java:)
at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:)
at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:)
测试发现,截止到最新arcgis版本100.5.0,在华为honor DUA-AL00(Android8.1.0)机型上依旧报这个错。
怎么办呢,只好捕获异常了。
解决方法如下:
package com.tepia.guangdong_module.amainguangdong.common;
import android.app.Activity;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import com.tepia.base.utils.LogUtil;
import com.tepia.base.utils.ToastUtils;
import com.tepia.base.utils.Utils;
import com.tepia.guangdong_module.amainguangdong.SplashOfGDActivity;
/**
* @author Liying
* on 2017-3-8.
*/
public class CrashHandler implements Thread.UncaughtExceptionHandler {
public static final String TAG = "CrashHandler";
private static CrashHandler INSTANCE = new CrashHandler();
private Context mContext;
private CrashHandler() {
}
public static CrashHandler getInstance() {
return INSTANCE;
}
public void init(Context context) {
//避免
mContext = context;
Thread.setDefaultUncaughtExceptionHandler(this);
}
@Override
public void uncaughtException(Thread thread, Throwable ex) {
//throwEglException
LogUtil.e(TAG, "some uncaughtException happend"+ex.getMessage());
String mes = ex.getMessage();
if (mes != null && mes.contains( "EGL_BAD_CONFIG")) {
LogUtil.e(TAG, "该机型不支持Arcgis地图");
ToastUtils.shortToast("该机型不支持Arcgis地图");
new Thread() {
@SuppressWarnings("WrongConstant")
@Override
public void run() {
((Activity)mContext).finish();
/* Intent intent = new Intent(mContext, SplashOfGDActivity.class);
PendingIntent restartIntent = PendingIntent.getActivity(mContext, 0, intent, Intent.FLAG_ACTIVITY_NEW_TASK);
AlarmManager mgr = (AlarmManager) mContext.getSystemService(Context.ALARM_SERVICE);
mgr.set(AlarmManager.RTC, System.currentTimeMillis() + 100, restartIntent);
android.os.Process.killProcess(android.os.Process.myPid());*/
}
}.start();
}else if(mes != null && mes.contains("EGL_SUCCESS")){
ToastUtils.shortToast("EGL_SUCCESS报错");
new Thread(){
@Override
public void run() {
((Activity)mContext).finish();
}
}.start();
}
}
}
这样至少能保证不崩溃。