android测试本地服务调试流程
我今天调试的整个过程
package test.OO.innerClass.innerClassObject;
import java.util.ArrayList;
import java.util.List;
public class testLocalVariableInFunction {
public static void main(String [] args){
final List<String> list = new ArrayList<String>();
list.add("kitty");
System.out.println("1,"+list);
Thread t1 = new Thread(new Runnable(){
public void run(){
System.out.println("2,"+list);
list.add("raoxiang");
System.out.println("3,"+list);
list.add("yan");
System.out.println("4,"+list);
}
});
// Thread t1 = new Thread(){
// public void run(){
// System.out.println("2,"+list);
// list.add("raoxiang");
// System.out.println("3,"+list);
// list.add("yan");
// System.out.println("4,"+list);
//
// }
// };
t1.start();
System.out.println("5,************************end1");
try {
t1.join();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("6,************************end2");
System.out.println("7"+list);
}
}
t1.start();
System.out.println("5,************************end1");
try {
t1.join();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("6,************************end2");
System.out.println("7"+list);
}
}
以下是解决问题后的网络连接部分的android代码,目的是从服务器取json转换为list返回,其中 NewsService.getLastNews()会启用网络连接,具体实现就不贴了
private List<HashMap<String,Object>> getNewes(){
final List<HashMap<String,Object>> data = new ArrayList<HashMap<String,Object>>();
Thread t1 = new Thread(){
@Override
public void run() {
try {
List<News> newes = NewsService.getLastNews();
for(News news : newes ){
HashMap<String,Object> item = new HashMap<String,Object>();
item.put("title",news.getTitle());
item.put("timelength",news.getTimelength());
data.add(item);
}
} catch (Exception e) {
e.printStackTrace();
}
}
};
t1.start();
try {
t1.join();
} catch (InterruptedException e) {
e.printStackTrace();
}
return data ;
}
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。