这里有一些可以帮助你的代码.
首先创建一个类
import java.lang.Thread.UncaughtExceptionHandler;
import android.content.Context;
import android.content.SharedPreferences;
public class ExceptionHandler implements UncaughtExceptionHandler {
private Context context;
public ExceptionHandler(Context context) {
super();
this.context = context;
}
public void uncaughtException(Thread thread, Throwable ex) {
SharedPreferences prefs = context.getSharedPreferences("Your_preference_name", Context.MODE_PRIVATE);
prefs.edit().putBoolean("is_force_closed", true).commit();
}
}
Run Code Online (Sandbox Code Playgroud)
然后在应用程序的主要活动中初始化此类
ExceptionHandler exp = new ExceptionHandler(getApplicationContext());
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
118 次 |
| 最近记录: |