-1

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?

BenMorel
  • 34,448
  • 50
  • 182
  • 322

4 Answers4

4

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();
            }
        });
ckpatel
  • 1,926
  • 4
  • 18
  • 34
0

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()
{
}
TNR
  • 5,839
  • 3
  • 33
  • 62
  • Hi if i have to click on the customize back button means i should able to go to the previous screen.how can i do – user1780331 Nov 02 '12 at 07:04
  • @user1780331 just call the YourActivity.super.onBackPressed() in the customized back button's onClick(). It worked for and should work for you. I have given you the explaination in my answer itself – TNR Nov 02 '12 at 07:45
-1

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

Thanh Le
  • 1,370
  • 2
  • 19
  • 30
-1

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();
}
});
  • Button back = (Button) findViewById(R.id.back); back.setOnClickListener(new OnClickListener() { public void onClick(View v) { finish(); } }); i have used this code.i have to run the app means and view more pages after click the custom back button means am getting first page only.but i wish to need the previous screen – user1780331 Nov 02 '12 at 07:17
  • now first of all i want to know that where you have putted that code in header or somewhere else if header so it will come in all... – Stanley Fox Nov 02 '12 at 07:30