您的位置:首页 > 其它

学习andoid 遇到的小问题

2013-08-08 08:40 134 查看
13-8-10

这两天为了在android实现网络下载的功能出现android.os.NetworkOnMainThreadException(在java上实现是没问题的,但放到android上各种问题)

在android2.3上设计的下载程序,在android4.0上运行时报android.os.NetworkOnMainThreadException异常,原来在4.0中,访问网络不能在主程序中进行,有两个方法可以解决,一个是在主程序中增加:另一种是启动线程执行下载任务:publicvoidonCreate(BundlesavedInstanceState){super.onCreate(savedInstanceState);setContentView(R.layout.main);//启动线程执行下载任务newThread(downloadRun).start();}/***下载线程*/RunnabledownloadRun=newRunnable(){@Overridepublicvoidrun(){//TODOAuto-generatedmethodstubupdateListView();}};
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//启动线程执行下载任务
newThread(downloadRun).start();
}

/**
*下载线程
*/
RunnabledownloadRun=newRunnable(){

@Override
publicvoidrun(){
//TODOAuto-generatedmethodstub
updateListView();
}
};
UI更新的问题:
android.view.ViewRootImpl$CalledFromWrongThreadException:Onlytheoriginalthreadthatcreatedaviewhierarchycantouchitsviews.
/article/4192182.html

                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: