My App nothing stopped working. I was writing code for Notifications. I did not put, only comment/uncomment code. Before was working and nothin stpped working. My MainActivity:
using System;
using Android.App;
using Android.Content.PM;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;
using Android.Gms.Common;
using Firebase.Messaging;
using Firebase.Iid;
using Android.Util;
using PushNotification.Plugin;
using Newtonsoft.Json.Linq;
using PushNotification.Plugin.Abstractions;
using Android.Content;
using Java.Lang;
namespace Autorizador.Droid
{
[Activity(Label = "Autorizador", Icon = "@drawable/icon", Theme = "@style/MainTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
public class MainActivity : //global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
global::Xamarin.Forms.Platform.Android.FormsApplicationActivity
{
public static Context AppContext;
protected override void OnCreate(Bundle bundle)
{
//TabLayoutResource = Resource.Layout.Tabbar;
//ToolbarResource = Resource.Layout.Toolbar;
base.OnCreate(bundle);
global::Xamarin.Forms.Forms.Init(this, bundle);
//AppContext = this.ApplicationContext;
//CrossPushNotification.Initialize<CrossPushNotificationListener>("840100012845");
//StartPushService();
LoadApplication(new App());
}
public static void StartPushService()
{
AppContext.StartService(new Intent(AppContext, typeof(PushNotificationService)));
if (Android.OS.Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.Kitkat)
{
PendingIntent pintent = PendingIntent.GetService(AppContext, 0, new Intent(AppContext, typeof(PushNotificationService)), 0);
AlarmManager alarm = (AlarmManager)AppContext.GetSystemService(Context.AlarmService);
alarm.Cancel(pintent);
}
}
public static void StopPushService()
{
AppContext.StopService(new Intent(AppContext, typeof(PushNotificationService)));
if (Android.OS.Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.Kitkat)
{
PendingIntent pintent = PendingIntent.GetService(AppContext, 0, new Intent(AppContext, typeof(PushNotificationService)), 0);
AlarmManager alarm = (AlarmManager)AppContext.GetSystemService(Context.AlarmService);
alarm.Cancel(pintent);
}
}
}
}
My App.xaml.cs
using PushNotification.Plugin;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Xamarin.Forms;
using System.Threading.Tasks;
using System.Threading;
using System.Diagnostics;
namespace Autorizador
{
public partial class App : Application
{
public static CancellationTokenSource CancellationToken { get; set; }
private Label _label = new Label();
public App()
{
InitializeComponent();
//MainPage = new Autorizador.MainPage();
MainPage = new NavigationPage(new Autorizador.MainPage());
}
protected override void OnStart()
{
//CrossPushNotification.Current.Unregister();
//CrossPushNotification.Current.Register();
}
protected override void OnSleep()
{
// Handle when your app sleeps
}
protected override void OnResume()
{
// Handle when your app resumes
}
}
}