简体   繁体   中英

Pass results from child activity to Parent Tab Activity

I have 6 activities in my app which are Activity1, Activity2, TabActivity, childTab1, childtab2, ExtraActivity.

App flow:

Activity1 => Activity2 => TabActivity =>ChildTab1 or ChildTab2 => ExtraActivity

Now i want to pass some data from ExtraActivity to Activity1 . I am using StartActivityForResult for starting all activities.

ExtraActivity is able to send data to ChildTab1 or ChildTab2 but i unable to send that data back to TabActivity and further back to Activity2 and finally to Activity1 .

Please help!!

Update: While searching, i got my solution via this post:

How to return a result (startActivityForResult) from a TabHost Activity?

I think you can delegate the onActivityResult method-result from ChildTabX to TabActivity with ((TabActivity)getParent()).onActivityResult(). There you just call setResult and finish() again to send the result to Activity2. Same for Activity2

You could use the application context to pass data between activites.

Way to use app context.

Extend the application class and add the attributes as you require. So in your activity you can access the application context and get the data. As the application context is a singleton it will be the same instance in every activity.

MyApplication appContext = (MyApplication) getApplicationContext();
appContext.myString = "YOUR DATA;

In any other activity you can access that bitmap the same way.

MyApplication appContext = (MyApplication) getApplicationContext();

Now the string is in the appContext object.

You also need to add

android:name=".MyApplication"

to application tag in the manifest file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM