I have created a service interface:
public interface IMessageDialogService
{
void ShowDialog(object context,string title,string message,string buttonTitle);
}
I have implemented that interface on both Android and iOS. The context is only used on Android where an Android Context is needed to display a message dialog. I pass this interface into my ViewModel to be injected by IoC. My problem is in my platform independent ViewModel which calls a WebService and then handles the return value. It checks the return value for an error condition and needs to display a message dialog. iOS does not need any context to display a UIAlertView, but on Android how do I get a hold of an Android context to pass in as the first argument?
Is there an easier way to display a simple informational dialog from a ViewModel?
After inspecting the source for the WebBrowserTask, it looks like I can always grab the current Activity by:
var activity = Mvx.Resolve<IMvxAndroidCurrentTopActivity> ().Activity;
so I don't have to pass it down, but have my implementation of IMessageDialogService on Android grab it and use it to display the message dialog.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With