android中使用线程的进度相关问题!
朋友们,
当我调用 Web 服务方法来 getposts 它显示进度时,我使用以下代码来显示 andorid 活动的进度。但是当服务调用完成时,我的应用程序崩溃了。
请指导我犯了什么错误或有其他替代方法来实现此目标吗?
mProgressStatus = 0;
Thread th=new Thread(new Runnable() {
public void run() {
if (mProgressStatus < 100) {
myProgressBar.setVisibility(View.VISIBLE);
} else {
myProgressBar.setVisibility(View.GONE);
}
}
});
th.start();
results = p.GetPosts(p, PageSize, adap.getCount());
mProgressStatus=100;
th.stop();
friends,
i am using following code to display progress on andorid activity when i call web service method to getposts it show progress. but when call of serivce is complete my application gets crashed.
please guide what mistake am i doing or any other alternative way to achieve this goal?
mProgressStatus = 0;
Thread th=new Thread(new Runnable() {
public void run() {
if (mProgressStatus < 100) {
myProgressBar.setVisibility(View.VISIBLE);
} else {
myProgressBar.setVisibility(View.GONE);
}
}
});
th.start();
results = p.GetPosts(p, PageSize, adap.getCount());
mProgressStatus=100;
th.stop();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
因此,如果您的应用程序崩溃,也许您应该首先查看错误消息?或者至少为我们提供它。
(提示:我今天读了您的三篇文章,您总是在粘贴代码的第一行/最后一行时遇到问题,请在提交问题之前检查您的代码粘贴...)
So, if your application crashes, maybe you should look at the error message first? Or at least provide it for us.
(A tip: I read three posts of you today and you always have trouble with the first/last lines of your code pasting, please check you code pasting before you submit a question...)
你可以尝试使用runOnUiThread,如果你在一个活动类中
关于UI的所有事情都必须在UI线程中执行
You can try using runOnUiThread, if you are in an activity class
Everything about the UI have to be executed in the UI Thread