开发者

Back button edit action

开发者 https://www.devze.com 2023-04-04 03:22 出处:网络
I have a splash screen and if I press the back button while the splash activity is running this activity is closed but the next activity after the splash (after 2 seconds) will be open. I would like t

I have a splash screen and if I press the back button while the splash activity is running this activity is closed but the next activity after the splash (after 2 seconds) will be open. I would like to set the back button to close the splash a开发者_C百科ctivity but to open immediately the next activity or to close the whole application.


You need to override the back-button with this:

    @Override
    public void onBackPressed(){
       Intent i1 = new Intent(getApplicationContext(), NextActivity.class);
       startActivity(i1);
    return; 

This will take you to the next Activity when you pres the button. If you want to close the app try this:

        @Override
        public void onBackPressed(){
            moveTaskToBack(true);
        return;
0

精彩评论

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

关注公众号