XurajB XurajB - 2 months ago 12
Android Question

Prevent opening Activity for multiple times

I have a common menu on my app with icons. Clicking an icon will start an Activity. Is there a way to know if an activity is already running and prevent it from starting multiple times (or from multiple entries)? Also can I bring an activity that is in onPause state to the front?

Answer

Use this:

intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);

while starting Activity.

from documentation:

If set in an Intent passed to Context.startActivity(), this flag will cause the launched activity to be brought to the front of its task's history stack if it is already running.

Comments