1

In my application some times it may take large time to load some values( like retrieving driving directions from google maps).This results in the launch of the "Wait" alert dialog.I wish to know what happens when the Force close button is clicked? I mean What code will be run when the force close is enabled? Do we can manually adjust the time for which the "Wait" alert dialog appears? If not what is the default time by which this dialog appears?

freshDroid
  • 509
  • 1
  • 5
  • 16

4 Answers4

2

I know it can sometimes be annoying but they made it pretty much purposely (in my opinion) to ensure programmers make sure their app runs smoothly with no UI freezing .. I cant find the documents about it right now but if I remember correctly its about 4 seconds.. you just need to make sure that there is no UI freeze or delay in your app which means that if your values takes more then a couple of seconds to load they should be loading asynchronously.
you need to move any heavy loading from your main activity to run asynchronusly (using async task or a thread).

Joe
  • 2,252
  • 1
  • 22
  • 32
  • it mainly happens when i try to get driving directions from google map!! – freshDroid Dec 01 '11 at 07:55
  • yes.. any online data pulling should be happening asynchronously. since you don't know how strong the user connection is or how long will it take to pull the data from the servers then you cant make your user wait (freeze the UI) in waiting for the data .. it has to be done in a thread or async-task so the main activity is not waiting for the data. your app wont crash even if it takes it an hour to load as long as your main activity is not freezing. – Joe Dec 01 '11 at 08:04
  • I'm pretty sure that on force close it just shut down your app's VM .. so no. but don't take my word for it, you can easily check it for yourself by putting a line of code under onDestroy() and see if it runs.. – Joe Dec 01 '11 at 08:15
  • can you please suggest me a good example or tutorial that dealt with async tasks android? – freshDroid Dec 01 '11 at 11:36
  • I don't know any specific tutorial but in my opinion the best way to get the basic understanding is by reading the official article document-http://developer.android.com/resources/articles/painless-threading.html (and also the links I added in my answer) and after that I bet your google skills are as good as mine :) – Joe Dec 01 '11 at 13:57
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/5499/discussion-between-freshdroid-and-joe) – freshDroid Dec 01 '11 at 13:58
1

You should read this article on Android threading.

You never want to perform any long-running tasks on your main thread. If the operation is going to take more than a fraction of a second, you should be using AsyncTask or creating your own background thread to perform the task.

goto10
  • 4,370
  • 1
  • 22
  • 33
0

As far as I know, when you get to that dialog, the Android OS has taken over and is killing your process. If this is a regular occurrence, a stack dump should be of use to figure out what is crashing your app.

0

You should not be doing time-consuming initialization on the event thread. You should start a background thread (or AsyncTask) to do the initialization work. See the guide topic Designing for Responsiveness. Follow-up reading should include Processes and Threads and Painless Threading.

Ted Hopp
  • 232,168
  • 48
  • 399
  • 521
  • @freshDroid - I don't think so. The OS has taken over and is in the process of killing your app. – Ted Hopp Dec 01 '11 at 14:26
  • @freshDroid - That's the only way, I think. Do all time-consuming work off the event thread. (In Honeycomb and later, I believe, you will get an exception if you try to make a network connection on the event thread.) – Ted Hopp Dec 01 '11 at 15:17