I have a Gluon Mobile (Glisten Afterburner) App and would like to prevent the user from going to the Login Screen of the App on pressing the back button in Android.
There are ways to do this for a particular activity in Android native code. How do I implement it in Gluon.
While @Bek's answer will work on a pure Android approach, using Gluon Views and the Glisten-Afterburner framework, there is an equivalent way:
When you create your project with that template, there are two views, defined with some flags, as you can see in AppViewManager
:
public static final AppView PRIMARY_VIEW = view("Primary", PrimaryPresenter.class, MaterialDesignIcon.HOME,
SHOW_IN_DRAWER, HOME_VIEW, SKIP_VIEW_STACK);
public static final AppView SECONDARY_VIEW = view("Secondary", SecondaryPresenter.class, MaterialDesignIcon.DASHBOARD,
SHOW_IN_DRAWER);
The flags applied to each view are self explanatory, but if you recall, there is a SKIP_VIEW_STACK
flag, applied to the Primary view (which is the Home View): this means the Primary view is not added to the stack, and when you hit back on it, you won't go to other previous view you were before, you will just finish the application.
You can apply this flag to the secondary view as well, and this will mean that once you move from the Primary View to the Secondary View, you won't be able to go back to the primary view again.
So I've renamed the views, the first one will be the Login View, and when you move to the Primary View you won't be able to go back to it via back button:
public static final AppView LOGIN_VIEW = view("Login", LoginPresenter.class, MaterialDesignIcon.HOME,
SHOW_IN_DRAWER, HOME_VIEW, SKIP_VIEW_STACK);
public static final AppView PRIMARY_VIEW = view("Primary", PrimaryPresenter.class, MaterialDesignIcon.DASHBOARD,
SHOW_IN_DRAWER, SKIP_VIEW_STACK);
At a later state, you can always go to the login view programmatically, if you need to.