I found this java code to create a generic method to start any activity from other activity.
public void gotoActivity(Class activityClassReference)
{
Intent i = new Intent(this,activityClassReference);
startActivity(i);
}
How can I convert that code to c# for xamarin-Android?
Thanks in advance.
You can write:
public void GoToActivity(Type myActivity)
{
StartActivity(myActivity);
}
and call it like:
GoToActivity(typeof(ActivityType));
or just write:
StartActivity(typeof(ActivityType));
void btnEntrar_Click(object sender,EventArgs e)
{
var NxtAct= new Intent(this, typeof(Perguntas2));
StartActivity(NxtAct);
}
in my code i did this
This is how i've done it in my Applicaiton
public void StartAuthenticatedActivity(System.Type activityType)
{
var intent = new Intent(this, activityType);
StartActivity(intent);
}
public void StartAuthenticatedActivity<TActivity>() where TActivity: Activity
{
StartAuthenticatedActivity(typeof(TActivity));
}
You can then add in the where TActivity : YourBaseActivity
is a base activity that you have created
I know the question may be outdated but I have a different approach, with an external class for a general call action towards any existing activity:
public static class GeneralFunctions
{
public static void changeView(Activity _callerActivity, Type activityType)
{
ContextWrapper cW = new ContextWrapper(_callerActivity);
cW.StartActivity(intent);
}
}
Button redirectButton = FindViewById<Button>(Resource.Id.RedirectButton);
redirectButton.Click += delegate
{
GeneralFunctions.changeView(this, typeof(LoginView));
};
Maybe that helpful for some of you