“Introduction to Xamarin” events are over! Let’s recap!

Good evening everybody,

it has been a while since the last time I wrote here, but I have been really busy organizing Xamarin Student Ambassadors events here in Milan!

So, what did we speak about? We had the chance to keep 3 lessons and they were articulated in this way:

  1. During the first lesson we introduced the Xamarin world and benefits, and showed how to code two apps with Xamarin, one running on iOS, the other one running on Android.
    1. Introduction Slides: http://www.slideshare.net/guidomagrin/introduction-to-xamarin-48120074
    2. Android e iOS Slides: http://1drv.ms/1EvQZ25
  2. During the second lesson we explained how to use Xamarin.Forms and how to use MVVM in Xamarin.
    1. Xamarin.Forms Slides: http://www.slideshare.net/guidomagrin/xamarin-forms-48299949
    2. Xamarin.Forms Code: https://github.com/guido1993/somecode/tree/master/Introduction%20to%20Xamarin/2nd%20Lesson%20-%20Xamarin.Forms%20Demo%20App
  3. During the third and last lesson we explained how to use SQLite into a Xamarin.Forms app, how to create Custom Renderes in Xamarin.Forms and how to implement Azure Mobile Services in a Xamarin.Forms app.
    1. SQLite Slides: http://www.slideshare.net/guidomagrin/sqlite-in-xamarinforms
    2. Azure Mobile Services Slides: http://1drv.ms/1Q8gkGh
    3. Azure Mobile Services Code: https://github.com/poz1/PoliXamarin.MobileServicesDemo

You can find the material for each lesson at the given links! I hope that all of this material will be found useful by at least someone! We will be planning more events, after summer!

See you soon, and happy coding! 🙂

How to overcome the 2 GB RAM limit on Android Visual Studio 2015 emulators

Good evening everybody!

As a devoted Xamarin dev, as soon as it got available, I installed Visual Studio 2015 Release Candidate on both my work machines, my desktop PC (with 16 GB of RAM) and my Surface Pro 3 (with “just” 4 GB of ram).

And this is where the issue raised: I tried running the new Visual Studio 2015 Android emulator, boosted by Hyper-V, on both PCs, but it relentlessly failed to launch multiple times on my Surface Pro 3, always returning this error:

Android Emulator 2048 MB error

“Visual Studio Emulator for Android: The emulator is unable to verify that the virtual machine is running: Not enough memory is available in the system to start an emulator that uses 2048 MB of startup RAM. Please close other applications and try to launch the emulator again. If closing other applications doesn’t help, please follow the instructions on this KB article: http://support.microsoft.com/kb/2911380/en-us”

And that’s what I did! I slavishly followed every single step that was suggested by that Microsoft article, and this would have theoretically led me to have a running Hyper-V Android emulator on my PC, but upon several restarts and attempts, nothing changed.

That’s where I opened the Hyper-V Manager and manually modified the settings of the Emulator “VS Emulator 5-inch KitKat (4.4) XXHDPI Phone.guido”, in order to make it need 1024 MB instead than 2048 MB. It may have worked out at first, but Visual Studio thought: “Why did he change the required RAM to 1024 MB? Hey! Let’s revert it to 2048 MB, so his poor PC won’t be capable of handling it!” (yeah, I have around 1.5 GB of free RAM, sadly, with just Visual Studio 2015 running on my SP3).

In complete despair, I started wandering in the Visual Studio installations folders on my PC, to check where the heck it was forcing the starting RAM of the emulator to be exactly 2048 MB. I encountered some files that didn’t help me at all, but at last I found the right ones, modified them and, upon trying again, my Hyper-V Android emulator was running great on my Surface Pro 3! 😀

The configuration (.cfg) files you have to modify are located here:

C:\Users\[YourUserName]\AppData\Local\Microsoft\VisualStudioEmulator\Android\Containers\Local\Devices

Just head to this URL and you will find the four little bastards:

FilesToModify

Now you will just have to open each one of them and change this line content, replacing the “2048” value with “1024”:

FROM: device.vm.ram.size=2048
TO: device.vm.ram.size=1024

While I didn’t try if the emulators were launching with lower RAM values, I suppose that it’s possible reducing the RAM size until 512 MB without incurring in major issues (and unless you are debugging a game or something as heavy). All I can say is that with 1024 MB the Hyper-V Android emulators run just as fine as they run with 2048 MB on my desktop PC.

I am leaving here a link to download a .zip file to make you able to download the four files, already patched and such: http://1drv.ms/1QjZExk

Well, this is what worked for me! 🙂 Feel free to post below here for more support, should you still have that infamous screen show up after following my guide!

Happy coding! 🙂

Why should I make my next mobile app in Xamarin? #Part5: You are using C#!

In this brief post, the 5th of the series, we will analyze why it’s relevant that Xamarin is build around C#! 🙂

Well, starting from basics, one of the main advantages of C# are the support of LINQ, which allows you to execute queries and select data from arrays and databases like SQLite. An example of LINQ:

LINQ

Moreover, in C# you can easily manage Events and Delegates:

EventsDelegates

And you can work with IntelliSense and Lambda expressions!
Also, C# natively supports JSON through the Json.NET library. Json.NET offers simple conversions to and from JSON strings and .NET objects, with SerializeObject and DeserializeObject methods.
Here is an example of creating a class with a method to get names:

ObjCClass C#Class

In C#, one line with LINQ is used to execute the whole command. Also, the C# class takes advantage of C# features and set properties easily.
Last but not least, the Async/Await constructs will allow you to set up a multithreading environment with the lowest effort possible. Below here a comparison between the Async/Await and the same code written in Objective-C!
ObjCAsync C#Async

See you on the next post! 😀
Happy coding! 🙂