Skip to content Skip to sidebar Skip to footer

Using Notifications On Android With Mvvmcross

I do want to create a plugin which does implement something like a notification-service. So what I'm doing at the moment is something like this: var activity = Mvx.Resolve

Solution 1:

The default MvvmCross presenter on Android uses Intents for navigation. These are generated by the method Intent GetIntentFor(MvxViewModelRequest request) in the IMvxAndroidViewModelRequestTranslator interface.

By default this is implemented within: MvxAndroidViewsContainer.cs#L117

publicvirtual Intent GetIntentFor(MvxViewModelRequest request)
    {
        var viewType = GetViewType(request.ViewModelType);
        if (viewType == null)
        {
            thrownew MvxException("View Type not found for " + request.ViewModelType);
        }

        var converter = Mvx.Resolve<IMvxNavigationSerializer>();
        var requestText = converter.Serializer.SerializeObject(request);

        var intent = new Intent(_applicationContext, viewType);
        intent.PutExtra(ExtrasKey, requestText);

        AdjustIntentForPresentation(intent, request);

        intent.AddFlags(ActivityFlags.NewTask);
        return intent;
    }

If you need to generate Intents for other purposes (e.g. in order to then go on and generate PendingIntents) then you can Resolve and call this interface yourself.

var request = MvxViewModelRequest<MyViewModel>.GetDefaultRequest();
    request.PresentationValues = new Dictionary<string, string>() {
       { "life", "42" }
    };
    var translator = Mvx.Resolve<IMvxAndroidViewModelRequestTranslator>();
    var intent = translator.GetIntentFor(request);
    var pending = PendingIntent.GetActivity (context, 0, intent, 0);

For further information on generating MvxViewModelRequest objects, see also the overloaded ShowViewModel methods in MvxNavigatingObject.cs

Post a Comment for "Using Notifications On Android With Mvvmcross"