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

Opening a Page from background

$
0
0

I managed to open a new Form from a Push Notification and it opens perfectly when the app is visible, it even opens when the app is not visible (minimized or running in background) and when I then open the app the Form is visible (which was opened from the PushNotification).in just Xamarin.Android I usually just started a new Activity and it would popup wether the app was visible or not (for example the app is running but the user is viewing photos) I would like to achieve the same in Xamarin.Forms My current approach is

This is my Service that handle the PushNotification Clicks

[Service]
[IntentFilter(new[] { ActionNotification })]
public class NotificationIntentService : IntentService
{
    public const string ActionNotification = "NotificationIntentServiceAction.ViewNote";
    protected override void OnHandleIntent(Intent intent)
    {
        var current = (App)Xamarin.Forms.Application.Current;
        if (intent.Action == ActionNotification)
        {
            current.DisplayNote(intent.GetStringExtra("Data"));
        }
    }
}

This is my base App Class in the Xamarin.Forms PCL Library

public class App : Application
{
    public App()
    {
        // The root page of your application
        if (Device.OS == TargetPlatform.Android)
        {
            MainPage = new NavigationPage(new Login());
        }
        else
        {
            MainPage = new Login();
        }
    }

    public void DisplayNote(string getStringExtra)
    {
        Device.BeginInvokeOnMainThread(async () =>
        {
            var note = new ViewNote(getStringExtra);
            await MainPage.Navigation.PushModalAsync(note);
        });
    }
}

Viewing all articles
Browse latest Browse all 89864

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>