onKeyDown() or onBackPressed()

前端 未结 4 1965
栀梦
栀梦 2020-12-06 05:10

I want to implement the back button functionality in my application. In application whenever I\'m clicking on back button in middle my control is going to login page direct

4条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-06 05:40

    see below code. write outside the onCreate

      @Override  
        public boolean onKeyDown(int keyCode, KeyEvent event)  
      {  
             //replaces the default 'Back' button action  
             if(keyCode==KeyEvent.KEYCODE_BACK)  
             {  
    
                    Intent intent = new Intent(currentActivity.this, RequiredActivity.class);
                    finish();
                    startActivity(intent); 
    
             }  
             return true;  
       }  
    

提交回复
热议问题