The android project's return key is sometimes difficult to handle.
When listening for the physical key, you can use the onkeydown method. The activity already has the keyevent. Callback interface, because the project uses fragment and fragment does not have this interface. In fact, even if you are yourselfImplements has keyevent. Callback, and it won't call it by itself (I don't know why). However, fragmentactivity has this interface, so we only need to implement the relevant logic in the activity. If you need to listen on a specific fragment, you can use it in combination.Fragmentmanager. getbackstackentrycount ().
@ override Public Boolean onkeydown ( int keycode, keyevent event) { If (keycode = keyevent. keycode_back & event. getrepeatcount () = 0) {/// If you press back, there are no duplicates /// do something here return true ;} return super . onkeydown (keycode, event) ;}