Asin task get data

   new Retrive().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, id);
    }

    class Retrive extends AsyncTask<String, Void, String> {

        @Override
        protected void onPreExecute() {

            super.onPreExecute();
        }

        @Override
        protected String doInBackground(String... param) {
            String data = null;
            String success = null;
            try {

                Log.e("Value", "--->" + param[0]);
                data = URLEncoder.encode("p_id", "UTF-8") + "=" + URLEncoder.encode("", "UTF-8");

                // data = URLEncoder.encode("p_id", "UTF-8")+ "=" + URLEncoder.encode("267", "UTF-8");

            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }

            String text = "";
            BufferedReader reader = null;

            // Send data
            try {

                // Defined URL  where to send data
                URL url = new URL("http://sktechnocast.brijeshgohel.com/android/feach_image.php");

                // Send POST data request
                URLConnection conn = url.openConnection();
                conn.setDoOutput(true);
                OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
                wr.write(data);
                wr.flush();

                // Get the server response

                reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
                StringBuilder sb = new StringBuilder();
                String line = null;

                // Read Server Response
                while ((line = reader.readLine()) != null) {
                    // Append server response in string
                    sb.append(line + "\n");
                }


                text = sb.toString();
                Log.e("Responce", "" + text);

                        try {
                            JSONObject j = new JSONObject(text);
                            Log.e("Http Post Response:", "" + j);
                            success = j.getString("success");
                            Log.e("success value : " + success, "");
                            JSONArray j1 = j.getJSONArray("result");
                            for (int i = 0; i < j1.length(); i++) {
                                JSONObject obj = j1.getJSONObject(i);
                                id = obj.getString("p_id");
                                Image = obj.getString("p_image");

                                 contactList.add(id);
                                 contactList1.add(Image);
                            }
                        } catch (JSONException e) {

                        }

            } catch (Exception ex) {

            } finally {
                try {

                    reader.close();
                } catch (Exception ex) {
                }
            }
            // Show response on activity
            return success;
        }

        @Override
        protected void onPostExecute(String s) {
            super.onPostExecute(s);
            if (s.equals("1")) {

                //    Toast.makeText(feachimage.this, id, Toast.LENGTH_LONG).show();
                //  Toast.makeText(feachimage.this, Image, Toast.LENGTH_LONG).show();
            } else {

            }

            Toast.makeText(feachimage.this, id, Toast.LENGTH_LONG).show();
            Toast.makeText(feachimage.this, Image, Toast.LENGTH_LONG).show();

            GalleryAdapterPAR adapter = new GalleryAdapterPAR(contactList, contactList1, getApplicationContext());

            lv1.setAdapter(adapter);
        }
    }

Comments

Popular posts from this blog

retrofil gjstatus lanuage

form object

Login Preference in android create class