How to pass data between TabHost's Activities in android -
i trying pass data between 2 activities of tabhost not succeded. here code:
public class androidtablayoutactivity extends tabactivity { @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.main); tabhost tabhost = gettabhost(); tabspec livedata = tabhost.newtabspec("photoes"); livedata.setindicator("photoes", getresources().getdrawable(r.drawable.icon_photos_tab)); intent livedataintent = new intent(this, photosactivity.class); livedata.setcontent(livedataintent); tabspec addedlegs = tabhost.newtabspec("songs"); addedlegs.setindicator("songs", getresources().getdrawable(r.drawable.icon_songs_tab)); intent addedlegsintent = new intent(this, songsactivity.class); addedlegs.setcontent(addedlegsintent); tabhost.addtab(livedata); tabhost.addtab(addedlegs); } }
main.xml
<?xml version="1.0" encoding="utf-8"?> <tabhost xmlns:android="http://schemas.android.com/apk/res/android" android:id="@android:id/tabhost" android:layout_width="fill_parent" android:layout_height="fill_parent"> <linearlayout android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <tabwidget android:id="@android:id/tabs" android:layout_width="fill_parent" android:layout_height="wrap_content" /> <framelayout android:id="@android:id/tabcontent" android:layout_width="fill_parent" android:layout_height="fill_parent"/> </linearlayout> </tabhost>
output image: performing calculations in photosactivity.class(which in first tab(photoes)) activity , pass result string songsactivity.class (which in second tab(songs)) use string further calculations.
can suggest way archieve that? thanx inadvance!!
the idea of communication between parent activity
, child using associated tags
in case "photoes" , "songs".
for example: if need pass string tab
"photoes" parent activity.
1)you need create public method in parent activity
call following child
((androidtablayoutactivity)getparent()).myfunctionname("string value");
2)to pass value specific child,e.g. "songs", have create public method within child activity
, call parent using it's tag
.
public void myfunctionname(string str){ activitytab1 activity = (activitytab1) getlocalactivitymanager().getactivity("tab1"); activity.takethisvalue(str); }
you may need validation make sure activity instances not null
if(activity !=null) //do stuff