The problem is that if we used Android's default "choose what to do" dialog, then
- the list you're given will include the Stack Exchange app itself, which would be highly surprising, and
- even worse, if that Stack Exchange app is set as your default handler for Stack Exchange URLs, then Android would just open it with the app again without asking, which is exactly what you do not want to do.
There is no way to tell Android "use the system's default handling, but exclude this very app". In my experience, many app developers don't care because they don't want you to leave their app anyway. Unfortunately that means we have to work around it.
To answer your precise question, we first create an ACTION_VIEW
intent with the question's URL, and query the system what possible activities are available on the system to handle this intent (this will usually be the Stack Exchange app and all browsers you have installed). We remove the Stack Exchange app from that list. If that only leaves a single activity (i.e. you have only one browser installed), then we launch the intent with that activity. If there is more than one left, then we launch an ACTION_CHOOSER
intent that lets you choose from them.
From the docs:
The user does not have the option to make one of the matching activities a preferred activity, and all possible activities will always be shown even if one of them is currently marked as the preferred activity.