Xamarin forms: The equivalent of .Finish() - mobile

I have a Xamarin Forms application which very well on all three platforms. The app has a login screen and other pages that are available one a user has successfully logged in. My question is: In Xamarin Forms; is there a way to have the equivalent of the Finish method that Xamrin for Android provides to remove the login page from the navigation stack? If a user keeps pressing the back button they eventually get back to the login screen which is undesirable. I have tried using Navigation.PopAsync () but seem not to work

Navigation.PopAsync and Navigation.RemovePage should definitely work.
BUT if your page is also a MainPage you can't remove it. You could change it to another page using this code:
App.Current.MainPage = new NavigationPage(new MyContentPage());

Related

Is the any way for Next-Auth with google provider to invoke pop-up window instead of redirect to another page?

I am trying to implement google authentication but the requirements of the projects says Pop-Up window login instead of redirect. Is there any solution like uxMode="popup"?
I think there is not an available option, but I was wondering if there is a work around.

How to stay logged in when you're redirected from other pages?

I am developing an app with ReactJs, the basic is done but now I have a problem. My app consists of 2 screens, one is called Login and the other is called Home. It's sort of a minigame linked to other pages. So if I have logged in on other pages, and then supposedly I click a button to redirect to my app, I want it to check the authentication before rendering, if the user is valid then it goes straight to Home, if not then the Login is required. Due to security reasons, I can't share any code, I just want to know what's the approach to this situation. Many thanks.

How to open application from a webbrowser windows phone

