I just modified my onPostExecute(...) method:

protected void onPostExecute(String result) {

                        Log.i("LOGGER", "Done...");
                        pDialog.dismiss();
                        if(result=="success"){
                                Toast.makeText(ctx, "complete", 
Toast.LENGTH_LONG).show();
                                Intent i=new Intent(ctx,SillyActivity.class);
                                startActivity(i);
                        }else{
                                Toast.makeText(ctx, "fail", 
Toast.LENGTH_LONG).show();
                        }



                super.onPostExecute(result);
        }

ctx is my context
I noticed that I can't call the startActivity(Intent i) method within
the AsyncTask, how else would I start an activity from here?

On Mar 6, 10:13 pm, Romain Guy <[email protected]> wrote:
> onPostExecute() is invoked on the UI thread so you can use this method
> to start an Activity. It's pretty much what it's for.
>
>
>
>
>
> On Fri, Mar 5, 2010 at 6:29 AM, John Wesonga <[email protected]> wrote:
> > I have a simple app and I'm using the AsyncTask to test out a
> > background process, for clearness purposes I've opted to put my
> > AsyncTask in a separate class rather than in an inner class, which
> > where my problems begin, this is my AsyncTask
>
> > package org.tutorial.test101.tasks;
>
> > import android.app.ProgressDialog;
> > import android.content.Context;
> > import android.os.AsyncTask;
> > import android.util.Log;
>
> > public class LoginTask extends AsyncTask<String, String, String> {
>
> >        Context ctx;
> >        ProgressDialog pDialog;
>
> >        public LoginTask(Context context){
> >                super();
> >                this.ctx=context;
> >        }
> >       �...@override
> >        protected String doInBackground(String... params) {
> >                Log.i("LOGGER", "Starting...");
> >                try{
> >                        Thread.sleep(8000);
> >                }catch(InterruptedException e){
>
> >                }
> >                return null;
> >        }
>
> >       �...@override
> >        protected void onPostExecute(String result) {
>
> >                        Log.i("LOGGER", "Done...");
> >                        pDialog.dismiss();
> >                      //
> >                super.onPostExecute(result);
> >        }
>
> >       �...@override
> >        protected void onPreExecute() {
> >                pDialog=new ProgressDialog(ctx);
> >                pDialog.setTitle("Login");
> >                pDialog.setMessage("doing stuff..");
> >                pDialog.show();
> >        }
>
> > }
>
> > What I'd like is that once the task is complete, I do something in the
> > UI thread may be start another activity or even display a Toast saying
> > activity complete. I know I can't start a new Activity in the
> > onPostExecute() so I need to start it in the UI thread any idea how I
> > can do this? This is my Activity that starts the AsyncTask
>
> > package org.tutorial.test101.activities;
>
> > import org.tutorial.test101.tasks.LoginTask;
>
> > import android.app.Activity;
> > import android.app.Dialog;
> > import android.content.Context;
> > import android.os.AsyncTask;
> > import android.os.Bundle;
> > import android.util.Log;
> > import android.view.View;
> > import android.view.View.OnClickListener;
> > import android.widget.Button;
>
> > public class Test101 extends Activity{
> >        private Button btnLogin;
> >        private LoginTask mLoginTask;
> >        private Context context=this;
> >    /** Called when the activity is first created. */
> >   �...@override
> >    public void onCreate(Bundle savedInstanceState) {
> >        super.onCreate(savedInstanceState);
> >        setContentView(R.layout.main);
> >        btnLogin=(Button)findViewById(R.id.btnLogin);
> >        btnLogin.setOnClickListener(new OnClickListener(){
>
> >                        public void onClick(View v) {
> >                                if(mLoginTask==null){
> >                                        mLoginTask=new LoginTask(context);
> >                                        mLoginTask.execute(null);
> >                                }
>
> >                        }
>
> >        });
> >    }
>
> > }
>
> > --
> > You received this message because you are subscribed to the Google
> > Groups "Android Developers" group.
> > To post to this group, send email to [email protected]
> > To unsubscribe from this group, send email to
> > [email protected]
> > For more options, visit this group at
> >http://groups.google.com/group/android-developers?hl=en
>
> --
> Romain Guy
> Android framework engineer
> [email protected]
>
> Note: please don't send private questions to me, as I don't have time
> to provide private support.  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 [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to