I want to set alarm for Xamarin.Droid project. Use DependencyService for platform-specific functions, define an interface with the signature of these functions
namespace ExampleProgram.Droid
{
public interface IRunAlarm
{
Intent setIntent();
...
}
}
and class with implementation.
[assembly: Dependency(typeof(ExampleProgram.Droid.RunAlarm))]
namespace ExampleProgram.Droid
{
public class RunAlarm: MainActivity, IRunAlarm
{
public Intent setIntent()
{
Intent i = new Intent(this, typeof(AlarmReceiver));
return i;
}
...
}
}
But, when I run the program, an exception occurs:
Attempt to invoke virtual method 'java.lang.String android.content.Context.getPackageName()' on a null object reference
An exception occurred on this line:
Intent i = new Intent(this, typeof(AlarmReceiver));
How to handle this exception and how to get MainActivity correctly in this case?