I have two activity, cartActivity and paymentActivity.When I click back in payment activity it has to go back to the cartActivity but instead the app is closing completely. I don’t get any error also.
override fun onBackPressed() {
this.finish()
}
This is in payment activity.
2
Answers
While switching from CartActivity to PaymentActivity don’t finish the CartActivity. So now when you press back you will switch to previous Activity.
Or simply write finish() instead of this.finish() in onBackPressed() Method like this.
Hope this will solve.
When you navigate from
CartActivity
topaymentActivity
, make sure are not clearing thebackstack
using flags like these:These flags are responsible for clearing
backstack
, so in case you have used them, when you press back onPaymentActivity
you will exit the app. This might be a reason for your problem, please provide complete code for more details.