the imap-/mvbox-/sentbox-/smtp-threads needs to be terminated
before dc_close() can be called successfully.
if this is not done, they are hanging around, and, even worse,
if an account is opened _again_, there are now two threads
working on the database which lead to duplicated messages.
note, that this issue is only related to duplicated messages
if ever an account was selected, which, however, might be the same as the current.
prevent switching accounts if the currently selected account was tapped,
just close the dialog in this case.
(ux wise, it is better to show the current account - to get some overview
and also to easily see what the current account is)
the foreground notification is an important element
that avoids the system from killing the app.
in the past, we added the foreground notification when the screen turns off
and removed it when the screen turns on again -
the reason was that the notification does not annoy users this way.
meanwhile, however, it seems that this approach is no longer as reliable
as in the past. might be that we are killed before the screen turns off -
or that some handlers are not executed by some systems.
also meanwhile, even the "allow to run in background" resp.
"allow battery consumption" seems to be unreliable on various systems,
there are several reports eg. on stackoverflow that apps are killed anyway -
but a foreground notification is not known to be killed yet -
also as the api contract is about to avoid exactly that.
finally, this notification is also a good methor for users
to notice if the app gets killed -
so that they can blame the system then.
therefore, the annoying of the permanent notification
is probably the smaller drawback compared to
received messages delayed.