Start an Activity from another Activity on Xamarin Android

匆匆过客 提交于 2019-12-05 05:56:50

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!