[android-developers] finish on child activity is calling onDestroy on parent

2012-01-18 Thread Michael
Hi,

I have a Motorola Xoom and a Sony S exhibiting this behavior. Both
running Android 3.2.

I have Activity A and Activity B. Activity A handles UI, Activity B
handles the Android MediaPlayer. Activity A launches Activity B with a
startActivityForResult.

I have a requirement to assume that the power button press means
close the player and return to the UI so I do a finish() in
Activities B's onPause() since it is handling the MediaPlayer. So
during playback, I press the power button and press it again to wake
up the screen and I notice my whole app restarts. I put some logs in
and I'm seeing this:

ActivityA: onDestroy
ActivityB: onDestroy
ActivityA: onActivityResult

I'm left scratching my head. If I call a finish() on Activity B,
shouldn't it be popping that Activity alone off the application stack?
Even doing a setResult(RESULT_OK) before the finish() doesn't help.
How is Activity A being popped off before Activity B as the parent?

Any suggestions on how to debug this problem would be greatly
appreciated.

-- 
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


Re: [android-developers] finish on child activity is calling onDestroy on parent

2012-01-18 Thread Mark Murphy
Replace startActivityForResult() with startActivity(), and try it again.

On Wed, Jan 18, 2012 at 6:54 PM, Michael michaeldh...@gmail.com wrote:
 Hi,

 I have a Motorola Xoom and a Sony S exhibiting this behavior. Both
 running Android 3.2.

 I have Activity A and Activity B. Activity A handles UI, Activity B
 handles the Android MediaPlayer. Activity A launches Activity B with a
 startActivityForResult.

 I have a requirement to assume that the power button press means
 close the player and return to the UI so I do a finish() in
 Activities B's onPause() since it is handling the MediaPlayer. So
 during playback, I press the power button and press it again to wake
 up the screen and I notice my whole app restarts. I put some logs in
 and I'm seeing this:

 ActivityA: onDestroy
 ActivityB: onDestroy
 ActivityA: onActivityResult

 I'm left scratching my head. If I call a finish() on Activity B,
 shouldn't it be popping that Activity alone off the application stack?
 Even doing a setResult(RESULT_OK) before the finish() doesn't help.
 How is Activity A being popped off before Activity B as the parent?

 Any suggestions on how to debug this problem would be greatly
 appreciated.

 --
 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



-- 
Mark Murphy (a Commons Guy)
http://commonsware.com | http://github.com/commonsguy
http://commonsware.com/blog | http://twitter.com/commonsguy

_The Busy Coder's Guide to Android Development_ Version 3.7 Available!

-- 
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