java Android内存不足事件 11 月 Questions & Answers 621 是否有任何方法可以统计发生的内存不足事件,甚至 如果只有几个 我主要关心的是事件的数量以及事件发生的时间。它是 我正在构建的应用程序中需要 是否有一些API支持,或者我需要解析一些文件
# 1 楼答案 如果您可以在开发环境中重现OOM错误,那么您可以使用Logcat查看GC消息,并可能在应用程序中记录事件。DDMS Eclipse视图中还提供了许多工具,帮助您跟踪分配并准确查看哪些对象占用内存 关于android dev site有大量可用信息
# 2 楼答案 您可以使用类似于Crashlytics的东西,它是免费的,并且易于设置。它会自动向您发送崩溃报告,无需向用户提示任何内容,并提供有关手机的完整堆栈跟踪和统计信息(即使没有互联网连接) 或者类似的东西能抓住一切: import java.io.FileOutputStream; import java.io.IOException; import android.app.Activity; import android.content.Context; public class SRSDexception implements Thread.UncaughtExceptionHandler { private Thread.UncaughtExceptionHandler defaultUEH; private Activity app = null; public SRSDexception(Activity app) { this.defaultUEH = Thread.getDefaultUncaughtExceptionHandler(); this.app = app; } public void uncaughtException(Thread t, Throwable e) { StackTraceElement[] arr = e.getStackTrace(); String Raghav =t.toString(); String report = e.toString()+"\n\n"; report += " - Stack trace -\n\n"+Raghav; for (int i=0; i<arr.length; i++) { report += " "+arr[i].toString()+"\n"; } report += " -\n\n"; // If the exception was thrown in a background thread inside // AsyncTask, then the actual exception can be found with getCause report += " - Cause -\n\n"; Throwable cause = e.getCause(); if(cause != null) { report += cause.toString() + "\n\n"; arr = cause.getStackTrace(); for (int i=0; i<arr.length; i++) { report += " "+arr[i].toString()+"\n"; } } report += " -\n\n"; try { FileOutputStream trace = app.openFileOutput( "stack.trace", Context.MODE_PRIVATE); trace.write(report.getBytes()); trace.close(); } catch(IOException ioe) { // ... } defaultUEH.uncaughtException(t, e); } } 找到here
# 1 楼答案
如果您可以在开发环境中重现OOM错误,那么您可以使用Logcat查看GC消息,并可能在应用程序中记录事件。DDMS Eclipse视图中还提供了许多工具,帮助您跟踪分配并准确查看哪些对象占用内存
关于android dev site有大量可用信息
# 2 楼答案
您可以使用类似于Crashlytics的东西,它是免费的,并且易于设置。它会自动向您发送崩溃报告,无需向用户提示任何内容,并提供有关手机的完整堆栈跟踪和统计信息(即使没有互联网连接)
或者类似的东西能抓住一切:
找到here