How can I make this happend?
Thread t = new Thread(new Runnable() {
@Override
public void run() {
FacebookConnectTask task =
new FacebookConnectTask("facebookId", "token", "email", facebookGender,0, 0);
task.setOnPreExecuteListener(this);
task.setOnDoneListener(this);
task.execute();
}
});
t.start();
public void onPreExecute() {
progressbar.setVisibility(View.VISIBLE);
}
public void onDone() {
progressbar.setVisibility(View.GONE);
}
Since I am opening a new thread, I can not change a UI element in it, so, How can I manage to do something to the UI, when the task starts and when it’s finished?
You could do the work in an
AyncTask. TheAsyncTaskexecutes everything indoInBackground()inside of another thread, which does not have access to the GUI where your views are.preExecute()andpostExecute()offer you access to GUI before and after the heavy lifting occurs in this new thread, you can even pass the result of the long operation topostExecute()to then show any results of processing.More here: http://developer.android.com/reference/android/os/AsyncTask.html
Example here: http://www.vogella.com/articles/AndroidPerformance/article.html