How to get activity result from an Activity in a TabHost?
In my application, Activity A will start a TabActivity, and the TabActivity has some Activity in its content.
tabHost.newTabSpec("tab1").setContent( new Intent(this, ActivityB.class ) ) ...
And ActivityB will get some data from user(i.e pick a contact), and i want ActivityA will get these data. But as you see, it seems I cannot startyActivityForResult and onActivityResult to get result.
So, how can i get data in ActivityA from开发者_JAVA百科 ActivityB ? Thanks.
Again there's no answer to my question. So i have to solve it myself. My solution is ugly but worked. As somebody can guess, we can write a singleton class to store these data. ActivityB will write data and ActivityA will read it. Very easy.
In contrast, i searched in this site, and found some simple solution. Like here
Create a class for the object you want to store (ie: ObjectYouWantToStore).
Extend the android.app.Application.
public class MyApp extends android.app.Application {
private ObjectYouWantToStore mObject;
public ObjectYouWantToStore getObject() {;
return mObject;
}
public void setObject(ObjectYouWantToStore obj) {
mObject = obj;
}
}
Write in the manifest file the path to the Application.
<application android:icon="@drawable/icon" android:label="@string/app_name" android:name=".MyApp">
Store the data in your activity B
MyApp app = (MyApp)getApplicationContext();
app.setObject(ObjectYouWantToStore);
Access the same data in your activity A
MyApp app = (MyApp)getApplicationContext();
ObjectYouWantToStore obj = app.getObject();
精彩评论