Starting Activity with back button

前端 未结 3 602
南旧
南旧 2021-01-25 04:42

I\'m developing an application in android, where i\'m looking for a solution.

There is an Activity(say A1) from which by clicking a button, user goes to another Activit

相关标签:
3条回答
  • 2021-01-25 05:40

    you can use:

    public void onBackPressed()  
    {  
        //do whatever you want the 'Back' button to do  
        //as an example the 'Back' button is set to start a new Activity named 'NewActivity'  
        this.startActivity(new Intent(YourActivity.this,NewActivity.class));  
    
        return;  
    }  
    

    look at here: http://www.41post.com/1685/programming/android-changing-the-back-button-behaviour

    0 讨论(0)
  • 2021-01-25 05:45

    Try this:

    public void onBackPressed() {  
        finish();
        return;  
    }
    
    0 讨论(0)
  • 2021-01-25 05:48

    You can override the Back Button key press like so:

    @Override
    public boolean onKeyUp(int keyCode, KeyEvent msg) {
    
         switch(keyCode) {
         case(KeyEvent.KEYCODE_BACK):
              Intent a1_intent = new Intent(this, A1Activity.class);
              startActivity(a1_intent);
              finish();
              return true;
    
    
    
         }
         return false;
    }
    

    Take a look at this

    0 讨论(0)
提交回复
热议问题