0

i am using HttpURLConnection and i want to create async application. for example if data changed into mysql database the auto update into application.

i read about handler but i cant understand how can i use in my case.

here is my code for getting data from database using api

private class GetGroupsMember extends AsyncTask<String, Void, String> {
        @Override
        protected String doInBackground(String... params) {
            String response = null;
            try {
                URL url = new URL(params[0]);
                HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
                InputStream inputStream = urlConnection.getInputStream();
                urlConnection.connect();
                BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
                response = bufferedReader.readLine();
                bufferedReader.close();
                urlConnection.disconnect();
                return  response;
            } catch (MalformedURLException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return null;
        }

        @Override
        protected void onPostExecute(String response){
            super.onPostExecute(response);
            Log.d("response",response);
        }
    }
AskNilesh
  • 67,701
  • 16
  • 123
  • 163
Kaushik Makwana
  • 2,422
  • 9
  • 31
  • 50
  • 1
    Don't reinvent the wheel. If you want auto updates, you can use Firebase, Realm Sync, or Couchbase Lite – OneCricketeer Sep 18 '17 at 06:10
  • 1
    @cricket_007 is right go with Firebase, Realm Sync, or Couchbase Lite or start background service for check auto updates. – Damodhar Sep 18 '17 at 06:38
  • 1
    Also [please **research** your topic](https://www.google.com/search?q=site%3Astackoverflow.com+android+mysql+sync) – OneCricketeer Sep 18 '17 at 06:52

0 Answers0