我使用以下代碼向服務器發出請求。我調用了該函數一次,但請求被發送了兩次。我從服務器返回的結果來自第二個請求結果。如何只向服務器發送一個請求?我存儲所有我的:Classrunnablespublic class ServerRunnables implements Runnable { Account currentAccount = Account.getInstance(); private String result = ""; private Context context; private Boolean callSuccess = true; int serviceCalled; String email; String password; String username; int coinChanges; String urlString = "http://10.0.2.2/MobileCoin/" + services[serviceCalled]; String requiredParams; public ServerRunnables(Context context, int serviceCalled, String email, String password, String username, int coinChanges) { this.context = context; this.serviceCalled = serviceCalled; this.email = email; this.password = password; this.username = username; this.coinChanges = coinChanges; } public void run() { urlString = "http://10.0.2.2/MobileCoin/" + services[serviceCalled]; switch (serviceCalled) { case SERVICE_RANDOM_COIN: generateCoinServiceCalled(); break; default: break; } } private void generateCoinServiceCalled() { requiredParams = "email=" + email; urlString = urlString + "?" + requiredParams; getMethodCalled(urlString); callSuccess = true; String message1 = ""; if (result.equals(ServerConstants.RANDOM_COIN_EMPTY)) { callSuccess = false; message1 = "No Data Received"; } else if (result.equals(ServerConstants.RANDOM_COIN_FAIL)) { callSuccess = false; message1 = "Data Does not Exist."; } else if (result.equals(ServerConstants.CONNECTION_ERROR)) { callSuccess = false; message1 = "Connection Error, Check Server"; } }
添加回答
舉報
0/150
提交
取消