progress related problem in android using Threading!

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();

Answers


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...)


You can try using runOnUiThread, if you are in an activity class

mProgressStatus = 0;
    MyActivity.this.runOnUiThread(new Runnable() {});
        public void run() {
            if (mProgressStatus < 100) {
                myProgressBar.setVisibility(View.VISIBLE);
            } else {
                myProgressBar.setVisibility(View.GONE);
            }
        }
   });

Everything about the UI have to be executed in the UI Thread


Need Your Help

Deserialization Error: The XML element 'name' from namespace '' is already present in the current scope

c# xml serialization xml-serialization

This is my first time using XML Serialization and this is driving me absolutely nuts after 2 days of trying to troubleshoot this.

sizeof(array) does not give the expected value in this strstr reimplementation

c++ arrays pointers sizeof

I've got this simple strstr re-making as an exercise but there's an error I don't understand

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.