Search code examples
androidandroid-activitykotlin

Back button query, want it to return to a specific page on the stack


I have three activities A, B and C.

A --> B --> C. activity B isn't shown to the user, its calling an api and gathering some information. Should the user hit back I'm hoping for it to go back to A, but not sure how this can be done?

I've already tried coroutines to get around this issue and I've not had much look.

Result is that the back button when pressed continues back to activity C and never gets back to activity A.

Any advice would be great.

Thanks


Solution

  • You can call finish() on B Activity after startActivity(...) call

        startActivity(Intent(this, C::class.java))
        this.finish()