Monday, July 25, 2011

[android-developers] Activities in Tabs

I am creating an app which has 4 tabs. I have been following tutorials
like this one http://androidgenuine.com/?feed=rss2&tag=tabhost-nested-activity-android
. That is how i set up my app, one main class that extends TabActivity
and 4 different tabs that extend ActivityGroup. so everytime i want to
add an activity to the tab i do something like this. This is not my
code its from the example.

Intent i = new Intent(this, ShowCity.class);
String city_name = (String)
getListAdapter().getItem(position);
i.putExtra("city_name", city_name);

// Create the view using FirstGroup's LocalActivityManager
View view = FirstGroup.group.getLocalActivityManager()
.startActivity("show_city", i
.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP))
.getDecorView();

// Again, replace the view
FirstGroup.group.replaceView(view);

So by the looks of it, it creates a new Intent and makes it into a
View then replaces the tab view with this one. The problem is that
methods in the new Activity like Onback, onResume, and all the other
ones are not being called by the current activity in the tab. Those
methods get called by the tab itself. So the tab Onback, onResume ect.
will always be the same for each activity being shown on the tab. Is
there a way so those methods get called by the current activity being
shown, not the tab itself? Also on the back method there is a
problem.

// back
public void back() {
if(history.size() > 0) {
history.remove(history.size()-1);
setContentView(history.get(history.size()-1));
}else {
finish();
}
}

it works but none of the activity get finish() or destroyed. So the
heap keeps on getting bigger as more activity are being called.


--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

No comments:

Post a Comment