1

We are facing a strange issue. Not sure if it is design flaw of the existing application. Your help/suggestion is appreciated.

We have a Xamarin.forms app. Targeted both for iOS and Android.

Problem is coming mainly in Android app.

Application flow:

  • once we logout from the application, app opens an logout activity and delete user info and other data.
  • opens a new activity for login which contains client SSO implementation
  • on successful login, app is setting user info and fetch data from web service.
  • then it calls LoadApplication method so that flow comes back in main application

Now if user perform logout/login several times, its opening a new application instance by calling LoadApplication method and then displaying home screen

So when user is tapping back button in home page, app is not closing and displays previous instance of same application. User need to press back button several times (depending how many time user perform logout-login).

Is there any goodway to stop this? Can we close current instance of the application before LoadApplication being called?

Stuck for a long time.

Abhinav
  • 523
  • 6
  • 17

2 Answers2

2

I'd try to avoid to call LoadApplication more then once. You should control the navigation stack.

Given you are on the LogoutPage

  • remove all views via PopToRootAsync
  • show the LoginPage
await Navigation.PopToRootAsync(false);
await Navigation.PushAsync(new LoginPage(), true);

This blog post may be worth a reading: https://jfarrell.net/2015/01/22/understanding-xamarin-forms-navigation/

Sven-Michael Stübe
  • 14,560
  • 4
  • 52
  • 103
  • Main problem is login/logout functinality is implemented using client SSO. – Abhinav Sep 27 '16 at 08:13
  • And why is it a problem? – Sven-Michael Stübe Sep 27 '16 at 08:17
  • Also, SSO can be implemented from native only. we've a root page of master-detail kind and by default first item (Home page) from hamburger menu is selected. And in the same hamburger menu we have logout page. So, when user taps on logout item from hamburger menu, app loads logout page which in turns call logout page renderer and hence app starts logout activity. After logout completion, app starts login activity which has implementation of SSO with login successful and login failed callbacks. From successful login callback, app calls LoadApplication method. – Abhinav Sep 27 '16 at 08:20
  • Ye after successful login. Don`t call LoadApplication, clear the navigation stack and present your master detail page. – Sven-Michael Stübe Sep 27 '16 at 08:24
0

Kindly try this.

https://stackoverflow.com/a/36885388/1941942

[Activity (NoHistory = true)]
public class LoginActivity : Activity { }

The saving instance error has gone a while after I implement it on MainActivity.

Community
  • 1
  • 1
pampi
  • 517
  • 4
  • 8