androidback-buttonback-button-control

back button functionality in android app


I have to develop one android app. Here I wish to go back means I have used keyboard button only.but am shouldn't use keyboard back button. I wish to use the back button function for all activities.

For example:

If I have to click on the customize back button means I should able to go to the previous screen. How can I do?


Solution

  • MainActivity :

    next.setOnClickListener(new OnClickListener() {
    
                @Override
                public void onClick(View v) {
                    // TODO Auto-generated method stub
                    Intent intent=new Intent(MainActivity.this,Second.class);
                    startActivity(intent);
                }
            });
    

    SecondActivity :

    pre.setOnClickListener(new OnClickListener() {
    
                @Override
                public void onClick(View v) {
                    // TODO Auto-generated method stub
                    Intent intent = new Intent();
                    finish();
                }
            });