gpt4 book ai didi

c# - 使用 mvvmcross 显示 View 模型时无法解析当前的顶级 Activity

转载 作者:行者123 更新时间:2023-11-29 21:31:21 24 4
gpt4 key购买 nike

我正在我的 Mvvmcross 应用程序中实现自定义演示器。我想完成的是:常规导航和 fragment 导航。

在我的主要 Activity 中,我设法根据以下示例嵌入了几个 fragment View :https://github.com/i486dx400/MultiRegionPresenter

在 fragment 运行的同时,我还想展示不作为 fragment 托管的常规 Activity 。因此,我扩展了这个演示者,如下 fragment 所示:https://gist.github.com/JelleDamen/7003702

问题/错误:当我展示第二个 Activity 时,它就会显示出来。但是当我返回到之前的 View (即主机)并再次重新打开相同的 Activity 时,它不会显示。输出日志显示:“mvx:Warning: Cannot Resolve current top activity”

我做错了什么,或者我应该做什么来通知框架什么 Activity 是当前最重要的 Activity ?

提前致谢!

最佳答案

What is going wrong?

您提供的跟踪线显示自:

    protected virtual void Show(Intent intent)
{
var activity = Activity;
if (activity == null)
{
MvxTrace.Warning("Cannot Resolve current top activity");
return;
}
activity.StartActivity(intent);
}

https://github.com/MvvmCross/MvvmCross/blob/v3/Cirrious/Cirrious.MvvmCross.Droid/Views/MvxAndroidViewPresenter.cs

所以看起来当调用 Show 时,没有显示当前的 MvvmCross Activity。

... 并查看 https://github.com/i486dx400/MultiRegionPresenter/blob/master/RegionEx.Droid/MainActivity.cs看起来确实如此——应用程序中的主要 Activity 适用于 MvvmCross,而只是一个普通的 FragmentActivity。

what should an app do to inform the framework what activity is the current top activity?

MvvmCross 通常通过拦截 Activity 生命周期事件来跟踪“顶级 Activity”——特别是 Activity 创建、启动、重新启动、恢复和销毁事件。这些显示在 http://developer.android.com/reference/android/app/Activity.html 中的生命周期图中

Mvvm 交叉:

所有内置的 MvvmCross Activity 类型——MvxActivity、MvxFragmentActivity 等——都称它们为“自动”。这些适应可以使用类似 ActionBarSherlock with latest MVVMCross 中描述的步骤扩展到其他 Activity 类型。 ,或者您的应用可以根据需要手动调用其中一些 Hook 。


个人意见:我觉得你最好不要关注https://github.com/i486dx400/MultiRegionPresenter太近了。 https://github.com/i486dx400/MultiRegionPresenter/blob/master/RegionEx.Droid/MainActivity.csOnCreate中的代码似乎每次创建 MainActivity 时都尝试启动应用程序——当然,在每个应用程序的生命周期中可能会发生多次。

相反,请阅读该样本和其他类似 http://motzcod.es/post/60427389481/effective-navigation-in-xamarin-android-part-1 的样本, https://github.com/jamesmontemagno/Xam.NavDrawer/tree/master/Mvxhttp://enginecore.blogspot.ro/2013/06/more-dynamic-android-fragments-with.html - 然后实现适合您的导航需求的东西。

关于c# - 使用 mvvmcross 显示 View 模型时无法解析当前的顶级 Activity ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19397283/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com