How i pass the result obtained from onpostexecute method to another activity or into oncreate method using intent
Asked
Active
Viewed 739 times
-3
-
Send a bundle of data with the intent, then in the new Activity catch it by overriding the onNewIntent() method. – cYrixmorten Mar 18 '14 at 10:06
-
1Please don't just open another question. Instead edit your previous question and provide the additional information requested by the users trying to help you – super-qua Mar 18 '14 at 10:07
-
Check this link to get result to main activity. Once you got the result, you can pass it to next activity: http://stackoverflow.com/questions/12575068/how-to-get-the-result-of-onpostexecute-to-main-activity-because-asynctask-is-a – Lokesh Mar 18 '14 at 10:09
2 Answers
1
public void onPostExecute(String result){
Intent intent = new Intent(ThisActivity.this, TargetActivity.class);
intent.putExtra("YourData", result);
StartActivity(intent)
}
and get it in another activity via getIntent()
Mathias Müller
- 21,291
- 13
- 56
- 74
NullPointerException
- 3,912
- 4
- 32
- 52
-
1@user3431956 Please do not edit someone's answer and add code. Instead, edit your _question_. – Mathias Müller Mar 24 '14 at 09:42
0
Use WeakReference class:
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));
}
}
}
NullPointerException
- 3,912
- 4
- 32
- 52
Swagat Mali
- 156
- 9
-
Thank you rashmi for your reply. Unfortunately i tried this previously but its not working.I will paste my code tomorrow hope you might be able to answer it – user3431956 Mar 18 '14 at 11:18