Question

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?

Was it helpful?

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();
            }
        });

OTHER TIPS

when you want to go back write the following line it will navigates you to back.

super.onBackPressed();

Here if you want to remove the device back button functionality remove the same line in onBackPressed() by overriding like below

@Override
protected void onBackPressed()
{
}

You can create a back button, and in onclick() function, you need only call this : this.finish()

Write this code, few months ago i have used this :-

ImageButton back = (ImageButton) findViewById(R.id.btn_back);
back.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
finish();
}
});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top