我如何将从onpostexecute方法获得的结果传递给另一个活动或使用intent传递给oncreate方法
答案 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));
}
}
}