I need to start activity within my library. For example, I have a button in main activity and I want to attach to this button a method from library. In this method, I want to start new activity. My problem is I can't pass any info about my app to library, so I can't use context in Intent to start activity. Now I'm trying to do this like that:
public void MethodToInvokeWithinApp()
{
//Because this activity is never started, it haven't
//built context so I try to achieve this in that way
OnCreate(new Android.OS.Bundle());//but this throw:
//Java.Lang.NullPointerException: Attempt to read from field
//'java.lang.String
//android.content.pm.ActivityInfo.parentActivityName' on a null
//object reference
var intent = new Intent(this, typeof(ActivityInLibrary));
StartActivity(intent);
Finish();
}
Have you any idea how I can achieve this? Is there any way to get context from process?
More info:
This is my class in library and method I want to invoke
[Activity]
public class DroidAuthenticator : MvxActivity, IAuthenticator
{
private ICallbackManager callbackManager;
public void FacebookLogin()
{
OnCreate(new Android.OS.Bundle());
var intent = new Intent(this, typeof(FacebookLoginActivity));
StartActivity(intent);
Finish();
}
}
Invoke looks like that:
public class MainViewModel : MvxViewModel
{
IAuthenticator authenticator;
private ICommand facebookLoginCommand;
public ICommand FacebookLoginCommand =>
facebookLoginCommand = facebookLoginCommand ?? new MvxCommand(FacebookLogin);
public MainViewModel(IAuthenticator authenticator)
{
this.authenticator = authenticator;
}
private void FacebookLogin()
{
authenticator.FacebookLogin();
}
}
So as you can see I'm using Xamarin with MvvmCross. In ViewModel I inject IAutheticator with is register on platform side.