Cannot resolve current top activity while showing viewmodel using mvvmcross

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-11 08:48:00


I'm implementing a custom presenter in my Mvvmcross application. What I wanted to accomplish is: regular navigation and fragment navigation.

In my main activity, I managed to embed several fragment views based on this example:

while the fragments are working, I also wanted to show regular activities, that aren't hosted as a fragment. Therefor I extended this presenter as shown in this snippet:

The problem/bug: When I show this second activity, it gets shown. But when I go back to the previous view (which is the host) and re-open the same activity again, it doesn't get shown. The output log says: "mvx:Warning: Cannot Resolve current top activity"

What am I doing wrong, or what should I do, to inform the framework what activity is the current top activity?

Thanks in advance!


What is going wrong?

The line of trace you have provided is shown from:

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


So it would appear that when Show is called, then there is no current MvvmCross Activity shown.

... and looking at it does appear this is true - the main activity in the app is not adapted for MvvmCross, but is instead just a normal FragmentActivity.

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

MvvmCross normally tracks the "top activity" by intercepting Activity lifecycle events - specifically the Activity created, started, restarted, resumed and destroyed events. These are shown in the lifecycle diagram in


  • hooks into these events via the MvxActivityAdapter in
  • these hooks call the extension methods in
  • these extension methods inform the lifecycle monitor about the lifecycle changes - see -

All the built-in MvvmCross Activity types - MvxActivity, MvxFragmentActivity, etc - call these "automatically". These adaptions can be extended to other Activity types using steps like those described in ActionBarSherlock with latest MVVMCross, or your app can manually call some of these hooks if it prefers.

Personal opinion: I think you'd be better off not following too closely. The code in OnCreate in seems to try to Start the app every time that MainActivity is created - which can, of course, happen multiple times during the lifecycle of each app.

Instead, read that sample and others like, and - then implement something that suits your navigation needs.