asynctask android

0

czesc pobieram przy pomocy asynctask co kilka sekund dane z serwera, problem jest taki, ze wykonuje mi doinbackground, ale nie konczy wątku, tylko cały czas wykonany wątek trwa(onpostexecute sie nie wykonuje) i po kilku sekundach zaczynam nowy przez to pamięć się kończy i wyrzuca aplikacje

  class refresh extends AsyncTask<String, String, String> {

       @Override
        protected void onPreExecute() {
            super.onPreExecute();

        }

      
  protected String doInBackground(String... args) {

            runOnUiThread(new Runnable() {
                @Override
                public void run() {

                    RestAdapter adapter = new RestAdapter.Builder().setEndpoint(RestInterface.url).build();
                    final RestInterface restInterface = adapter.create(RestInterface.class);

                    restInterface.get(nick, pass, new Callback<LoginModel>() {
                        @Override
                        public void success(LoginModel model, Response response) {


      t1.setText("true");


                        }

                        @Override
                        public void failure(RetrofitError error) {

                            String merror = error.getMessage();
                            Toast.makeText(this, merror, Toast.LENGTH_LONG).show();
                        }
                    });


                }
            });
            return null;
        }

              protected void onPostExecute() {
         

            Toast.makeText(getApplicationContext(),"skonczone",Toast.LENGTH_LONG).show();


                }

            }
final Handler handler = new Handler();
Runnable refresh = new Runnable() {
        @Override
        public void run() {
            try {
              
new refresh().execute();
            } catch (NullPointerException e) {
                Log.e(TAG, "" + e);
            }
            handler.postDelayed(this, 3000);
        }
    };
handler.postDelayed(refresh, 3000);
0

Uruchamiasz coś w doInBackground po to aby zrobić tam runOnUiThread? Przecież to jest kompletnie bez sensu. Po to jest AsyncTask żeby on miał interakcję z UI, ale nie robi się tego przez runOnUIThread.

1 użytkowników online, w tym zalogowanych: 0, gości: 1