开发者

Display a Message on Closing an Activity

开发者 https://www.devze.com 2023-02-16 03:55 出处:网络
So, when the user force closes an activity, I want to display a custom message (Toast) to the user. Any suggestions? I tried putting the Toast in my onPause() / onStop() 开发者_如何学编程methods, but

So, when the user force closes an activity, I want to display a custom message (Toast) to the user. Any suggestions? I tried putting the Toast in my onPause() / onStop() 开发者_如何学编程methods, but they cause the program to crash.

And no, I'm not trying to spam the user with messages everytime he/she force closes an activity. I just want to display the Toast when a particular activity is closed.


 public boolean onKeyDown(int keyCode, KeyEvent event) {
            if (keyCode == KeyEvent.KEYCODE_BACK) {

                toast(getString(R.string.exit_msg), Toast.LENGTH_SHORT);
             }
            return super.onKeyDown(keyCode, event);
        }       
0

精彩评论

暂无评论...
验证码 换一张
取 消