StartService throws a Java.Lang.NullPointerException

Hello.
I need to use the GCM notifications in my app.
In my PCL Xamarin Forms i'm using Dependency Injection, because i need to subscribe on custom gcm topics dinamically, after a login procedure.

That's my scenario:

PCL Interface:

        public interface INotificationService
        {
            void Start();
        }

...

INotificationService ns = DependencyService.Get<INotificationService>();
ns.Start();

Android MainActivity:

[assembly: Dependency(typeof(MainActivity))]
namespace MyApp.Droid

...
public class MainActivity : XFormsApplicationDroid, INotificationService
...

public new void Start()
    {
        var intent = new Intent(this, typeof(RegistrationIntentService));
        ApplicationContext.StartService(intent); // -> Java.Lang.NullPointerException
    }

at ApplicationContext.StartService(intent); i get this exception:
Java.Lang.NullPointerException: Attempt to invoke virtual method 'android.content.Context android.content.Context.getApplicationContext()' on a null object reference

I also get the same exception if i run this:

public new void Start()
{
var resultCode = GoogleApiAvailability.Instance.IsGooglePlayServicesAvailable(this); //-> Java.Lang.NullPointerException
...
}

Can you help me?
Thanks.

Posts

Sign In or Register to comment.