Android';s Log.wtf是否终止我的应用程序?
我想将我的应用程序的错误报告记录到Android Market错误控制台;看起来我可以用这个Android';s Log.wtf是否终止我的应用程序?,android,Android,我想将我的应用程序的错误报告记录到Android Market错误控制台;看起来我可以用这个 Log.wtf的文档说明: 多么可怕的失败:报告一个永远不会发生的情况。错误将始终与调用堆栈一起记录在断言级别。根据系统配置,可能会向DropBoxManager添加报告和/或使用错误对话框立即终止该过程 在我的例子中,我可以捕获这些异常并通过显示错误消息从中恢复;我不希望我的应用程序崩溃,但我确实希望将报告发送到错误控制台 在什么情况下,Log.wtf会终止我的应用程序?是否可以在不导致应用程序崩溃的
Log.wtf
的文档说明:
多么可怕的失败:报告一个永远不会发生的情况。错误将始终与调用堆栈一起记录在断言级别。根据系统配置,可能会向DropBoxManager添加报告和/或使用错误对话框立即终止该过程
在我的例子中,我可以捕获这些异常并通过显示错误消息从中恢复;我不希望我的应用程序崩溃,但我确实希望将报告发送到错误控制台
在什么情况下,
Log.wtf
会终止我的应用程序?是否可以在不导致应用程序崩溃的情况下获取错误报告?这取决于您的系统设置(可以启用某些选项进行调试,但在正常设备上禁用)。当为设备和内核编译android时,它们是启用的设置
我建议使用带有前缀的Log.e()而不是Log.wtf()来避免任何问题,例如wtf:发生了可怕的事情
下面是调用Log.wtf()时发生的情况
->Log.java
/**
* What a Terrible Failure: Report an exception that should never happen.
* Similar to {@link #wtf(String, Throwable)}, with a message as well.
* @param tag Used to identify the source of a log message.
* @param msg The message you would like logged.
* @param tr An exception to log. May be null.
*/
public static int wtf(String tag, String msg, Throwable tr) {
TerribleFailure what = new TerribleFailure(msg, tr);
int bytes = println_native(LOG_ID_MAIN, ASSERT, tag, getStackTraceString(tr));
sWtfHandler.onTerribleFailure(tag, what);
return bytes;
}
private static TerribleFailureHandler sWtfHandler = new TerribleFailureHandler() {
public void onTerribleFailure(String tag, TerribleFailure what) {
RuntimeInit.wtf(tag, what);
}
};
->Log.java
/**
* What a Terrible Failure: Report an exception that should never happen.
* Similar to {@link #wtf(String, Throwable)}, with a message as well.
* @param tag Used to identify the source of a log message.
* @param msg The message you would like logged.
* @param tr An exception to log. May be null.
*/
public static int wtf(String tag, String msg, Throwable tr) {
TerribleFailure what = new TerribleFailure(msg, tr);
int bytes = println_native(LOG_ID_MAIN, ASSERT, tag, getStackTraceString(tr));
sWtfHandler.onTerribleFailure(tag, what);
return bytes;
}
private static TerribleFailureHandler sWtfHandler = new TerribleFailureHandler() {
public void onTerribleFailure(String tag, TerribleFailure what) {
RuntimeInit.wtf(tag, what);
}
};
->RuntimeInit.java
/**
* Report a serious error in the current process. May or may not cause
* the process to terminate (depends on system settings).
*
* @param tag to record with the error
* @param t exception describing the error site and conditions
*/
public static void wtf(String tag, Throwable t) {
try {
if (ActivityManagerNative.getDefault()
.handleApplicationWtf(mApplicationObject, tag,
new ApplicationErrorReport.CrashInfo(t))) {
// The Activity Manager has already written us off -- now exit.
Process.killProcess(Process.myPid());
System.exit(10);
}
} catch (Throwable t2) {
Slog.e(TAG, "Error reporting WTF", t2);
}
}
->ActivityManagerActive.java
public boolean handleApplicationWtf(IBinder app, String tag,
ApplicationErrorReport.CrashInfo crashInfo)
throws RemoteException {
Parcel data = Parcel.obtain();
Parcel reply = Parcel.obtain();
data.writeInterfaceToken(IActivityManager.descriptor);
data.writeStrongBinder(app);
data.writeString(tag);
crashInfo.writeToParcel(data, 0);
mRemote.transact(HANDLE_APPLICATION_WTF_TRANSACTION, data,
reply, 0);
reply.readException();
boolean res = reply.readInt() != 0;
reply.recycle();
data.recycle();
return res;
}
以下是nebkat的信息。小心使用WTF:该设备的API级别必须是8或更高。我没有直接回答你的问题,但你可以考虑使用远程StcTrace:我过去使用过它,它在找到我所有的bug方面都有很大的帮助。当我读到那个代码时,看起来Log.wtf将根据MrRead回复的内容崩溃应用程序。看来我还是得用远程Stacktrace了。