I want to move my AsyncTask String value to another class with my constructor, my asynctask class is this
GetTiempoGoogle.class
public class GetTiempoGoogle extends AsyncTask<Void, Void, Void> {
private Context context;
String dateStr;
@Override
protected Void doInBackground(Void... voids) {
try{
HttpClient httpclient = new DefaultHttpClient();
HttpResponse response = httpclient.execute(new HttpGet("https://google.com/"));
StatusLine statusLine = response.getStatusLine();
if(statusLine.getStatusCode() == HttpStatus.SC_OK){
DateFormat df = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss z");
dateStr = response.getFirstHeader("Date").getValue();
Date startDate = df.parse(dateStr);
dateStr = String.valueOf(startDate.getTime()/1000);
//Here I do something with the Date String
} else{
//Closes the connection.
response.getEntity().getContent().close();
throw new IOException(statusLine.getReasonPhrase());
}
}catch (ClientProtocolException e) {
Log.d("Response", e.getMessage());
}catch (IOException e) {
Log.d("Response", e.getMessage());
} catch (ParseException e) {
e.printStackTrace();
}
return null;
}
// can use UI thread here
protected void onPostExecute(final Void unused) {
}
public String getDateStr() {
return dateStr;
}
}
I have my getter there (getDateStr) which will return a google time date, so I need to access this value in my other class, what I did is this
MyActivity.class
GetTiempoGoogle Uconexion = new GetTiempoGoogle();
Uconexion.execute();
String Uconexionapp = Uconexion.getDateStr();
Log.e("UconexionApp",""+Uconexionapp);
it seems that when I try to get the value is null... and I don't know why, I was trying a lot of things but I can't reach the date value.