首页 > 解决方案 > 如何从非 Activity 类启动 Activity?

问题描述

如何从 Xamarin.Forms 中的非 Activity 启动 Activity?

我怎样才能做到这一点?

谢谢。


我的活动.cs:

public void MyMethod()
{
    // [Working Code...]
}

MyClass.cs:

public void OnSuccess
{
    // What should I put here to call MyMethod?
}

标签: c#androidandroid-intentandroid-activityxamarin.forms

解决方案


像这样的东西应该可以解决问题!(我想,已经有一段时间了……)

MyClass.cs:

using System;

namespace MyClass {

   public static class Program {

     public static void MyMethod()
     {
         // [Working Code...]
     }

   }

}

我的活动.cs:

using System;
using MyClass; //get your other file by the namespace

namespace MyActivity {

   public static class Program {

     public static void OnSuccess()
     {
         Program.MyMethod();  //[class name]..MyMethod();
     }

   }

}

推荐阅读