I have this (attached)code which works perfectly on all the AVDs I create with eclipse. It calls a php file on a website. The php script files the xxx when the call http://somebody.me.uk/testingphp/signup.php?user=xxx is made. The php script does not give a response nor do I want one, the stuff in the loop of the code below is what I want to capture in the php file. In the real world, a nexus one phone with this code fails to contact the php script. In trying to resolve the problem I inserted lines of code creating toasts between the lines of code in the try block. Suddenly the app starts working and the php files the xxx. I presume this is due to introducing a delay on the nexus one while it shows the toasts, and gives chance for the communications to work. Any Ideas how to resolve the problem (without using toasts) Thank you.
private boolean hasSolution(){
if (cells.solve()) {
// send to web site for QA analysis.
String urlString = "http://somebody.me.uk/testingphp/signup.php?user=" ;
for (int j=0; j<9; j++) {
for (int i=0; i<9; i++) {
urlString += cells.getSolution(i, j);
}// end for i
}// end for j
try {
URL url = new URL(urlString);
URLConnection conn = url.openConnection();
BufferedReader rd = new BufferedReader(new InputStreamReader(conn.ge开发者_如何学PythontInputStream()));
rd.close();
}catch (IOException e) {Toast.makeText(app.this, "io error", Toast.LENGTH_SHORT).show();}
return true;
}// end if
return false;
}
//define this two variable in your activity
private ProgressDialog pDialog = null;
private Runnable submittingScore;
submittingScore = new Runnable(){
@Override
public void run()
{
try {
do your task here
}
catch (Exception e) {
pDialog.dismiss();
// TODO Auto-generated catch block
e.printStackTrace();
}
}
};
Thread thread = new Thread(null, submittingScore, "MultibreifsBackground");
thread.start();
pDialog = ProgressDialog.show(postServer.this,
"Please wait...", "Submitting Scores...", true);
Put the pDialog.dismiss
in all the catch methods. Now when you call the URL, it will show processing until the URL is complete
精彩评论