I am developing a windows phone application.
In a page I placed a button and on this button click I open the webbrowser and redirects to our website pages for some processes. There are many webpages. In the last webpage we added a button "Close". In the close button click I want to close the webbrowser and open the application back with the last state before opening the webbrowser. How can I do this ?
Thanks.
I will refer to the button in the app as "app button" and the button in the web page as "close button".
Add a WebBrowser control called webBrowser1 to the Windows Phone app. Make it cover the entire screen, and set it's Visibility property to Collapsed.
On the app button's click event, use
webBrowser1.Visibility = System.Windows.Visibility.Visible;
webBrowser1.Navigate(new Uri("http://yourwebsite.com/page");
to show the web browser and navigate it to the first page on your website.
Make the close button on the last page of your site navigate to a new page on your site, called "close.html" or whatever you want. In javascript, this would look like
<Button onclick="window.location.href='http://yourwebsite.com/close.html';">
Back in the app: On webBrowser1's Navigating event use,
if (e.Uri.ToString().Contains("close.html"))
{
webBrowser1.Visibility = System.Windows.Visibility.Collapsed;
}
When the you click the button on the last page of your site, it navigates to "close.html". When this happens, the Web Browser's Navigating event fires. Since this event fires every time you change pages, you need to check to see if the new url contains "close.html", the page your close button is navigating to. If it does, the Web Browser will be hidden and you will see your app again.
.
(In VB, the code would be )
webBrowser1.Visibility = System.Windows.Visibility.Visible
webBrowser1.Navigate(New Uri("http://yourwebsite.com/page")
And
If e.Uri.ToString.Contains("close.html")
webBrowser1.Visibility = System.Windows.Visibility.Collapsed
End If
Edit: I was thinking in generic terms when i wrote the answer and did not remember that you are asking specifically about the webbrowser (hence, using a webbrowsertask launcher). Thank you #Claus for point out the OAuth situation. So, i am amending my answer to explain that it is possible and also mention an issue with using the launcher as there is no way guarantee to return back to a given point in your launcher app (as it is with choosers due to the availability of callbacks).
It is not possible to achieve this in general terms. That is, there is an application A which opens another application B and from application B you would like to close-it-and-open-A. There are many reasons why i think it is not possible:
- How does one get the address/reference to the application A. No API for that at the moment.
- There is no content-handler/plugin where a 3rd party can register an app with the web-browser.
- Most importantly, security, security, security. This would open doors for attacks from the web.
However, for your requirement of application B being a web-browser, it is possible to use a task launcher WebBrowserTask. As #claus suggests, you could have Window.close() javascript in your last page to close the browser and hence reveal the app underneath it (hopefully, A). The problem here is that if, the user opens an app (let's call it C) after the browser has launched (and before the browser is closed), and the user does not close C, then when the browser gets closed, the user will be returned to C and not to the launcher App! This is not what you want based on your requirement.
So, if you would like to achieve the kind of effect you are describing in your question, it is best that you embed the Web-browser in your application (as a full-screen app) and from that vantage point you can interact between the web-browser (control) and the (host) app via Javascript.
Hopefully, this helps.

Windows Phone show ConnectionSettingsTask and back

I am working on a windows phone app right now.
In the app, I am handling an exception in page 1, that when there is no wifi connection, it will pop a XNA messagebox, user can choose to open the WIFI settings page. I have the following code:
ConnectionSettingsTask connectionSettingsTask = new ConnectionSettingsTask();
connectionSettingsTask.ConnectionSettingsType = ConnectionSettingsType.WiFi;
connectionSettingsTask.Show();
But the problem with this is, when user hit back key in the wifi settings page, they will be navigate back to page 1, which has a loading problem and can not display the proper content. In this case, I would like user to directly go to another page, call it page 2.
Is that possible? Thank you
++++++++++++++Update
Is there are way to customize the back key functionality when showing the XNA messagebox?
I don't know about XNA coding much, but I do know that if you return from wifi connection page to your app, the OnNavigatedTo function is invoked. Try setting out your flow of code according to the application flow. If there is some code you have executed at the constructor, shift it to OnNavigatedTo and vice-verse, which may solve your problem. Also if you want to shift to another page, do it in the same function (OnNavigatedTo) itself. Hope it helps.
Maybe you can change the navigation behavior: http://blogs.msdn.com/b/ptorr/archive/2010/08/28/redirecting-an-initial-navigation.aspx
However it is recommended to merge the two pages together (hide loading bar and show main page) as you will have less problems...
why not handle this code in the IsNetworkAvailable check? that way you'l avoid the exception altogether

Programmatically back out of first page of your application

I have a login page which is shown on first launch. After the user puts in his credentials he is taken to the main page of the application. At this point, if the user presses the back key I want it to skip the login page and exit. I tried what was suggested here: Remove a page from Navigation Stack (in OnNavigatedTo, use NavigationService.GoBack()) but it throws an exception because there is nothing else in the back stack. I read some other places that not handling exceptions is basically the only way to close the app...
The problem with this method of closing the app is, well other than being a hack, it doesn't hit Application_Closing() so my state isn't saved.
Anyone know how I can skip the login page when hitting the back key, save state, and exit the application?
Thanks in advance!
Yeah, this is becoming a huge problem with Navigation in WP7 - many folks are complaining about this same type of issue. The key to remember is that Navigation mimics navigation of a website - it acts a lot less like UserForms and more like web pages and their static history.
The easiest way around this which is both transparent to your users and easy for you is to make that first login page you are reference as User Control that sits on top of your actual main page (i.e. don't use a phone:PhoneApplicationPage for your login page - just a control that is part of your main page phone:PhoneApplicationPage). Use a boolean in your OnNavigatedTo on the main page that says "if user is not logged in, display login control, otherwise, just show main page."
On saving state (i.e. tombstoning), ask another question as that's another topic.
The general best practice is to not use a page for anything you dont want in the navigation stack.
In my case i chose to use a Popup to host my Login Control. I pop it from my mainpage if they are not logged in. If they are i dont show it. This way if they are not logged in and hit back, they exit the app. However if they are logged in and also on teh main page, they see their data, and if they hit back they also exit the app (not see the login page).
For the login / home page scenario one thing you can do is on successful login rather than navigating to the home page you call "GoBack", this will take them back to the home page, but pop the login page off the navigation stack and allow the user to exit the app on the next press of the back button.

Resources