当前位置: 动力学知识库 > 问答 > 编程问答 >

Android: Press Home Button in Child Activity to kill Parent Activity

问题描述:

I'm having an activity A which starts another activity B, I use the startActivityForResult method.

My plan is:

When I press Home button in activity B, I want Activity A to be killed as well.

In the onStop() of activity B, I tried setResult(1,mIntent) and in activity A, when request code ==1, I finish A.

However, when I press home button in B, the setResult method didn't get called.

I'm just wondering anybody knows why is that or is there another way to kill parent activity in child activity when home button pressed?

网友答案:

Try the onUserLeaveHint method:

http://developer.android.com/reference/android/app/Activity.html#onUserLeaveHint%28%29

It executes when the user forces an activity to stop by, for example, clicking the home button

分享给朋友:
您可能感兴趣的文章:
随机阅读: