If your thread is stopping, it is an issue in your implementation of
doInBackground(), which you haven't shown.  And whatever your problem is,
you will have it with a Thread as well.  AsyncTask is just doing work from
threads, after all.

On Tue, Mar 27, 2012 at 1:18 AM, martypantsROK <martyg...@gmail.com> wrote:

> I have an operation that consumes too much time for the UI thread and
> need to do it in another thread. I created a thread using AsyncTask
> and the thread loops until it finds and answer. When its done, I use
> postExecute to deal with the data and update views. The problem is
> that the thread intermittently stops in the middle of a long loop with
> no errors. Sometimes it goes through all data looking, sometimes, the
> thread returns having only looped through a portion.
>
> I posted a question on Stackoverflow, but the only answer I got was
> not to use AsyncTask but just use threads without providing any
> reasoning or details why one is better than another.
>
> What do folks here think?  Is there something wrong with the way I've
> implemented my AsyncTask? Or is the stackoverflow poster correct in
> that I should just blindly use Thread without understanding why this
> is incorrect, good, bad, ugly or whatever.
>
> private void playDeviceTile() {
>
>    if (mDbHelper.isPlayingDevice(game_id)) {
>
>        // make sure I'm seeing all played tiles
>        refreshPlayedTiles();
>
>        final Boolean found;
>
>
>
>        final ProgressDialog dialog = new ProgressDialog(mcontext);
>        dialog.setMessage("Android is thinking...");
>        dialog.show();
>
>            new AsyncTask<Void,Void, Boolean>(){
>                @Override
>                protected void onPostExecute(Boolean isFound) {
>                    if (!isFound) {
>
>                            passPlay(1);  // never found a tile to
> play. We have to pass
>                        }
>                        else {
>                           playTile(currentTile,1);
>
>                       }
>                    dialog.dismiss();
>                    postInvalidate();
>                    invalidate();
>                }
>
>                @Override
>                protected Boolean doInBackground(Void... params) {
>                    try {
>                        return doSearchforSpot();
>                    } catch (Exception e) {
>                        Log.e("DRAW", "Exception find spot for device
> tile", e);
>                    }
>                    return null;
>                }
>
>            }.execute();
>
>    }
> }
>
> --
> 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
>



-- 
Dianne Hackborn
Android framework engineer
hack...@android.com

Note: please don't send private questions to me, as I don't have time to
provide private support, and so won't reply to such e-mails.  All such
questions should be posted on public forums, where I and others can see and
answer them.

-- 
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