我有这个问题,当我尝试加载新视图时,在我得到服务响应之前我得到黑屏。现在为了解决这个问题,我使用了 AsyncTask 并且我已经解决了这个问题,但问题是我没有从我的服务中获得输出。下面是我的代码。
class GetInfo extends AsyncTask<String, String, String> {
/**
* Before starting background thread Show Progress Dialog
* */
@Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(NewHomeView.this);
pDialog.setMessage("Loading...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(true);
pDialog.show();
}
/**
* Creating player
* */
protected String doInBackground(String... args) {
goal = MMBusinessFacade.baseURL;
goal = goal + "getGoal.jsp?acno=" + acnt;
goal = goal.replaceAll(" ", "%20");
res = MMBusinessFacade.getXML(goal, NewHomeView.this);
NewHomeView.res1 = gp.getOutput(res);
System.out.println("URL:" + goal);
System.out.println("Output:" + res1);
/********************************************************************************************/
spnrshi1 = MMBusinessFacade.baseURL;
spnrshi1 = spnrshi1 + "getFunds.jsp?acno=" + acnt;
spnrshi1 = spnrshi1.replaceAll(" ", "%20");
res = MMBusinessFacade.getXML(spnrshi1, NewHomeView.this);
System.out.println("URL" + spnrshi1);
list1 = fdp.getOutputOrg1(res);
list = fdp.getOutputOrg(res);
if (list1 != null && list1.size() > 0) {
for (int j = 0; j < list1.size(); j++) {
FundsAvailable prpobj = (FundsAvailable) list1.get(j);
FundDetail prpobj1 = (FundDetail) list.get(j);
ite = prpobj.getAmount() + " " + prpobj.getCurrency();
System.out.println("Item:" + ite);
NewHomeView.favail = prpobj1.getAmount() + " " + prpobj1.getCurrency();
NewHomeView.cur = prpobj.getCurrency();
}
}
return null;
}
/**
* After completing background task Dismiss the progress dialog
* **/
protected void onPostExecute(String file_url)
{
// dismiss the dialog once done
pDialog.dismiss();
gl.setText(NewHomeView.res1);
avilfund.setText(NewHomeView.ite);
fndraised.setText(NewHomeView.favail);
}
}
请给您宝贵的建议。谢谢