取消订阅NavigationView

时间:2015-09-25 11:42:28

标签: android xamarin mvvmcross

我正在开发Xamarin Android Application。我坚持如何取消订阅NavigationView检索到的消息。 我试过了:

public override void OnDestroyView ()
{
    messenger.Unsubscribe<UserLoginMessage> (_token);
    base.OnDestroyView ();
}

这是我在导航视图中订阅消息的方式:

 public class MenuFragment : MvxFragment<MenuViewModel>, NavigationView.IOnNavigationItemSelectedListener
{
    private NavigationView navigationView;
    public TextView LoginUserName;
    public ImageView ProfilePicture;
    public IMvxMessenger messenger;
    public MvxSubscriptionToken _token;
    public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
    {
        var ignore = base.OnCreateView(inflater, container, savedInstanceState);

        var view = this.BindingInflate(Resource.Layout.fragment_navigation, null);

        navigationView = view.FindViewById<NavigationView>(Resource.Id.navigation_view);
        navigationView.SetNavigationItemSelectedListener(this);
        navigationView.Menu.FindItem (Resource.Id.nav_home).SetChecked (true);
        navigationView.Menu.FindItem (Resource.Id.nav_LogOut).SetVisible (false);           

         messenger = Mvx.Resolve<IMvxMessenger>();
        _token = messenger.SubscribeOnMainThread<UserLoginMessage>(Login_Info,MvxReference.Strong);

        return view;
    }

但这不是取消订阅消息,而是我收到了两次消息 解决方案是什么?请帮助!

0 个答案:

没有答案