我有一个 Asynctask 检索两个 int 值,我想将它们传递给 onPostExecute 以在视图上显示它们。
这是我的代码:
public class QueryServer extends AsyncTask <String, Void, Integer> {
protected Integer doInBackground(String... serverAddress) {
Log.d("QueryServer", ""+serverAddress[0]);
MCQuery mcQuery = new MCQuery("" + serverAddress[0] ,25565);
QueryResponse response = mcQuery.basicStat();
int Onlineplayers = response.getOnlinePlayers(); //first vaule
int Maxplayers = response.getMaxPlayers(); //second vaule
Log.d("MCQuery", "" + Onlineplayers + " OnlinePlayers");
return Onlineplayers;
}
protected void onPostExecute(Integer Onlineplayers){
TextView onlinePlayersView = (TextView) findViewById(R.id.online_players);
onlinePlayersView.setText(""+Onlineplayers+"/"+ Maxplayers); //i need to pass Maxplayers to use it here
}
先感谢您。