Forum Xamarin.Android

Resume app after notification click

JonAlzaJonAlza ESMember ✭✭✭

I'm developing cross platform app with Xamarin.Forms that show a notification when a timer finishes and the app is not active. I tried using Local Notifications Plugin, but I had problems with shared library reference. So I took the code from github and I use more or less the same code in my app. Now I had another problem: when notification is clicked the launcher activity is launched instead of resume the current activity.

I think that the problem is in LocalNotificationsImplementation class. In Show() method there is this code:

var resultIntent = GetLauncherActivity();
resultIntent.SetFlags(ActivityFlags.NewTask | ActivityFlags.ClearTask);
var stackBuilder = Android.Support.V4.App.TaskStackBuilder.Create(Application.Context);
stackBuilder.AddNextIntent(resultIntent);
var resultPendingIntent =
    stackBuilder.GetPendingIntent(0, (int)PendingIntentFlags.UpdateCurrent);
builder.SetContentIntent(resultPendingIntent);
 _manager.Notify(id, builder.Build());

And this is GetLauncherActivity()

public static Intent GetLauncherActivity()
{
    var packageName = Application.Context.PackageName;
    return Application.Context.PackageManager.GetLaunchIntentForPackage(packageName);
}

I can see that this method gets the launcher.

Is it possible to get an Intent to only resume the app to show the current screen?

Best Answer

Answers

Sign In or Register to comment.