Get started with other activities on Xamarin Android

I found this java code to create a generic method to run any activity from another activity.

public void gotoActivity(Class activityClassReference)
{
    Intent i = new Intent(this,activityClassReference);
    startActivity(i);
}

How can I convert this code to C # for xamarin-Android?

Thanks in advance.

+4
source share
4 answers

You can write:

public void GoToActivity(Type myActivity)
{
            StartActivity(myActivity);
}

and name it like this:

 GoToActivity(typeof(ActivityType));

or just write:

StartActivity(typeof(ActivityType));
+8
source

This is how I did 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));
    }

Then you can add to where TActivity : YourBaseActivityis the base activity that you created

+2
source
void btnEntrar_Click(object sender,EventArgs e)
    { 
        var NxtAct= new Intent(this, typeof(Perguntas2));
        StartActivity(NxtAct);
    }

+1

I know that the question may be obsolete, but I have a different approach, with an external class for a common call action to 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));
};

This may be useful for some of you.

0
source

All Articles