Set Action for home button in android

后端 未结 3 1986
余生分开走
余生分开走 2021-01-23 11:39

How I can change working of home button in android? I want to when I click on home button I do some actions and after that application should go to background. How I can do that

3条回答
  •  有刺的猬
    2021-01-23 12:31

    I do it this way:

    /* Handles item selections */
        @Override
        public boolean onOptionsItemSelected(MenuItem item) {
            switch (item.getItemId()) {
                case android.R.id.home:    
                        //You can do whatever you want here       
                Intent homeInt = new Intent(this, SomeActivity.class);
                startActivity(homeInt);
                return true;
            }
            return false;
        }
    

提交回复
热议问题