-1

I have an activity which has various settings the user can choose. There's a 'Save Settings' button on the activity and when pressed saves the user settings. At the moment, once saved the user then has to press the back button to take them back to the last activity.

How would I get rid of the settings screen when the save button is pressed rather than the user having to click the back button after?

Mint_Sauce
  • 55
  • 1
  • 11

4 Answers4

2

Just call finish() on your activity when you press the button. It will go back to the previous activity in the stack.

RufusInZen
  • 2,119
  • 1
  • 19
  • 26
2

Call finish() to terminate your activity

http://developer.android.com/reference/android/app/Activity.html#finish()

CAS
  • 535
  • 1
  • 8
  • 15
  • Thank you, so simple and worked straight away! Love it when that happens (not often enough in my experience). – Mint_Sauce Mar 05 '15 at 20:04
1

use this code :

 btnsave.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            finish();
        }
    });
Ravi
  • 34,851
  • 21
  • 122
  • 183
0

you can use onBackPress() method and make intent to previous activity like this.

@Override
    public void onBackPressed() {
        Intent intent = new Intent(FirstActivity.this, PrevActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
                | Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(intent);
        finish();
    }
Kristiyan Varbanov
  • 2,439
  • 2
  • 17
  • 37