title: Update ViewPager after Asynctask from the result
body: <p>I had a problem here.</p>
  
  <p>I have a login_activity that execute asynctask to get some result from a php file which it connects to mysql database.</p>
  
  <pre><code>public class login_main extends AppCompatActivity implements OnDataSendToActivity{
      ViewPager viewPager;
      CustomAdapter adapter;
  
      ArrayList&lt;String&gt; image = new ArrayList&lt;&gt;();
  
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_login_main);
          Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
          //setSupportActionBar(toolbar);
  
          String type = "getProfileImages";
  
          RetrieveData retrieveData = new RetrieveData(this);
  
          retrieveData.execute(type);
  
          //After Asycntask, get the result and put back into image array
  
          viewPager = (ViewPager) findViewById(R.id.view_pager);
          adapter = new CustomAdapter(login_main.this,image);
          viewPager.setAdapter(adapter);
      }
  
  
      public void sendData(String response) {
          try {
              JSONObject jsonObject = new JSONObject(response);
              JSONArray result = jsonObject.getJSONArray("result");
  
              for (int i = 0 ; i &lt; result.length(); i++) {
                  JSONObject obj = result.getJSONObject(i);
                  String id = obj.getString("image"+i);
                  image.add("http://192.168.12.252/"+id+"/profile.png");
              }
  
  
          } catch (JSONException e) {
              e.printStackTrace();
          }
      }
  </code></pre>
  
  <p>When i get the result i try to process the result by using interface from the asynctask</p>
  
  <pre><code>protected void onPostExecute(String result) {
          super.onPostExecute(result);
          dataSendToActivity.sendData(result);
  }
  </code></pre>
  
  <p>Everything is working fine except that the image array always empty when i pass it to the PageAdapter. How can i pass the data back to activity from asycntask and push into the array image, by using interface, it cant work.</p>
  
  <p>Or anyway i can directly process it in Asyntask and update the ViewPager.</p>
  
  <p>Here is my Asynctask</p>
  
  <pre><code>public class RetrieveData extends AsyncTask&lt;String,Void,String&gt;{
      Context context;
      RetrieveData(Context ctx) {
          context = ctx;
      }
      private OnDataSendToActivity dataSendToActivity;
  
      public RetrieveData(Activity activity){
          dataSendToActivity = (OnDataSendToActivity)activity;
      }
  
      @Override
      protected String doInBackground(String... params) {
          String profile_url = "http://192.168.12.252/getprofile.php";
          String image_url = "http://192.168.12.252/imagelist.php";
          String type = params[0];
  
          if(type.equals("getProfile")){
              try {
                  String user_name = params[1];
                  URL url = new URL(profile_url);
                  HttpURLConnection httpURLConnection = null;
                  httpURLConnection = (HttpURLConnection)url.openConnection();
                  httpURLConnection.setRequestMethod("POST");
                  httpURLConnection.setDoOutput(true);
                  httpURLConnection.setDoInput(true);
  
                  httpURLConnection.setDoOutput(true);
                  httpURLConnection.setDoInput(true);
                  OutputStream outputStream = httpURLConnection.getOutputStream();
                  BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(outputStream, "UTF-8"));
                  String post_data = URLEncoder.encode("user_name", "UTF-8")+"="+URLEncoder.encode(user_name, "UTF-8");
                  bufferedWriter.write(post_data);
                  bufferedWriter.flush();
                  bufferedWriter.close();
                  outputStream.close();
  
                  InputStream inputStream = httpURLConnection.getInputStream();
                  BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream,"iso-8859-1"));
                  String result = null;
                  result = bufferedReader.readLine();
                  bufferedReader.close();
                  inputStream.close();
                  httpURLConnection.disconnect();
                  return result;
              } catch (IOException e) {
                  e.printStackTrace();
              }
          }else if(type.equals("getProfileImages")){
              try {
                  URL url = new URL(image_url);
                  HttpURLConnection httpURLConnection = null;
                  httpURLConnection = (HttpURLConnection)url.openConnection();
                  httpURLConnection.setRequestMethod("POST");
                  httpURLConnection.setDoOutput(true);
                  httpURLConnection.setDoInput(true);
  
                  httpURLConnection.setDoOutput(true);
                  httpURLConnection.setDoInput(true);
                  OutputStream outputStream = httpURLConnection.getOutputStream();
                  BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(outputStream, "UTF-8"));
                  String post_data = URLEncoder.encode("Image", "UTF-8")+"="+URLEncoder.encode("Image", "UTF-8");
                  bufferedWriter.write(post_data);
                  bufferedWriter.flush();
                  bufferedWriter.close();
                  outputStream.close();
  
                  InputStream inputStream = httpURLConnection.getInputStream();
                  BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream,"iso-8859-1"));
                  String result = null;
                  result = bufferedReader.readLine();
                  bufferedReader.close();
                  inputStream.close();
                  httpURLConnection.disconnect();
                  return result;
              } catch (IOException e) {
                  e.printStackTrace();
              }
          }
          return null;
      }
  
      @Override
      protected void onPostExecute(String result) {
          super.onPostExecute(result);
          dataSendToActivity.sendData(result);
      }
  
      @Override
      protected void onPreExecute() {
          super.onPreExecute();
      }
  
      @Override
      protected void onProgressUpdate(Void... values) {
          super.onProgressUpdate(values);
      }
  }
  </code></pre>