I have activities that are create and launched from menu options. However Ive noticed that this may mean that sometimes there are two or more copies of the same activity. So Im wondering if there's a way to see if another activity is already instantiated and then have the application switch to it or create a new one if its not instantiated.
Re-use previous activities?
Asked Answered
You can control some aspects of this with android:launchMode
on the activity.
Programmatically try following:
Intent intent = new Intent(contextActivity, NextActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
contextActivity.startActivity(intent);
When providing code that solves the problem, it is best to also give at least a short explanation of how it works so that folks reading won't have to mentally parse it line by line to understand the differences. –
Amendatory
You can specify information regarding that in the android manifest. See activity element documentation. I believe that launchmode might control what you are after.
© 2022 - 2024 — McMap. All rights reserved.