Android facebook等待AsyncFacebookRunner完成?
在我的应用程序中,我有一个ProgressDialog,在应用程序执行某些操作时显示:Android facebook等待AsyncFacebookRunner完成?,android,facebook,multithreading,Android,Facebook,Multithreading,在我的应用程序中,我有一个ProgressDialog,在应用程序执行某些操作时显示: mProgressDialog = ProgressDialog.show( ((FriendListActivity) ctx).getParent(), "Please wait...", "Getting data...", true); updateDisplay(true); 在updateDisplay方法中,它执行如下操作: items
mProgressDialog = ProgressDialog.show(
((FriendListActivity) ctx).getParent(), "Please wait...",
"Getting data...", true);
updateDisplay(true);
在updateDisplay方法中,它执行如下操作:
items = new ArrayList<FriendInfo>();
fa = new FriendListAdapter(ctx, R.layout.friendlist_item, items);
setListAdapter(fa);
Thread t = new Thread() {
public void run() {
getFriendList(); //This is where the problem occured
initFriendList();
handler.post(new Runnable() {
public void run() {
mProgressDialog.dismiss();
fa.notifyDataSetChanged();
};
});
}
};
t.start();
之后,用户信息将保存在我的数据库中。和initFriendList()代码>方法(下面的getFriendList()
)将使用该数据初始化视图
问题是我希望initFriendList()等待getFriendList()完成以获取数据。但是在getFriendList()
中,我使用AsyncFacebookRunner,因此initFriendList()将立即运行。如何使initFriendList()在运行之前等待AsyncFacebookRunner完成。我是android世界的新手,也许这些可以帮助我
特别是异步任务
可以使用泛型指定参数的类型、进度值和任务的最终值
方法doInBackground()在工作线程上自动执行
onPreExecute()、onPostExecute()和onProgressUpdate()都是在UI线程上调用的
doInBackground()返回的值被发送到onPostExecute()李>
您可以随时在doInBackground()中调用publishProgress()以在UI线程上执行onProgressUpdate()李>
您可以随时从任何线程取消任务
这里解释得很好
在正确的轨道上
--
AsyncFacebookRunner mAsyncRunner = new AsyncFacebookRunner(
facebook);
mAsyncRunner.request("me/friends&fields=name,picture",
new FriendsRequestListener((FriendListActivity) ctx,
currentuser));