I have follow this guide to setup push notification in my Xamarin Forms app.
I have an app with two activity, one splash activity
Activity(Theme = "@style/SplashTheme",
MainLauncher = true, ScreenOrientation = ScreenOrientation.Portrait, NoHistory = true)]
public class SplashAct: Activity
{
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
StartActivity(typeof(MainActivity));
Finish();
}
}
and the MainActivity
[Activity(
ClearTaskOnLaunch = false,
FinishOnTaskLaunch = false,
Theme = "@style/MainTheme",
LaunchMode = LaunchMode.SingleTask,
ScreenOrientation = ScreenOrientation.Portrait,
ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
public partial class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity, Android.Gms.Tasks.IOnSuccessListener
in the main activity I have override the OnNewIntent method
protected override void OnNewIntent(Intent intent)
{
base.OnNewIntent(intent);
ProcessNotificationActions(intent);
}
and I have tried to send a notification using a web api published on Azure with this body:
{
"text": "Test msg",
"action": "action_a"
}
on device the text is correctly shown, but when the code reach the OnNewIntent method the intent has not extras so I lost the "action" value.
How can I solve this?
NB. I can't use LaunchMode = LaunchMode.SingleTop otherwise the OnNewIntent is not called, the OnCreate is called and the app shows a blank screen.
This happens only if the application is in background or closed. If it is in foreground all works fine.
Attached a sample, a video and info to make the POSTMAN\RESTER request.