運行我編碼的程序,其從MySQL從服務器提取數據(使用JSON)和它更新UI因此,runOnUiThread不在的AsyncTask
我讀取兩種類型的數據使用的AsyncTask從服務器
1) Bubble Answers
2) Comments
的parseBubbleAnswers方法成功運行,並更新UI, 但parseComments類,這是的AsyncTask,並調用parseComments方法d oInBackground,不運行runOnUiThread(new Runnable() { run() });
誰能幫我解決這個
這裏是我的代碼:
public class FetchServer extends Activity
{
protected void onCreate(Bundle savedInstanceState)
{
String photoId = "1"; // photo id for which the data is fetched
checkBubbleData(photoId); // which call AsyncTask - 2 differnt calls
}
public void checkBubbleData(String photoId)
{
new parseBubbleAnswers().execute(photoId); // to fetch bubble answers
new parseComments().execute(photoId); // to fetch comments
}
class parseBubbleAnswers extends AsyncTask<String, Integer,String>
{
@Override
protected String doInBackground(String... params)
{
// TODO Auto-generated method stub
Looper.prepare();
parseBubbleAnswers(); // which has runOnUiThread(new Runnable() which updates (successfully !) the UI
return null;
}
}
class parseComments extends AsyncTask<String, Integer,String>
{
@Override
protected String doInBackground(String... params)
{
// TODO Auto-generated method stub
Looper.prepare();
String parseComReturn = parseComments();
if(parseComReturn=="end")
{
commentBuilder(); // which will update UI after fetch data by parseComments() method
}
}
}
public void commentBuilder()
{
runOnUiThread(new Runnable() // while debugging, it comes here, on Step Over it stick for 2 times and then move at the end of method without error
{
public void run()
{
// update UI code
}
});
}
}
檢查我在下面發佈的解決方案。讓我知道是否仍有問題。謝謝。 –