How to implement a ProgressDialog while Activity requests a SoapObject from a Web Service?

后端 未结 4 1767
既然无缘
既然无缘 2021-01-21 09:06

I know that ProgressDialog with Threads questions have been asked many times but none of the solutions seem to work for my project. Basically what I want to do is this: 1) when

4条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-21 10:03

    You better use AsyncTask (which is the Android way):

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    
        new TheTask().execute();
    }
    
    private class TheTask extends AsyncTask{
    
        @Override
        protected void onPreExecute() {
            authProgressDialog = ProgressDialog.show(XXX.this, "", "Authenticating...", true, false);
        }
    
        @Override
        protected Void doInBackground(Void... params) {
            authenticate(); // method that calls the API via SOAP
            authenticateReal(); // method that handles the response
            return null;
        }
    
        @Override
        protected void onPostExecute(Void result) {
            authProgressDialog.dismiss();
        }
    }
    

    By the way... I have found this presentation to be very useful (it talks about REST apps, but you can apply the same concept for different kind of apps): Developing Android REST client applications

提交回复
热议问题