Your problem can be solved by using the clearHistory()
of service $ionicHistory
method. Both in your student or teacher view controller you can call that method and this will prevent you from being able to navigate backwards since that method deletes the history except the current view (that is why it is necessary that you do it in the view of the student or professor).
...
.controller('EstudianteCtrl', function($ionicHistory) {
...
$ionicHistory.clearHistory();
});
You can also use the nextViewOptions()
method and disable the back button in this way
$ionicHistory.nextViewOptions({
disableBack: true // Esto pone en 'null' la vista anterior
});
But this must be done from the previous view (The view "loading") since that applies to the next view to be displayed before transitioning to it.
Finally to make your application exit by pressing the back button you have to use the service $ionicPlatform
using onHardwareBackButton
but you are entering inadvertently into a problem:
If you leave your application when doing back, you run the risk that your users leave the application unwittingly, especially if you have many in-depth views in your navigation. Back ..., Back ..., Back ..., Exit ... Ups !!!
Most mobile applications implement a way to exit when they reach the home view using the back button, which has become practically a standard.
You want to keep users inside your application and not outside it;)
The solution that I see to that is to use two backs instead of one showing a toast with a message with something like "Press again to exit"
The toast can be installed with a plugin that you can find in link using
cordova plugin add cordova-plugin-x-toast
Then in the event platformReady
you set the event (to make sure that the plugin has loaded)
$ionicPlatform.ready(function () {
var closeApp = false;
$ionicPlatform.onHardwareBackButton(function () {
if ($state.is('mivistaraiz')) {
if (closeApp === true) {
navigator.app.exitApp();
}
else {
closeApp = true;
$timeout(function () {
closeApp = false;
}, 2000);
notifications.notify("Presione nuevamente para salir", "short", "bottom");
}
}
});
});
You can change the timeout to make it bigger but basically what you do is exit if you press the back in a 2-second interval, otherwise it will show the toast again, thus preventing your users from leaving the application by accident.