Beginner
Beginner

Reputation: 1424

how can i make my back button work similar to device back button android

I have implemented presently back button like below

<Button
                android:id="@+id/back"
                style="@style/NavButtons"
                android:layout_width="wrap_content"
                android:layout_height="30dp"
                android:layout_alignParentLeft="true"
                android:layout_centerHorizontal="true"
                android:layout_centerVertical="true"
                android:layout_marginLeft="5dp"
                android:background="@drawable/back"
                android:onClick="finishActivity"
                android:paddingLeft="5dp" />

and in code i am doing

public void finishActivity(View v) {
        finish();
    }

But the back button i have implemented doesnt work similar to device back button. what i should make my back button implementation work similar to device back button?

Thanks:)

Upvotes: 1

Views: 197

Answers (3)

Ahmad
Ahmad

Reputation: 72613

You can use this:

super.onbackpressed();

if you want to do the same as the devices back button, just programmatically.

Upvotes: 4

stinepike
stinepike

Reputation: 54702

public void finishActivity(View v) {
        onBackPressed();
    }

Upvotes: 1

Related Questions