From 818e04c68728d9a4e21c2fbe93e3f23cb1fceb7e Mon Sep 17 00:00:00 2001 From: zlzw <583819556@qq.com> Date: Wed, 7 Sep 2022 13:09:40 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E4=BF=AE=E5=A4=8D=E9=A6=96=E6=AC=A1?= =?UTF-8?q?=E8=BF=9B=E5=85=A5=E9=9A=8F=E6=9C=BA=E8=BF=9B=E5=AF=86=E7=A0=81?= =?UTF-8?q?=E6=88=BF=E5=BC=B9dialog=E5=AF=BC=E8=87=B4=E9=97=AA=E9=80=80?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/shayu/phonelive/AppContext.java | 9 ++++++++- .../com/shayu/phonelive/NeverCrashUtils.java | 20 +++++++++++++++++++ .../yunbao/main/activity/LoginActivity.java | 12 +++++------ 3 files changed, 34 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/com/shayu/phonelive/AppContext.java b/app/src/main/java/com/shayu/phonelive/AppContext.java index 4205d336e..fdb5dfb3f 100644 --- a/app/src/main/java/com/shayu/phonelive/AppContext.java +++ b/app/src/main/java/com/shayu/phonelive/AppContext.java @@ -4,13 +4,16 @@ import android.app.Activity; import android.app.ActivityManager; import android.content.Context; import android.net.http.HttpResponseCache; +import android.os.Build; import android.os.Bundle; import android.os.Message; import android.text.TextUtils; import android.util.Log; +import android.widget.Toast; import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import androidx.annotation.RequiresApi; import com.adjust.sdk.Adjust; import com.adjust.sdk.AdjustConfig; @@ -33,6 +36,8 @@ import com.yunbao.common.manager.imrongcloud.InstructorSendReward; import com.yunbao.common.manager.imrongcloud.InstructorSendRewardProvider; import com.yunbao.common.manager.imrongcloud.MessageIMManager; import com.yunbao.common.manager.imrongcloud.RecommendLiveRoom; +import com.yunbao.common.utils.FileUtil; +import com.yunbao.common.utils.ToastUtil; import com.yunbao.live.views.RecommendLiveRoomProvider; import com.yunbao.common.manager.imrongcloud.RongcloudIMManager; import com.yunbao.common.utils.L; @@ -44,6 +49,8 @@ import com.yunbao.main.activity.MsgSettActivity; import java.io.File; import java.io.IOException; +import java.io.PrintWriter; +import java.io.StringWriter; import java.util.ArrayList; import io.rong.imkit.config.RongConfigCenter; @@ -208,7 +215,7 @@ public class AppContext extends CommonAppContext { } } } catch (Exception e) { - + e.printStackTrace(); } return false; } diff --git a/app/src/main/java/com/shayu/phonelive/NeverCrashUtils.java b/app/src/main/java/com/shayu/phonelive/NeverCrashUtils.java index bf9b557c4..00a795770 100644 --- a/app/src/main/java/com/shayu/phonelive/NeverCrashUtils.java +++ b/app/src/main/java/com/shayu/phonelive/NeverCrashUtils.java @@ -1,8 +1,16 @@ package com.shayu.phonelive; import android.app.Application; +import android.content.Context; import android.os.Handler; import android.os.Looper; import android.util.Log; +import android.widget.Toast; + +import com.yunbao.common.utils.FileUtil; + +import java.io.File; +import java.io.PrintWriter; +import java.io.StringWriter; /** * @ClassName NeverCrashUtils @@ -86,6 +94,8 @@ public class NeverCrashUtils { if (isDebugMode()) { Log.e(TAG, "未捕获的主线程异常行为", e); } + Toast.makeText(application, "发生闪退", Toast.LENGTH_SHORT).show(); + FileUtil.saveStringToFile(new File(application.getDir("files", Context.MODE_PRIVATE).getAbsolutePath()),throwableToString(e),"error.log"); getMainCrashHandler().mainException(Looper.getMainLooper().getThread(), e); } } @@ -96,7 +106,11 @@ public class NeverCrashUtils { if (isDebugMode()) { Log.e(TAG, "未捕获的子线程异常行为", e); } + Toast.makeText(application, "发生闪退", Toast.LENGTH_SHORT).show(); + FileUtil.saveStringToFile(new File(application.getDir("files", Context.MODE_PRIVATE).getAbsolutePath()),throwableToString(e),"error.log"); + getMainCrashHandler().mainException(Looper.getMainLooper().getThread(), e); getUncaughtCrashHandler().uncaughtException(t, e); + }); } @@ -107,4 +121,10 @@ public class NeverCrashUtils { public interface UncaughtCrashHandler { void uncaughtException(Thread t, Throwable e); } + private static String throwableToString(Throwable e) { + StringWriter writer=new StringWriter(); + PrintWriter printWriter=new PrintWriter(writer); + e.printStackTrace(printWriter); + return "[ERROR]"+writer.toString(); + } } \ No newline at end of file diff --git a/main/src/main/java/com/yunbao/main/activity/LoginActivity.java b/main/src/main/java/com/yunbao/main/activity/LoginActivity.java index 49f6d7986..d2eb1eab9 100644 --- a/main/src/main/java/com/yunbao/main/activity/LoginActivity.java +++ b/main/src/main/java/com/yunbao/main/activity/LoginActivity.java @@ -92,9 +92,10 @@ public class LoginActivity extends AbsActivity { protected int getLayoutId() { return R.layout.activity_login; } + @Subscribe(threadMode = ThreadMode.MAIN) public void onRegSuccessEvent(RegSuccessEvent e) { - if (!isFinishing()){ + if (!isFinishing()) { finish(); } } @@ -318,13 +319,12 @@ public class LoginActivity extends AbsActivity { public void onSuccess(int code, String msg, String[] info) { if (info[0] != null && mFirstLogin == true) { JSONObject obj = JSON.parseObject(info[0]); - if(obj.containsKey("home_zdy_img_us")) { + if (obj.containsKey("home_zdy_img_us")) { home_zdy_img_us = obj.getString("home_zdy_img_us"); home_zdy_img_cn = obj.getString("home_zdy_img_cn"); } MainActivity.forward(LoginActivity.this, false); - finish(); - gotoLive(obj.getString("anchor_id")); + //gotoLive(obj.getString("anchor_id")); IMLoginManager.get(mContext).setisNewUserOne(true); IMLoginManager.get(mContext).setNewUserGif(true); if (obj.containsKey("home_zdy_pop")) { @@ -332,8 +332,8 @@ public class LoginActivity extends AbsActivity { } } else { MainActivity.forward(LoginActivity.this, false); - finish(); } + finish(); } }); @@ -349,6 +349,7 @@ public class LoginActivity extends AbsActivity { this.finish(); } } + /** * 三方登录 */ @@ -383,7 +384,6 @@ public class LoginActivity extends AbsActivity { } - @Override protected void onDestroy() { if (mAnimator != null) {