xamarin.forms - 依赖服务和在机器人和标准项目之间传递值
问题描述
我有一个需要使用本机 droid 函数的方法。我正在使用依赖服务来实现这很好,但是我还需要发送一个填充到我的标准项目中的值。调试时我看到标准中的值但是一旦我进入 droid 值是 null 我也尝试过使列表静态但无济于事
我的服务
public interface INavigationService
{
void PushDictionary(List<Word> allWordsOfUserForAutomat);
}
我的实现
public class NavigationImplementation : Activities.INavigationService
{
public void PushDictionary(List<Word> allWordsOfUserForAutomat) //HERE I SEE THE VALUE
{
Intent intent = new Intent(MainActivity.Instance,typeof(LockScreenDictionary));
MainActivity.Instance.StartActivity(intent);
}
}
我的标准
protected void LockScreen()
{
if (!viewDisabled)
{
DependencyService.Get<INavigationService>().PushDictionary(_allWordsOfUserForAutomat); //HERE I SEE THE VALUE
}
else
{
NotificationService.ShowToast("Nothing to play");
}
}
我的机器人项目
[Activity(Label = "LockScreenDictionary", Theme = "@style/Theme.Splash")]
public class LockScreenDictionary : FormsAppCompatActivity
{
private List<Word> _allWordsOfUserForAutomat; //HERE ITS NULL
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
LangUpDictionaryPlayer.PlayAutomat(_allWordsOfUserForAutomat); //HERE ITS NULL
}
}
解决方案
您应该将allWordsOfUserForAutomat
to Intent 传递给:
在您的实施中:
public class NavigationImplementation : INavigationService
{
public void PushDictionary(List<Word> allWordsOfUserForAutomat) //HERE I SEE THE VALUE
{
Intent intent = new Intent(MainActivity.Instance, typeof(LockScreenDictionary));
//pass data
intent.PutExtra("myData", allWordsOfUserForAutomat);
MainActivity.Instance.StartActivity(intent);
}
}
在您的机器人项目中:
public class LockScreenDictionary : FormsAppCompatActivity
{
private List<Word> _allWordsOfUserForAutomat; //HERE ITS NULL
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
_allWordsOfUserForAutomat = Intent.Extras.GetInt("myData");
LangUpDictionaryPlayer.PlayAutomat(_allWordsOfUserForAutomat); //HERE ITS NULL
}
}
推荐阅读
- laravel - 如何避免 laravel 验证中的重复值?
- java - Mirth Connect 使用 mdth 库获取遭遇详情
- docker - 如何通过谷歌函数在谷歌容器注册表中运行 docker 容器?
- javascript - Web 应用程序输入类型文件在 WebView 中不起作用
- python-3.x - 使用 pandas 和 matplotlib 绘制带有条形图的子组标签
- javascript - JQGrid - 在没有本地数据的情况下管理分页和列过滤(loadonce = false)
- javascript - 在 Laravel 中实现可嵌入的自定义徽章
- javascript - 如何在本机反应中记录每次更新的动画值?
- django - 如何在 django 布尔字段上应用条件?
- redirect - 将子域页面重定向到主域页面