-1

i have this code and in MyAsyncOpenUrl i get a jason and parse it to read server message . i store it in a public variable name message. but my problem is the if statement is running before the server message arrives. how can i wait the task until i get the message ? by what i read in this question it seems i can use get method , but i dont know how to use it ?!!! :(

message = "";
MyAsyncOpenUrl task1 = new MyAsyncOpenUrl("http://test.com/op.php");
  try {
    task1.execute(myURL).get();
     } catch (InterruptedException e) {
    e.printStackTrace();
  } catch (ExecutionException e) {
  e.printStackTrace();
   }
//task1.onPostExecute(null);


if (message.equals("fail"))
      Toast.makeText(getBaseContext(), "Operation faild!", Toast.LENGTH_LONG).show();
Community
  • 1
  • 1
Saeid
  • 448
  • 1
  • 7
  • 19

1 Answers1

0

In tour asyncTask override method onPostExecute.

onPostExecute = your response is ready to use.

Esperanz0
  • 1,524
  • 13
  • 35
  • how can i give the url to onPostExecute ? – Saeid Aug 18 '16 at 12:42
  • please read about asynctask http://stackoverflow.com/questions/25647881/android-asynctask-example-and-explanation/25647882#25647882 – Esperanz0 Aug 18 '16 at 12:45
  • thankyou Esperanz0 , but i think it is not what i am seeking for , onPostExecute cant get my url , and i dont want to change my UI layout in it , be cause i want to use it for different urls and different actions. so i just need the message :( – Saeid Aug 18 '16 at 13:00