How to add AsyncTask in an HttpURLConnection?

后端 未结 3 1478
我寻月下人不归
我寻月下人不归 2020-12-11 09:08

I\'m establishing a server connection, my problem is that I need to put an AsyncTask on my code, because its not working in sdk version 10 up. I do

3条回答
  •  囚心锁ツ
    2020-12-11 09:59

    Refer below code

    new FetchRSSFeeds().execute();
    
    
    private class FetchRSSFeeds extends AsyncTask {
    
        private ProgressDialog dialog = new ProgressDialog(HomeActivity.this);
    
        /** progress dialog to show user that the backup is processing. */
        /** application context. */
    
        protected void onPreExecute() {
            this.dialog.setMessage(getResources().getString(
                    R.string.Loading_String));
            this.dialog.show();
        }
    
        protected Boolean doInBackground(final String... args) {
            try {
    
                /**
                 * Write your URL connection code and fetch data here
                 */
    
                return true;
            } catch (Exception e) {
                Log.e("tag", "error", e);
                return false;
            }
        }
    
        @Override
        protected void onPostExecute(final Boolean success) {
    
            if (dialog.isShowing()) {
                dialog.dismiss();
            }
    
                 /* Show the String on the GUI. */
                        aTextView.setText(aString);
                        this.setContentView(aTextView);
    
        }
    }
    

提交回复
热议问题