Completely new to Android and Java development in general, so please excuse any amateur ignorance and lack of terminology.
I am working on an Android application that includes fetching web pages as strings using a method based on the code available at http://www.spartanjava.com/2009/get-a-web-page-programatically-from- android / .
This takes a small but noticeable amount of time, but works great. It is launched by pressing a button in the user interface. Since the application does not respond to requests while receiving data, I have a toast that is designed to alert users before this happens.
Here, essentially, what is being done is done (and not the actual code, just illustrative):
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(); }
Unfortunately, the “Get Data” toast seems to only appear after the getPage method has completed, appearing very briefly before it closes with the “Data Retrieved” toast.
How can I avoid this by creating a “Data Retrieve” toast, then the getPage method is run, and a “Data Retrieved” toast appears when the method finishes?
Any suggestions would be highly appreciated. I expect the solution to include some kind of threads or synchronization, but I don’t even know where to start looking for the appropriate tutorial ...
Greg
source share