Detect home button press in android

后端 未结 17 2444
抹茶落季
抹茶落季 2020-11-22 08:22

This has been driving me nuts for a while now.

Is there any way of reliably detecting if the home button has been pressed in an android application?

Failing

17条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-22 09:14

    Since you only wish for the root activity to be reshown when the app is launched, maybe you can get this behavior by changing launch modes, etc. in the manifest?

    For instance, have you tried applying the android:clearTaskOnLaunch="true" attribute to your launch activity, perhaps in tandem with android:launchMode="singleInstance"?

    Tasks and Back Stack is a great resource for fine-tuning this sort of behavior.

提交回复
热议问题