Skip to content

Instantly share code, notes, and snippets.

@Veverke
Last active March 1, 2017 15:00
Show Gist options
  • Save Veverke/655c361dd74ebf73deb9d4b2aa2b77f1 to your computer and use it in GitHub Desktop.
Save Veverke/655c361dd74ebf73deb9d4b2aa2b77f1 to your computer and use it in GitHub Desktop.
Xamarin Dependency Service - Can't get OnActivityResult to be fired.
namespace DependencyServiceDemo.Droid
{
public interface IDoWork
{
void DoSomething();
}
}
using System;
using Android.App;
using Android.Content.PM;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;
using Android.Content;
using DependencyServiceDemo.Droid;
[assembly: Xamarin.Forms.Dependency(typeof(MainActivity))]
namespace DependencyServiceDemo.Droid
{
[Activity(Label = "DependencyServiceDemo", Icon = "@drawable/icon", Theme = "@style/MainTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity, IDoWork
{
public void DoSomething()
{
System.Diagnostics.Debug.WriteLine("Doing something...");
}
protected override void OnCreate(Bundle bundle)
{
TabLayoutResource = Resource.Layout.Tabbar;
ToolbarResource = Resource.Layout.Toolbar;
base.OnCreate(bundle);
global::Xamarin.Forms.Forms.Init(this, bundle);
LoadApplication(new DependencyServiceDemo.App());
}
protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
{
base.OnActivityResult(requestCode, resultCode, data);
System.Diagnostics.Debug.WriteLine("On Activity Result...");
}
}
}
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:DependencyServiceDemo"
x:Class="DependencyServiceDemo.MainPage">
<Label Text="Welcome to Xamarin Forms!"
VerticalOptions="Center"
HorizontalOptions="Center" />
<Button Text="Click Me" Clicked="onClicked" />
</ContentPage>
using DependencyServiceDemo.Droid;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
namespace DependencyServiceDemo
{
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
}
private void onClicked(object sender, EventArgs e)
{
//DisplayAlert("No Camera Found", "No Camera Found/Available", "Close");
DependencyService.Get<IDoWork>().DoSomething();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment