That's the basic idea to get on the UI thread. See https://github.com/Raizlabs/RZAndroidBaseUtils/blob/master/BaseUtils/src/com/raizlabs/baseutils/ThreadingUtils.java
for how we do it in the BaseUtils (see runOnUIThread(Runnable)).

If you need Dialogs though, you definitely need the window/Activity, but the potential switching Activities becomes an issue for both leaks and crashes. The standard approach is to bind new Activities to the AsyncTask, but you can't really enforce this as a library so you get into issues. Not sure what the best approach would be there... Maybe keep a WeakReference to the Activity, see if it still exists, see if you can check whether it's still attached, and if not maybe throw a notification instead? I don't really have a good answer unless you force them to always pass their new Activities which is far from ideal.