Remove activity from stack using Mono droid and sl

2019-02-16 03:35发布

I am trying to find a way to remove an activity from the stack- We have a flow in our app: activity/viewmodel a -> activity/viewmodel b ->activity/viewmodel c. In c the user have the posibility of choosing a date or go back. If he goes back he should be returned to b. However if he chooses a date he is fowarded to a new instance of activity/viewmodel b and the "old" instance of activity/viewmodel b is obsolete and should be removed.

A suggestion from Stuart Lodge (on a similar thread, just for mono touch) was to use RequestRemoveBackStep() but I am not sure how to use it and I cant find an example.

Can anyone point me in the right direction?

Regards

1条回答
Emotional °昔
2楼-- · 2019-02-16 04:07

The RequestRemoveBackStep() method is a member of the IMvxViewDispatcher interface and is implemented on some platforms:

public interface IMvxViewDispatcher : IMvxMainThreadDispatcher
{
    bool RequestNavigate(MvxShowViewModelRequest request);
    bool RequestClose(IMvxViewModel whichViewModel);
    bool RequestRemoveBackStep();
}

from https://github.com/slodge/MvvmCross/blob/vnext/Cirrious/Cirrious.MvvmCross/Interfaces/Views/IMvxViewDispatcher.cs

However, its not entirely simple to always do this... so on Droid, for example, it is currently implemented as:

    public bool RequestRemoveBackStep()
    {
        // not supported on Android? Not sure how to do this currently...
        return false;
    }

from https://github.com/slodge/MvvmCross/blob/vnext/Cirrious/Cirrious.MvvmCross.Droid/Views/MvxAndroidViewDispatcher.cs

There are issues logged about this functionality - e.g. https://github.com/slodge/MvvmCross/issues/80 - but it seems likely that this functionality might simply be dropped from future Mvx implementations - especially as it's not very easy to do for every view on every platform.


If you need this type of functionality now, then you'll need to find your own way of implementing this functionality... depending on what your specific use case is (sorry - the details of your current use case aren't clear to me from the question).

There are several technical routes available including:

  • using NoHistory flags
  • using RequestClose(oldviewModel) calls
  • adding logic to your Presenter
  • using a Messenger to request views close themselves.
查看更多
登录 后发表回答