Last active
March 1, 2017 15:00
-
-
Save Veverke/655c361dd74ebf73deb9d4b2aa2b77f1 to your computer and use it in GitHub Desktop.
Xamarin Dependency Service - Can't get OnActivityResult to be fired.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace DependencyServiceDemo.Droid | |
{ | |
public interface IDoWork | |
{ | |
void DoSomething(); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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..."); | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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