AsyncTask: How do I access onPostExecute parameters?
So I am passing in a String array into my onPostExecute method, but I was wondering how I can access the output of this thread in the next activity... i.e. Page.class
Right now I am using a putExtra, is there anything else I can do? After the putExtra here, how can I access this in Page.class. Note that Page.class is NOT the class that starts this thread.
public void onPostExecute(String[] x){
d.dismiss();
Intent i= new Intent(ctx,Page.class);
i.putExtra("values", x);
ctx.startActivity(i);
Intent b = getIntent();开发者_运维知识库
String[] values = b.getStringArrayExtra("values");
Log.d("hello", values[0]);
Your Page.class
is the activity started by onPostExecute()
, right?
Then whatever you put in the Extra Bundle would be accessible. @Gix already posted the way to access the bundle, so I am not repeating here. But please checkout the bundle class to see what you can put inside (Basically almost all primitives and arrays are OK)
In onCreate(...)
of your 'Page' Activity, simply use Intent i = getIntent()
then use String[] values = i.getStringArrayExtra("values")
If you are starting the activity Page straight from the onPostExecute you should be able to access the extras in the Page Activity without any problem. The way to do that is using the following code:
Bundle extras = getIntent().getExtras();
String values = extras.getString("values");
and there you have them
精彩评论