How to prevent the Gluon App from closing on pressing Back - gluon

I am creating a Gluon Glisten App with functionalities similar to an email client.
There is a login page as soon as the app is launched and on successful login a list of inbox items is displayed. How do I prevent the App from closing when the Back button on Android is pressed in the INBOX_VIEW. Is there a way to push the app to background when back is pressed in the last view on the stack?
Below are my three Views
public static final AppView LOGIN_VIEW = view("Login", LoginPresenter.class, MaterialDesignIcon.HOME, HOME_VIEW,SKIP_VIEW_STACK);
public static final AppView INBOX_VIEW = view("Inbox", InboxMessagesPresenter.class, MaterialDesignIcon.MAIL, SHOW_IN_DRAWER,SKIP_VIEW_STACK);
public static final AppView INBOX_MESSAGE_DETAIL_VIEW = view("InboxDetail", ReceivedMessageDetailPresenter.class, MaterialDesignIcon.DASHBOARD);

Related

How to hide TimePicker and DatePicker on lifecycle events in Xamarin Forms

I'm running into an issue on android where our TimePicker and DatePicker stay visible when we navigate OnPause(). We need to redirect our users back to the login screen when they background the application, but if the TimePicker or DatePicker is active when they do this it stays on the screen. It appears above the login screen and pressing cancel or ok crashes the app.
We are hooking into the native android lifecycle events (not just using Xamarins built in hooks) and we redirect OnResume(). I've tested this in a barebones app though and it still happens OnPause().
Here is our TimePicker causing us the issue:
<TimePicker x:Name="VitalTimePicker" HorizontalOptions="Fill" VerticalOptions="Fill" IsVisible="false" PropertyChanged="OnTimePickerPropertyChanged"/>
And here is an example of changing screens on a lifecycle event:
protected override void OnSleep()
{
App.Current.MainPage = new NavigationPage(new NotesPage());
}
Any ideas? I was thinking of clearing the Pickers but I can't seem to find how to do that
Edit
Just to add a little more context
The Application class (app.xaml.cs) has lifecycle hooks that we use to catch when our users background the app. In here we call MainPage = new NavigationPage(new LoginPage()); which takes the app back to the login page.
I've added
protected override void OnDisappearing()
{
VitalTimePicker.Unfocus();
VitalDatePicker.Unfocus();
}
to the view i'm working from and it seems to be called when we background the application, but for some reason the TimePicker is staying on the screen when our login page pops up again.
You can programmatically close DatePickers and TimePickers using the method Unfocus(). I'd recommend closing them before you call the next page, as I don't know if they will be able to be referenced and closed after the other screen has been initialized.
Create a method that calls VitalTimePicker.Unfocus() and the same for any other picker you have, and call this method before changing to login screen and you should be good to go.

How to Close/Exit current instance of Xamarin.Forms app while loading a new one

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.
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/
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.

Closing Android Activity opened from Forms.Context.StartActivity

I am working on facebook authentication in a Xamarin forms app and want to use "native" login on each device.
The Facebook SDK (by Xamarin) is not designed for forms since it requires passing in an Android activity that implements some specific interfaces.
However; I was able to get the UI to display using a custom page renderer and then in that renderer calling StartActitivty with an activity that uses the exact implementation described in the Facebook SDK getting started. https://components.xamarin.com/view/facebookandroid
So far everything works perfect. The android app starts, xamarin forms kicks in, the custom page renderer is loaded the login android activity starts and the user logs in with facebook and we get to the console.writeline below.
So, how do I dismiss this intent or otherwise get back to xamarin forms?
Do I:
Dismiss this intent? - if so then what?
Inject something to "reset" the main page?
Other?
public void OnCompleted (Xamarin.Facebook.Model.IGraphUser user, Response response)
{
//TODO: show user details with welcome and button that takes them to main app.
//TODO: switch back to xam forms from here on out.
//TODO: figure out how to change the `main` activity to xam forms.
// 'Me' request callback
if (user != null) {
//How do I get back to Xamarin forms from here?
Console.WriteLine ("GOT USER: " + user.Name);
} else {
Console.WriteLine ("Failed to get 'me'!");
}
}
You should call Finish();
Anyway, if you want to see exactly how I did it, you can check it here:
https://github.com/IdoTene/XamarinFormsNativeFacebook

Update UI after download with FileDownloader

I have some code which extends a button to offer a download with FileDownloader:
private final InputStream stream;
private final Label label;
private final Button button;
//…
StreamResource.StreamSource source = new StreamResource.StreamSource() {
#Override
public InputStream getStream() {
label.setValue("downloaded");
return stream;
}
};
FileDownloader downloader = new FileDownloader(new StreamResource(source));
downloader.extend(button);
This code wants to update the UI as well (set the Label to "downloaded").
This works in some browsers (Konqueror and Chromium), but in Firefox (31) it doesn't.
The behaviour in FF is quiet strange: The first click on the button starts the download without any update of the UI. A second click on the button shows the update of the UI only (i.e. no download).
My suspicion is that FF doesn't like FileDownloader's iframe:
Please note that the download will be started in an iframe
Any idea how I can achieve an update of the UI from within StreamSource.getStream()? If not, any better ideas to offer a download which updates the UI as well?
It's vaadin-7.1.15.
maybe it will work when you update the label value in a clicklistener?
button.addClickListener(new ClickListener() {
#Override
public void buttonClick(ClickEvent event) {
label.setValue("downloaded");
}
});
I would also try to set the label to immediate=true:
label.setImmediate(true);
You can either add the ClickListener to the button as suggested, or you need to let your UI poll the server (or even better use push).
That the second click on the button will update the UI is caused by the fact, that this click initiates a client request and the server will answer with the changes in the UI. Before that you have updated the UI correctly - on server side - but the browser does not know about this. Therefore you should use UI listeners like the ButtonClickListener.
By the way I don't think that this is only a firefox issue.

How can i use NavigationServices in Application_Activated windows phone 7?

im developin an app for wp7 that it holds pictures and notes with password login. But when app running if user press windows button app is running at background and if user press back button it resumes without asking password again.
i tried to Navigate when app activated but i couldnt manage it in Application_Activated method. is there a way to do that? Or could you advice me sth else that solve my problem.
ty.
here is my code im using to navigate,
(Application.Current.RootVisual as PhoneApplicationFrame).Navigate(new Uri("/MainPage.xaml", UriKind.Relative));
I got around this issue by using UserControls on the MainPage, showing one if the user had not yet logged in and the other if they had, I set these controls up to show/hide based on certains states in the MainPage and then bind that to the MainViewModel:
private void Application_Activated(object sender, ActivatedEventArgs e)
{
// Ensure that application state is restored appropriately
....your code here to load stuff...
App.ViewModel.MainPageState = "ShowThemTheLogin";
}
}

Resources