0

Lets assume a scenario such below and in this scenario every letter points an activity, every number within parenthesis points opening time and every arrow points a transition from one to another

A(1) -> B(1) -> A(2) (meaning A is opened then B is opened and A is opened again)

if I press back button A tries to open itself again

A(1) -> B(1) -> A(2) -> B(2) -> A(3) -> C(1) -> A(4)

at this point if I press back button I tries to open itself 4 times again. What I expect is at least it should open C(1) then A(3) then B(2) then A(2) ...

the problem goes by changing the launchmode to singleInstance but I don't understand why this is happening? This is the first time that I'm facing an issue like this.

<activity
    android:name="ProfileActivity"
    android:theme="@style/NoActionBarTheme">
</activity>

and I'm calling it like below

fun launchProfileActivity(context: Activity) {
context.startActivity(
    Intent(context, ProfileActivity::class.java))
}
Mustafa Güven
  • 15,526
  • 11
  • 63
  • 83

1 Answers1

0

You can use finish() with activities like A and B which are repeatedly called many times. This will destroy activity A as soon as you switch to another activity. So only single Instance of A will be there next time you switch to it. Write finish() after startActivity method.

  • I know but the real question im asking is why after A4 gets closed it does not show C1? normally It should show C1 then show A3. – Mustafa Güven Feb 19 '18 at 18:35