The problem is that the code quoted below ties up the application's main thread while it's loading data from the Internet. This has serious consequences for the UI, as the message loop stops working for that period of time, possibly causing the "Application Not Responding" dialog (ANR for short), offering the user to kill the program. Even if that doesn't happen, the UI cannot update during that time, since it relies on that message loop to keep working.

http://developer.android.com/guide/practices/design/responsiveness.html

Programming in Java (Android or not) running on top of a framework is very much not like programming in JavaScript running inside a web browser.

http://developer.android.com/guide/topics/fundamentals/processes-and-threads.html#Threads

Accurately predicting how long an HTTP transaction over the Internet will take is a task that would make Nostradamus proud.

And since there are no guarantees, you just can't run networking code on the main UI thread, you need to run that code elsewhere, on a worker thread.

Android offers several ready-made mechanisms for that "elsewhere": such as IntentService, or AsyncTask (probably easiest to start with).

-- Kostya

11.03.2011 21:14, Aisthesis пишет:
I have the identical code in a similar situation, and the dialog
showed up when i put in a timer before dismissing it. On mine, I've
basically assumed that the data retrieval and processing is happening
before the dialog really has a chance and am hoping that it will show
up on phones that are using a slower 3G connection rather than a
direct connection to the net.

See it yours works if you throw in a timer to make it wait a few
seconds before calling dismiss(). I'm betting that it will.

I'll leave it to others to say whether it will work properly without
the timer when actually deployed, as I haven't reached that point yet.

On Mar 10, 6:12 pm, David Williams<dwilli...@dtw-consulting.com>
wrote:
All,

I have my main class GolfCaddie.java which is called when the app is
launched.  GolfCaddie.java extends the TabActivity.
I have 3 other classes, one for each tab, and at the moment these 3
classes just display text or graphics.

In GolfCaddie.java the code is broken down as follows.   Trying to
simply it but can provide full code if needed:

onCreate
      Set up Tabs
      Call initApp

onCreateOptionsMenu
      Setup options Menu

initApp
      ProgressDialog dialog = ProgressDialog.show(GolfCaddie.this,
"","Initializing. Please wait...", true);
      Set up some variables
      Obtain deviceID
      Checks app name, and determines if this is the trial version or the
full version
      Makes a call to my server and returns a JSONObject which is then
decoded and certain items checked.
      If the app is the trial version AND the trial date has passed throw
up an Alert with a message. Only option is to click OK which closes the App.
      Otherwise, if the app is the trial version through up an alert
showing when the trial expires.
      dialog.dismiss();

That's it for now.  Very crude but working.  My problem is that the
ProgressDialog never shows up, and all the code in initApp is done
against a black screen, even though the onCreate sets the tab default to
0, which has a graphical backdrop.  Probably not doing this in the
correct way, but I was hoping for the ProgressDialog to display (againt
Tab(0) which has the background image) whilst it performs the code in
initApp.  The call to my server is quick, but it's possible it can take
upwards of 10-20 seconds depending upon connectivity and so wanted to at
least show that something was happening.  Having a black screen is not
great at all.

Would appreciate any help, and again, I can provide more detailed code
if needed.

TIA.
--
------------------------------------------------------------------------

David Williams
Check out our WebOS mobile phone app for the Palm Pre and Pixi:
<http://www.dtw-consulting.com/GolfCaddie>  Golf Caddie
<http://www.dtw-consulting.com/GolfCaddie>  | Golf Caddie Forum
<http://www.dtw-consulting.com/GolfCaddie/forum>  | Golf Caddie FAQ
<http://www.dtw-consulting.com/GolfCaddie/faq.html>  by DTW-Consulting, Inc.


--
Kostya Vasilyev -- http://kmansoft.wordpress.com

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to