460 likes | 621 Views
Building Windows phone, iOS and Android apps with C#. Jaime Rodriguez Principal Evangelist, Microsoft. About me Why this talk…. 2000. 2005. 90s. 2008-Today. Primitives. Mobile. Productivity. UX. Disclaimer. About me Why this talk…. 2000. 2005. 90s. 2008-Today.
E N D
Building Windows phone, iOS and Android apps with C# Jaime Rodriguez Principal Evangelist, Microsoft
About me Why this talk…. 2000 2005 90s 2008-Today Primitives Mobile Productivity UX Disclaimer
About me Why this talk…. 2000 2005 90s 2008-Today I do not work for Xamarin Opinions are my own, not those of my day-job employer This space evolves very fast Primitives Mobile Productivity UX Disclaimer
Mobile Explosion • Consumers are already mobile-first • Business users are increasingly demanding mobile scenarios
How? #1 – Web Build a Mobile Website
How? #2 – Hybrid Web Native App Mobile Website Put a Web App In the Store
How? #3 – Cloned Native Build App Multiple Times
How? #4 – Shared Native Build Natively and Share Code Shared UI Code
Why Native? Xamarin apps look and feel native because they are native Native User Interfaces Native API Access Native Performance
… add Windows APIs 100% coverage
… or iOS APIs 100% coverage
… or Android APIs 100% coverage
demo Xamarin Development with Visual Studio
iOS @implementationMSViewController - (void)viewDidLoad { [superviewDidLoad]; } - (IBAction)OnButtonDown:(id)sender { UIAlertView* view = [[UIAlertViewalloc]init]; [view setTitle:@"Hello World"]; [view setMessage:@"How are you?”]; [view addButtonWithTitle:@"OK"]; [view show]; } @end publicpartialclassiOSAppViewController : UIViewController { publiciOSAppViewController (IntPtr handle) : base(handle){}publicoverridevoidViewDidLoad(){base.ViewDidLoad ();}partialvoidOnButtonDown (UIButton sender){ UIAlertView view = newUIAlertView(); view.Title = "Hello World" ; view.Message = "How are you? " ; view.AddButton ("OK"); view.Show(); } }
Android [Activity (Label = "AndroidApp", MainLauncher = true, Icon = "@drawable/icon")]publicclassMainActivity : Activity {protectedoverridevoidOnCreate (Bundle bundle) {base.OnCreate(bundle);SetContentView(Resource.Layout.Main);Buttonbutton = FindViewById<Button> (Resource.Id.me);button.Click+= delegate {AlertDialog.Builderbuilder = newAlertDialog.Builder (this ); AlertDialogdialog = null ; builder.SetTitle( "Hello World").SetMessage ( "How are you") .SetPositiveButton( "OK" , delegate { dialog.Dismiss(); } ); dialog = builder.Show (); } ; }} public class MyActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { Button myBtn = (Button) this.findViewById( R.id.clickMe); myBtn.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View view) { AlertDialog.Builderbuilder = new AlertDialog.Builder(MyActivity.this) ; builder.setTitle( "Hello World") .setMessage("How are you?") .setPositiveButton( "OK", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterfacedialogInterface, inti) { dialogInterface.dismiss(); }}) .show(); }});} }
Anything you can do in Objective-C or Java can be done in C# with Xamarin using Visual Studio
Native Performance Xamarin.iOS does full Ahead Of Time (AOT) compilation to produce an ARM binary for Apple’s App Store. Xamarin.Android takes advantage of Just In Time (JIT) compilation on the Android device.
So far… Using C# BCL on iOS, Android and Windows Phone apps C# Bindings to iOS/Android Great tooling Editors Debugging Extensibility Potentially cumbersome code sharing as you write platform specific code ?
Sharing v1 Really?
Compiler Directives Linked Files
Share Code: Portable Class Libraries 1 Assembly Multiple Platforms Including: Xamarin.iOS Xamarin.Android
UI: Xamarin+ Xamarin.Forms With Xamarin.Forms: more code-sharing, native controls Traditional Xamarin approach Shared UI Code
UI: Xamarin.Forms • 40+ Pages, Layouts, and Controls • Build from code behind or XAML • Two-way Data Binding • Navigation • Animation API • Dependency Service • Messaging Center Shared UI Code
Layouts ContentView ScrollView Absolute Relative Grid Stack Frame
Controls BoxView Button DatePicker Editor ActivityIndicator Entry Image Label ListView Map OpenGLView Picker ProgressBar SearchBar Slider Stepper TableView TimePicker WebView EntryCell ImageCell SwitchCell TextCell ViewCell
Xamarin Forms • Mark-up (XAML 2009 spec) • Data binding & Data Templates • Markup Extensions • Resources Dictionaries
Xamarin Forms Platform Features • Page.DisplayAlert • UI Thread marshalling • Timers • Xamarin.Forms.Maps • Platform code via OnPlatform<T> and DependencyService.Get<T>
demo Hacking away with Xamarin and Visual Studio
Ramp-up & Mastery • To be successful using C# on iOS, Android, and Windows Phone, you still have to know how to code for these platforms
Sharing code… what should you use? • PCL • Shared Projects • partial classes • C# extensions • All of the above
UI Patterns & Tips • Separate your concerns • Declarative XAML • MVVM is not required • Use OnPlatform<T> for platform specific code • Use ContentPage + layout panels for dynamic resolution
Connect to the cloud: Microsoft Azure http://azure.microsoft.com/en-us/documentation/services/mobile-services/
Memory & Garbage Collection • iOS • Uses AOT (Ahead of Time) compiler • Two GCs: default (Boehm) or Sgen • Android • Uses Sgen GC • Windows Phone • Uses .NET GC, http://developer.xamarin.com/guides/cross-platform/application_fundamentals/memory_perf_best_practices/ http://msdn.microsoft.com/en-us/library/ms973837.aspx
Performance • Is usually not a problem • Use native tools to measure • iOS: Instruments • Android: Device Monitor’s Allocation Manager • Windows Phone: Visual Studio, Windows Phone Power tools, • Graphics Diagnostics
Closing: Mobile app development with C# • Familiar • Productive • Highly reusable • Empowering • Built on a solid and extensible foundation
Want to win a free Xamarin license? • Download free version of Xamarin Studio … • Create a small Hello World Project on at least two of the three platforms: Windows Phone, Android, iOS. • Tweet a link to your project to @jaimerodriguez before October 10th at noon PST • One random submission will be selected….and a coupon for free license will be emailed
Gracias!!! • Aquiestoy los tresdias! • @jaimerodriguez • jaimer@microsoft.com