Android中更详细的log获取方法


今天在分析QuickSearchBox中看到一种新的记录log的方式。Debug.startMethodTracing(String filePath).(packages\ apps\QuickSearchBox\src\com\android\quicksearchbox\SearchActivity.java)

该方法将程序运行详细trace信息,包括方法的开始结束、应用运行状况等全部写入一个file的方式记录下来(参考Debug类)。


使用方法:

在onCreate中添加如下代码:

public void onCreate(Bundle savedInstanceState) {
mTraceStartUp = getIntent().hasExtra(INTENT_EXTRA_TRACE_START_UP);
if (mTraceStartUp) {
String traceFile = new File(getDir("traces", 0), "qsb-start.trace").getAbsolutePath();
Log.i(TAG, "Writing start-up trace to " + traceFile);
Debug.startMethodTracing(traceFile);
}

·······

}


在onResume中停止方法的跟踪:

protected void onResume() {
super.onResume();
if (mTraceStartUp) Debug.stopMethodTracing();
}


注意startMethodTracing和stopmethodTracing是成对使用的。在程序开发中可以使用该形式将程序运行状态记录下来,并且在出现bug的时候传回给开发者。


另:在xiaanming的博客上面看到博文--将crash信息保存到SD卡上。也对应用程序开发者很有帮助,有兴趣的朋友可以移步一观。










评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值