4

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 ActivityB ? Thanks.

kevin lynx
  • 785
  • 9
  • 17

2 Answers2

1

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

Community
  • 1
  • 1
kevin lynx
  • 785
  • 9
  • 17
0

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();
Gilbou
  • 5,244
  • 6
  • 24
  • 27