Note that there are some explanatory texts on larger screens.

plurals
  1. POPreventing Internet-accessing-method from delaying a toast popup
    primarykey
    data
    text
    <p>Quite new to Android development and Java in general, so please excuse any amateur ignorance and lack of terminology.</p> <p>I'm working on an Android app that involves fetching Web pages as strings, using a method based on the code available at <a href="http://www.spartanjava.com/2009/get-a-web-page-programatically-from-android/" rel="nofollow">http://www.spartanjava.com/2009/get-a-web-page-programatically-from-android/</a>.</p> <p>This takes a small but noticeable amount of time, but works fine. It is triggered by pressing a button in the UI. Since the application is unresponsive while data is being fetched, I've got a toast that is meant to warn users before it happens.</p> <p>Here is essentially what is being done (not the actual code, just illustrative):</p> <pre><code>public void buttonPressed(View view) { Toast.makeText(this, "Getting Data!", Toast.LENGTH_LONG).show(); //See the page linked above for the code in this function! String page = getPage("http://www.google.com/"); Toast.makeText(this, "Data Retrieved!", Toast.LENGTH_LONG).show(); } </code></pre> <p>Unfortunately, The "Getting Data" toast only seems to appear after the getPage method has completed, appearing very briefly before being covered up by the "Data Retrieved" toast.</p> <p>How do I avoid this, making the "Getting Data" toast appear, then the getPage method run, then the "Data Retrieved" toast appear when the method terminates?</p> <p>Any suggestions would be much appreciated. I expect the solution involves some kind of threads or synchronisation, but don't even know where to start looking for an appropriate tutorial...</p> <p>Greg</p>
    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.
    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