APP开发流程实例讲解-儒释道网络电台八天开发全程之
百度云深度兼容测试并进一步优化排错
APP开发流程实例讲解-儒释道网络电台八天开发全程
加入Log
测试前的准备,必须添加Log。添加Log是个非常好的编程习惯。在开发阶段,单步调试也不错。但在测试阶段,必须使用Log。添加一个Log的控制类(网上找来的)
/**
* Created by do168 on 16-7-9.
* Log.v() Log.d() Log.i() Log.w() 以及 Log.e() 。
* 根据首字母对应VERBOSE,DEBUG,INFO, WARN,ERROR
*
public static final int ASSERT = 7;
public static final int DEBUG = 3;
public static final int ERROR = 6;
public static final int INFO = 4;
public static final int VERBOSE = 2;
public static final int WARN = 5;
*/
public class MyLog {
public static int logLevel = Log.VERBOSE;
public static void i(String tag, String msg) {
if (logLevel <= Log.INFO)
android.util.Log.i(tag, msg);
}
public static void e(String tag, String msg) {
if (logLevel <= Log.ERROR)
android.util.Log.e(tag, msg);
}
public static void d(String tag, String msg) {
if (logLevel <= Log.DEBUG)
android.util.Log.d(tag, msg);
}
public static void v(String tag, String msg) {
if (logLevel <= Log.VERBOSE)
android.util.Log.v(tag, msg);
}
public static void w(String tag, String msg) {
if (logLevel <= Log.WARN)
android.util.Log.w(tag, msg);
}
}
使用也非常简单,在程序出错或需要记录信息的地方用上面的法就可以了。主要在WebApi中和VideoView错误输出时记录
public void GetNote(IStringEvent noteEvent) {
this.noteEvent = noteEvent;
noteLoadTimes = 0;
Request request = new Request.Builder()
.url(noteUrl)
.build();
client.newCall(request).enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
MyLog.e("GetNote onFailure", e.getMessage());
e.printStackTrace();
if(e.getCause().equals(SocketTimeoutException.class) && noteLoadTimes<maxLoadTimes)
{
noteLoadTimes++;
MyLog.w("GetNote onFailure", "e.getCause().equals(SocketTimeoutException.class) && noteLoadTimes<maxLoadTimes");
client.newCall(call.request()).enqueue(this);
} else {
WebApi.this.noteEvent.getMsg(null);
}
}
@Override
public void onResponse(Call call, Response response) throws IOException {
String html = new String(response.body().bytes(), "utf8");
Matcher m = noteItemPattern.matcher(html);
StringBuilder sb = new StringBuilder();
while (m.find()){
String nm = m.group(1);
if(nm.startsWith("<")) {
Matcher hm = htmlTagPattern.matcher(nm);
nm = hm.replaceAll("");
}
sb.append(nm).append("\r\n");
}
if(sb.length()==0)
MyLog.w("GetNote onResponse", html);
WebApi.this.noteEvent.getMsg(sb.toString());
}
});
}
VideoView错误输出时记录
videoView.setOnErrorListener(new MediaPlayer.OnErrorListener() {
@Override
public boolean onError(MediaPlayer mediaPlayer, int what, int extra) {
MyLog.e("MediaPlayer onError", "int what "+what+", int extra"+extra);
resetVideoView(false);
return false;
}
});
修正几个错误
经自己手工测试,发现了几个问题,加以修正
1、更新ListView :((ServerListAdapter)lv_servers.getAdapter()).notifyDataSetChanged();
2、失去焦点的处理
@Override
protected void onStop() {
MyLog.v("onStop", "程序关闭,关闭视频。");
resetVideoView(false);
super.onStop();
}
3、增加网络返回值返回NULL的检测
4、添加检测是否仅声音函数,替换变量
boolean isOnlySound(){return cb_onlySound.isChecked();}
使用百度云深度兼容测试
百度云深度兼容测试首次使用免费,每天前50名免费。测试用时约3分钟。
测试过程:注册登陆、上传APP、选择服务、等待约10分钟、查看结果
测试结果最热门的前50种机型中通过46种,有4种出问题。结果如下图:
问题列表
问题类型 | 出错定位 | 发生机型数 | 问题机型 |
---|---|---|---|
crash | 2 | ||
anr | 2 |
测试出来的内容主要有:结果综述、兼容报告、性能报告、终端列表
今天的工作就到这里吧。
源码地址 https://code.csdn.net/do168/buddhismnetworkradio