Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to implement a ProgressDialog while Activity requests a SoapObject from a Web Service?
    primarykey
    data
    text
    <p>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 a user clicks a button the Activity sends an auth request to the server 2) while this is being done a ProgressDialog is shown 3) when the reponse comes I want to dismiss the ProgressDialog and the return object to be read and interpreted by the Activity</p> <p>If I: 1) set the Thread to update the Application field with the reponse, the next method (which is outside of the Thread) throws an NPE when accessing the field 2) if I include the next method in the Thread, the second method throws a 'java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()'</p> <p>Sorry for a long text, but I am totally losing it over this... My code is sth like this:</p> <pre><code>public class XXX extends Activity implements OnClickListener { // (...) private SoapObject returnObject; private String response; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); // (...) authProgressDialog = ProgressDialog.show(XXX.this, "", "Authenticating...", true, false); new Thread(new Runnable() { @Override public void run() { authenticate(); // method that calls the API via SOAP authenticateReal(); // method that handles the response } }).start(); mHandler = new Handler() { public void handleMessage(Message msg) { super.handleMessage(msg); switch (msg.what) { case 10: authProgressDialog.dismiss(); break; } } }; } } public void authenticate() { // API stuff (...) AndroidHttpTransport aht = new AndroidHttpTransport(URL); try { aht.call(SOAP_ACTION, soapEnvelope); returnObject = (SoapObject) soapEnvelope.getResponse(); response = returnObject.getProperty("ResponseStatus").toString(); } catch (Exception e) { e.printStackTrace(); } finally { mHandler.sendEmptyMessage(10); } } // Method that needs to access returnObject and reponse objects and // it is here where the NPE's or other exceptions are thrown public void authenticateReal() { // (...) } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload