c# - 如何从非 Activity 类启动 Activity?
问题描述
如何从 Xamarin.Forms 中的非 Activity 启动 Activity?
在主启动项目 MyApp.Droid 中,我有MyActivity.cs。
在 PCL 项目 MyApp.Plugin.Android 中,我有一个非活动类MyClass.cs。
在 MyClass.cs 中,我需要在 MyActivity.cs 中运行一些代码。
我怎样才能做到这一点?
谢谢。
我的活动.cs:
public void MyMethod()
{
// [Working Code...]
}
MyClass.cs:
public void OnSuccess
{
// What should I put here to call MyMethod?
}
解决方案
像这样的东西应该可以解决问题!(我想,已经有一段时间了……)
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();
}
}
}
推荐阅读
- node.js - 带有 Nodemailer、NGINX 和 Namecheap 的 SMTP 邮件服务器
- python - Flask-sqlalchemy 问题:无法适应类型“LocalProxy”
- amazon-web-services - 在 AWS lambda 中找不到模块“slugid”
- javascript - 有没有办法使用检查元素来选择电子中的元素?
- python - Django:在通过 url 访问媒体之前运行一个函数
- google-cloud-firestore - Cloud Firestore Query 过滤掉包含空白字符串的字段
- laravel - laravel 和配置变量的问题
- html - HTML和CSS多表显示问题
- c# - 我用 C# 做了灯光控制。但它有一个小问题
- node.js - 有没有办法在 discord.js 嵌入消息中创建超过 3 个内联字段?