UiApplication.getScreenCount()
will always give you the number of screens, so you can just do this (from anywhere, it doesn't even have to be from any particular Screen
class):
public void popToRoot() {
UiApplication app = UiApplication.getUiApplication();
while (app.getScreenCount() > 1) {
app.popScreen(app.getActiveScreen());
}
}