Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 58056

Best way of navigating between a log in/activation process and the main app

$
0
0

This is not something new but I'm trying to find a good/better solution/design when using Forms for all three platforms (iOS, Android and WinPhone) than what I've got. Plus I'd like to know how everyone else has solved it.

The whole scenario is this: You have an app that requires a user to log in or go through a certain activation process, maybe even two. The process is mostly a one-time thing, unless the user actively tells the app to clear their credentials (how should one best navigate then?).

When I had a pure iOS app I needed a login screen. The solution was simple, the login screen would check if it had credentials and sign you in automatically and navigate to the next view, if not you needed to enter your credentials. If the user logged out I would just navigate back until I hit the first view. It was simple but not optimal since the first view the user saw was the login flash by.

The criteria I have now is a bit more complex. I'm using Forms in order to get an app out on all three platforms, focusing on iOS and Android (WinPhone has sadly been pushed to the back seat when it comes to priorities). The app is going to need a multiple page activation process with multiple steps. Upon success it will navigate to the first page of the main app. This was solved with a splash page that checked for your credentials and depending on what it found it would change the root page to the main page or the first page of the activation process. Now, to do this on all three platforms (now two) and handling the back button on android, was and is tricky.

I saw an example of defining an interface that each platform implemented, the interface exposed a method that took a Xamarin Forms page and each platform implemented the method natively to swap out the the entire navigation stack for this page. On iOS this was easily done by setting the rootViewController and then invoking setkeyandmakevisible (or whatever the method was called, I don't have the code in front of me at the moment).

On Android, this became a complete nightmare and I couldn't just send the page... An activity has a method called SetPage which I tried using, however, using it a second, third or fourth time yielded very strange results. In some cases the app crashed due to outofmemoryexceptions (because the Image object leaks memory like a !"#¤!), in other cases I would get a blank screen until I rotated the phone so the view would redraw itself.

My solution for android as it is now consists of three activities which I start with specific intents (these intents only get metadata on which page to retrieve, since I can't pass an already instantiated xamarin forms page to another activity, I at least don't know how). Two out of three of these Activies have NoHistory = true, the main app has it set to false because otherwise the user would never get back to where he/she was after navigating from and back to the app (second page with the third tab selected). Two of these intents needed two flags set as well, New and Create. These flags were needed for when the main app (with NoHistory = false) wanted to start the activation process again. If the flags were not set the user could press the back key and get back to the main app, which is not something we want (invoking Finish() did not remove the activity from the navigation stack).

This whole solution, along with Image and ImageSource leaking memory insanely on Android, has left me with an app that flashes a bit at the start when toggling pages/activites. It works "ok" except for the Image memory problems on Android (which apparently have been confirmed on bugzilla.xamarin.com but with no information on "when" they'll release the fix).

Is there a better way/design, how have you solved this complex navigation problem (only troublesome when you have a hardware back button...)?

Should activation processes/sub navigation routes/tutorials be spawned as modal popups and when the main app starts we should always check "is the user logged in? handle result", "was the login window just visible and now I as the main window visible again, I'm missing credentials.. that means I need to pop myself off of the navigation stack to close the app..."?


Viewing all articles
Browse latest Browse all 58056

Trending Articles