如何使用intent将onpostexecute方法的结果传递给另一个活动

时间:2014-03-18 10:02:31

标签: java android oncreate

我如何将从onpostexecute方法获得的结果传递给另一个活动或使用intent传递给oncreate方法

2 个答案:

答案 0 :(得分:1)

public void onPostExecute(String result){

     Intent intent = new Intent(ThisActivity.this, TargetActivity.class);
     intent.putExtra("YourData", result);
     StartActivity(intent)

}

通过getIntent()

进入另一项活动

答案 1 :(得分:0)

使用WeakReference类:

public static class LoginTask extends AsyncTask<String, Integer, Boolean> {
    WeakReference<Activity> mActivityReference;

    public LoginTask(Activity activity){
        this.mActivityReference = new WeakReference<Activity>(activity);
    }

    @Override
    protected Boolean doInBackground(String... params) {

         boolean sucess;

         //do some stuff

         return sucess;
    }

    @Override
    protected void onPostExecute(Boolean result) {
        if (result && mActivityReference.get() != null) {
            Activity activity = mActivityReference.get();
            activity.startActivity(new Intent(activity, MainViewActivity.class));
        }
    }
}