Vra

First of all, I'm not sure if I am even going about this the best way in terms of design, but I'm a little new to Android and very new to Xamarin.Forms. My setup is a series of ContentPages in a Xamarin.Forms PCL that all deal with information from a REST service. This service, upon logging in, grants a WorkToken that the application then holds onto in order to perform further operations. I'm storing this in an ISessionManager.

My problem is a workflow issue. I have a LoginPage that I want to present to the user if their session has ended/faulted/whatever; basically if they aren't logged in and try to do anything, I want to push this page on the stack and force them to attempt to log in and if they provide valid credentials let them continue where they left off. All this is taking place, for the most part, in the PCL, but I've created an Android implementation of the ISessionManager that is queried on each ContentPage's overridden OnAppearing method. Each page calls ISessionManager's CheckLogin which will do just that, and if they aren't logged in, it will create an Intent and start the LoginActivity through that. LoginActivity essentially just wraps around the PCL's LoginPage.

The problem I am running into is that, doing it this way, the LoginActivity is run asynchronously on top of whatever page called it. This calling page is in a broken state, however, because it has not initialized properly through the REST service yet. I imagine there are two possible solutions. Either run the Intent synchronously (which I don't think is possible) or rethink my design. Here's the Intent setup:

var intent = new Intent(_context, typeof(LoginActivity));
intent.AddFlags(ActivityFlags.NewTask);
_context.StartActivity(intent);

I've checked several Xamarin forums for related posts on this, but have not found much beyond basic navigation workflows in Xamarin.Forms.

Edit: I've found something analogous to what I'm trying to do here: How to pass variables from a new intent back to the class that created it in android, but within the context of Xamarin.Forms. The startActivityForResult would solve my problem if it existed in Forms.Context, but there doesn't appear to be an equivalent.

Was dit nuttig?

Oplossing

Why are you creating a LoginActivity? is it because you need to use something native from android?

My first thought it's that after you check for the token status on the OnAppearing, you that can decide to push or not the modal for the login page, after the user login is done and the token is save, you can pop the modal and it will show the previous page the user was.

Gelisensieer onder: CC-BY-SA met toeskrywing
Nie verbonde aan StackOverflow
scroll top