4

I have two activities in my app. First activity launchmode is singleInstance and second activity launchmode is singleTask. I am using these launchmodes because i don't want to destroy any of the activity while switching between them. App is working correctly in case of mobile. But in case of tablet multiple instances(one of first and other of second activity) are visible in recent app list of tablet. How can i avoid multiple instances in recent app list of tablet?

David Wasser
  • 93,459
  • 16
  • 209
  • 274
Jeet
  • 73
  • 7

1 Answers1

4

Do not use the special launch modes for this purpose. This creates more problems than it solves. Revert to either standard launch mode or singleTop launch mode.

If you just want to switch between the 2 activities without finishing them or creating new ones, simply add Intent.FLAG_ACTIVITY_REORDER_TO_FRONT to the Intent that you use to launch one Activity from the other. This will just rearrange the activities on the stack without creating any new instances.

David Wasser
  • 93,459
  • 16
  • 209
  • 274
  • 1
    Your solution is working correctly for me. However if we use Intent.FLAG_ACTIVITY_REORDER_TO_FRONT to switch between activities. Then It may leads you to find a google bug which is confirmed [here](http://stackoverflow.com/questions/20695522/puzzling-behavior-with-reorder-to-front). But i found a [workaround](https://code.google.com/p/android/issues/detail?id=63570#c15) for this bug For me your solution works correctly. So I am marking it as correct. – Jeet Jan 03 '17 at 13:12
  • Glad to be of help. And thanks for the reference to the platform bug. I have a collection of there X-year-old platform bugs that have never been fixed :-( – David Wasser Jan 03 '17 at 13:29