在Android应用程序中,如果我们没有得到正确的例外,我们通常会收到"强制关闭"错误.
如果强行关闭,如何自动重启我的应用程序?
是否有任何特定的权限用于此?
是否有代码示例或有关如何使用该Thread.setDefaultUncaughtExceptionHandler方法的教程?基本上我在我的应用程序中尝试在抛出异常时显示自定义警报对话框.是否有可能做到这一点?我知道在屏幕上显示某些内容有点棘手,如果在UI线程中抛出异常,但我不知道任何解决方法.
你知道Android的任何崩溃报告库吗?
我不想花很多时间来编写自己的报告系统.
输出可以发送到电子邮件或某种服务器.
我知道谷歌在Froyo中引入了崩溃报告,但我想要一些旧版本的系统.
让我们总结一下答案:
我和Gson和ProGuard度过了一段难忘的时光.我有一个简单的对象,当我解析tojson时,保存到sqllite并从数据库读回以便将json加载回我的对象,我得到一个java.lang.classcastexception.如果我不使用ProGuard,everthing工作正常.
我已经验证了发送到数据库并从数据库获取的json字符串是相同的.从json转换时不会抛出异常,而是在我尝试访问对象时抛出异常.
这是我的简单对象:
public class ScanLog extends ArrayList<SingleFrame>
{
private static final long serialVersionUID = 1L;
public ScanLog()
{
}
}
public final class SingleFrame
{
public int Position;
public int Time;
public Map<Integer,String> MainDataMap;
public Map<Integer,String> DataMap;
public SingleFrame(int position, int time,
Map<Integer,String> mainDataMap, Map<Integer,String> dataMap)
{
this.Position = position;
this.Time = time;
this.MainDataMap = mainDataMap;
this.DataMap = dataMap;
}
}
Run Code Online (Sandbox Code Playgroud)
我的应用程序的所有其他方面都很好,但使用proguard导致这种情况发生....我已经在proguard.cfg中尝试了各种-keep命令,但我不确定我做的是对的.
编辑 - 添加PROGUARD.CFG
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontpreverify
-verbose
-dontshrink
-dontoptimize
-keep public class * extends android.app.Activity
-keep public …Run Code Online (Sandbox Code Playgroud) 我有一个新的Android应用程序,我几天前在市场上.我在发布之前对我的机器人机器人进行了相当多的测试,并试图进行彻底的测试.好吧,我得到了一些负面的评论,说明它是如何在某人的EVO 2.2或X10上运行的(甚至不知道最初是什么).好吧,它在我的手机上运行完美.
关于我应该如何修复或支持在100种不同手机上运行的应用程序的任何建议?
其他开发者如何接近这个?(实际上没有购买每部手机).谢谢.
有没有办法在您的应用程序触发ANR(应用程序无响应)时收到通知?类似于默认的异常处理程序?
期待"你会用它做什么"的答案,只需记录.不做"做"任何事情.
在我的onCreate()中,我设置了一个UncaughtException处理程序,如下所示:
Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
@Override
public void uncaughtException(Thread thread, Throwable throwable) {
Log.e(getMethodName(2), "uncaughtException", throwable);
android.os.Process.killProcess(android.os.Process.myPid());
}
});
Run Code Online (Sandbox Code Playgroud)
它工作正常,但我想恢复系统向用户显示强制关闭对话框的默认行为.
如果我尝试KillProcess()用throw throwable编译器替换调用,抱怨我需要用try/catch包围它.
如果我用try/catch包围它:
Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
@Override
public void uncaughtException(Thread thread, Throwable throwable) {
try {
Log.e(getMethodName(2), "uncaughtException", throwable);
throw throwable;
}
catch (Exception e) {
}
finally {
}
}
});
Run Code Online (Sandbox Code Playgroud)
编译器仍然抱怨throw throwable需要用try/catch包围.
我如何重新扔掉那个扔掉的?这样,除了信息量之外,Log.e()系统的行为与以前完全一样:因为我从未设置默认的UncaughtException处理程序.
我故意让自己的应用程序崩溃.我得到以下对话框.

但是,我希望通过报告按钮获得以下崩溃对话框.

我可以知道怎么做吗?我签了申请.(但我将APK本地转移到我的手机,而不是通过Android市场).我仍然无法得到Report按钮.
我的应用程序导致一个强制关闭某个地方,但我没有在我的LogCat中获得通常(且信息量很大)堆栈跟踪的致命异常,我只收到以下4行:
06-27 07:08:54.546: D/dalvikvm(14351): GC_FOR_MALLOC freed 9923 objects / 657416 bytes in 21ms
06-27 07:08:54.769: W/dalvikvm(14351): threadid=20: thread exiting with uncaught exception (group=0x4001d7f0)
06-27 07:08:54.796: W/dalvikvm(14351): threadid=21: thread exiting with uncaught exception (group=0x4001d7f0)
06-27 07:08:54.796: I/Process(14351): Sending signal. PID: 14351 SIG: 9
Run Code Online (Sandbox Code Playgroud)
这是在DEBUG模式下,LogCat上没有应用过滤器!
更新:感谢下面的@assylias,我已经能够实现:
final UncaughtExceptionHandler subclass = Thread.currentThread().getUncaughtExceptionHandler();
Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
@Override
public void uncaughtException(Thread paramThread, Throwable paramThrowable) {
Log.getStackTraceString(paramThrowable);
subclass.uncaughtException(paramThread, paramThrowable);
}
});
Run Code Online (Sandbox Code Playgroud)
这产生了这些增加的线:
06-27 08:24:47.105: D/dalvikvm(15475): GC_FOR_MALLOC freed 13865 objects / 1435952 bytes in …Run Code Online (Sandbox Code Playgroud) 我一直想知道是否可以通过捕获父活动中的崩溃来阻止Android应用程序崩溃.
假设我在子活动的onCreate方法中导致致命异常,我能否以任何方式捕获该异常?或者无论我尝试什么,应用程序都会崩溃?
这是我的意思的一个例子:
Main.java
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.ly_main);
// My Main activity starts
try{
// Call the next activity
Intent intent = new Intent(getApplicationContext(), Child.class);
startActivity(intent);
}catch(Exception e){
Log.wtf("Exception_WTF","Exception from child activity woohoo \n "+ e.toString());
}
Run Code Online (Sandbox Code Playgroud)
Child.java
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.ly_child);
// Create exception... for science
int a = 0;
a = 1/a;
}
Run Code Online (Sandbox Code Playgroud)
这不起作用.子活动死亡并将父母带走.
是否可以通过startActivityForResult来实现?
谢谢,
编辑:我不需要崩溃数据,我只是想知道如何避免应用程序崩溃.
环顾四周我发现: 在android上使用全局异常处理
其中包括这件作品:
Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
@Override
public void uncaughtException(Thread paramThread, Throwable paramThrowable) …Run Code Online (Sandbox Code Playgroud)