I have rephrased the question again to try to better clarify the need for my situation:
I need to run between the following activity's activityaa, by clicking the button, the application sends an information to a php page, which from this information generates a Query, validates the data and creates a JSON file on the server, then the application takes this file and le the JSON file.
I can now send the information to a PHP that generates JSON and I can also read the JSON file, but I can not run the two functions in sequence in the application . Someone has a vision of how to run this process with AsyncTask or another native Android class.
Below the code I retrieve the information in the JSON file that is saved on the server.
public class BackGroundWorkerItensActivity extends AsyncTask<String, Void, String> {
Context context;
public BackGroundWorkerItensActivity(Context context){
this.context = context;
}
@Override
protected String doInBackground(String... params) {
String iddist = params[0];
String url_receber = "http://minhaurl.com/teste/dados.json";
try {
URL url = new URL(url_receber);
HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
httpURLConnection.setRequestMethod("POST");
httpURLConnection.setDoInput(true);
httpURLConnection.setDoOutput(true);
InputStream inputStream = httpURLConnection.getInputStream();
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream, "iso-8859-1"));
String result="";
String line = "";
while ((line = bufferedReader.readLine()) != null) {
result += line;
}
bufferedReader.close();
inputStream.close();
httpURLConnection.disconnect();
return result;
} catch (IOException e) {
Log.i("DadosDist", "Erro na lista dos itens!");
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(String s) {
super.onPostExecute(s);
Intent intentLD = new Intent(context, MainActivity.class);
Log.i("Vem JSON", s);
intentLD.putExtra("JSON", s);
context.startActivity(intentLD);
}
If it is not well detailed, let me know what I will add more information.