Hello all:

I have a question about ActivityGroup and lifecycles. In my app, I
have a tabbed interface where each tab starts a new activity. The
first tab acts as a Media Player with two buttons for playing one of
two different music streams. This activity extends the ActivityGroup
because there is a third button on the page that launches an activity
that acts as an information page. I'm using an Activity Group because
I wanted the tab navigation to stay on top when I switch to the
information activity.

The information activity has several buttons on it, one of which looks
like an X which will switch back to the first activity with the Media
Player buttons. I found examples online using the following code to
switch between the two using Activity Group:

Code that's in the MediaPlayer Activity, this function is used in the
info button onClick listener:

public void replaceContentView(String id, Intent newIntent) {
     View view = getLocalActivityManager().startActivity(id,
newIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP))
                                   .getDecorView();
     this.setContentView(view);

Code that's in the Information Activity in the closeButton's onClick
Listener:
Intent parent = new Intent(v.getContext(), Home.class);     NOTE:
Home.class is the MediaPlayer Activity
Home parentActivity = (Home)getParent();
parentActivity.replaceContentView("info", parent);


This code works properly in the sense that my tab navigation stays on
top and it gives the impression that the Information is "sliding" on
top of the Media Player stuff and then "sliding" off screen again when
the X button is pressed. However, I've noticed some weird behavior.

If one of the streams is playing, and then the information button is
pressed, the stream continues to play, but when you click the close
button on the information page to go back to the media, the Media
Player gets re-initialized so that if I try to click the button to
stop the currently playing stream, another instance of the stream
starts playing on top of the one that's already playing. There's no
way to stop the original one.

I've been putting Log statements in each of the lifecycle methods
(onPause, onStop, onDestroy) and yet it seems that none of these
methods are being called when I switch to the Information Activity as
none of my log messages are appearing in the debugger.

I originally thought that by saving the state using something like
onSaveInstanceState would fix it, but it doesn't seem to be calling
this method either.

Upon reading on the Android Developer site about LocalActivityManager
and the startActivity method it states: "...If the new intent is the
same as the previous one and the new intent does not have the
FLAG_ACTIVITY_CLEAR_TOP set then the current activity will remain
running as is.....Otherwise, the current activity will be finished and
a new one started".

Basically it's my understanding that according to the rules defined
here and the way in which I'm using this, my first activity should be
finished which I assume means it's killed, but could be wrong, and
then the second activity starts. But as I stated earlier it seems this
is not the case. If I call finish() in the Information activity for
the close button it kills the entire app and takes me back to the Home
screen of the device.

Is there a better way to do this or how can I save the state of my
MediaPlayer objects and buttons so that they're not re-created every
time you return from the Information page?

Hope this all makes sense and thanks for the help,
DanielleM

-- 
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+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to