Tag: Mobile phone

Programming Stuff

iOS/Android/VisualStudio/C#/Xamarin – Getting a Working iOS Build

I’m happy to report that since my previous post, I am now able to build the iOS app without any difficulty. Thanks again to James Montemagno at Xamarin for his help.

BTW: My apologies for the 4-day gap between posting on the issue. I was out of town and didn’t have my Mac with me so couldn’t do the iOS part of the build.

The reason I encountered errors & warnings when building the iOS project is due to the fact that when the wizard generates the project it does not fill in 3 key fields in the project properties: Application Name, Identifier, and Version. The fields are all blank as shown here.


I filled those in with the appropriate values as shown here…


… and all builds well.

One bit of frustration is that I didn’t see anywhere in the Xamarin Hello, iPhone documentation where it said I had to fill these values in for a valid build.

Near the end of the documentation it does mention that one can edit the plist file using property pages. However, the screen shot shows the Identifier and Version fields empty giving one the impression that leaving them blank is OK.

With those values being so important, I would’ve preferred that Xamarin did one of the following (listed in my order of preference).

  1. Prompt for the values in the project wizard
  2. Default the fields to some reasonable value

In fairness, the error/warning messages do indicate that the values need to be set on the property page. It’s just that after the other headaches I was experiencing, seeing an untouched, wizard-generated project fail to build left me a bit discouraged.

IMHO – When working with a brand new environment, its critical that what comes out of the wizard must build without any errors. So often all one is trying to do is verify that the pieces are working and build errors on untouched wizard-generated projects give one the impression that something is wrong. 🙂

Build Success/Failure

One little thing that surprised me is that Visual Studio is not updating the status bar to indicate that a successful build has completed. In the case of a standard Visual Studio project, the status bar displays a message like the following indicating build success.


In the case of my VS solution containing the iPhone project, the status bar does not update with a success message as you can see here.


I’ve had to have the Output window open so that I can see when a successful build completes.

Although I haven’t tried to exhaustively diagnose the cause, the lack of a success message appears to be tied to the fact that the solution contains an iPhone project (Xamarin will often display the Mac build host IP Address in the status bar). When I create a solution containing only an Android project, the build result displays in the status bar as expected.

Xamarin.Android Beta Issue

Just to follow up on the issue I mentioned in my last post about the Xamarin.Android Beta breaking Xamarin.iOS in Visual Studio.

The folks at Xamarin have followed up and let me know that there is an incompatibility between the Xamarin.Android version that is currently in Beta and the production release of Xamarin.iOS. To safely install the Xamarin.Android Beta, I’ll need to install the corresponding Xamarin.iOS Beta … A very reasonable requirement.

You can find the bug report and Xamarin’s response here.

I’m not sure if I’m going to do the Beta installs right now or not. I may just wait for them to reach production release. I’ll keep y’all updated if I do decide to install the Betas.

Carrying On

So everything appears to now be working. I can start really digging into things now.

I do want to give Kudos to the folks at Xamarin…

So far every issue I’ve raised whether in their Forums or on their Bugzilla page has been responded to in a very reasonable time frame. Thanks guys!

Programming Stuff

iOS/Android with Visual Studio/C# Using Xamarin, First Impressions: A Little Frustrating

I’ve been wanting to dig into using Xamarin to do iOS/Android development in Visual Studio/C# for a while now. So finally had a chance to start looking into it closely.

Update: After you read this post, checkout the follow up.

I now have everything setup and running. I must admit that creating my first Android and iOS projects was not as a satisfying has I had hoped. There’s a bit of flaky behavior in the Android UI designer and the wizard generated projects for both Android and iOS have problems.

Let’s look at the Android side of things first.

Android Designer

The initial problems I ran into were tied to unexpected UI designer behavior I encountered when it was first opened.


  1. The “Alternative Layouts” button, which is a really cool feature that lets one manage different device layouts more easily, didn’t work at all. Clicking on it did nothing.
  2. The other buttons across the top allow one to manage the UI layout in different environments. As you can see some of those buttons are too small for their labels. There also some missing.
  3. I was expecting buttons on the bottom-left of the designer to allow me to toggle between the design-view and the XML-view but they aren’t there.
  4. Finally the label of the button on the device design-surface is showing the name of the string resource ‘@string/Hello’. It should be displaying the actual value.

The first two issues are easily resolved by simply taking some action that causes the design window to resize: explicitly resizing it, hiding/showing the toolbox, etc.

It turns out that the design-view/XML-view toggle buttons are not supported for VS2013 in the current stable release of Xamarin.Android (4.10.1), although they are supported in earlier VS versions and in Xamarin Studio (Xamarin’s stand-alone IDE). I checked around and found that the beta version of Xamarin.Android 4.10.2 does include support for the toggle buttons so I decided to install the beta.

When I installed the beta, it did indeed add the toggle buttons. It also fixed the first two issues I mentioned BUT

… it completely broke iOS support in Visual Studio 2013 (we need to keep in mind that Xamarin.Android 4.10.2 is still in beta). I could no longer open or create iOS projects (remember it’s Android support that I updated). Unfortunately reinstalling Xamarin.IOS did not fix it. I ultimately had to completely uninstall all of Xamarin then reinstall from scratch and live without the toggle buttons for now.

Android Project

Moving on from the Android UI designer for a moment, I also ran into problems with the wizard-generated Android project in that it’s naming the Android resource folders incorrectly.


Notice that the folders under Resources (Drawable, Layout, Values) are all capitalized. That’s not supposed to be the case [ excuse the pun 🙂 ]. The Android platform doesn’t like that. Those are supposed to be all lower-case. I had to go through and manually rename them. Not ideal but not the end of the world.

BTW: Fixing those folder names had a nice side effect: It resolved the problem with the string resources. With those names fixed, the string resource values now display correctly on the device design surface (thanks to James Montemagno at Xamarin for his help on this one).

You can follow the steps I went through working things out on the Xamarin Forum.

iPhone Project

After working through all the Android stuff I setup all of the iOS pieces which include setting up a Mac as a build server. The setup process went pretty smoothly. I then ran the wizard to generate an iPhone Hello World app, did a build and immediately got 2 build errors and 1 build warning.


And with that I’m calling it a day.

I must admit, I expected an unchanged, wizard-generated project to be error free. 🙂

Keeping Perspective

To not blow things out of proportion, we want to keep in mind that none of the issues I’ve mentioned are show-stopping. They’re basically annoyances and all fairly easily worked around.

We don’t want to lose sight of the fact that Xamarin is solving a very hard problem. Android and iOS are incredibly different platforms with many of their own nuances and complexities. Then on top of that, Xamarin has to integrate into Visual Studio (a complex IDE) and interact with the iOS toolset running on a Mac. Many, many challenges to overcome.

Final Thoughts

Working in a brand new environment is always a bit stressful. For me, the best way to have that stressed relieved is for the environment to all work smoothly which didn’t quite happen in this case. That said, I have a workable environment and although I do need to apply some workarounds, they are all fairly easy to deal with.

I’ll dig back into things tomorrow.

Update: I’ve posted a follow up to this post.

Programming Stuff

Creating Dynamic UI with Android Fragments gets 5-Star Review

I’m not big on self-promotion but I’ll make an exception as this is an exciting day for me…

My book Creating Dynamic UI with Android Fragments received its first user review on Amazon and its a 5-Star Review

This book is just what I was looking for. The three pieces I was having issues with were static vs. dynamic fragments, dialogue fragments and backstack management. This book covers all three of these in a manner that has really cleared up my understanding and improved my application design as a result.

Thank you to kbp135 – Here’s the link to the review.

And just in case you’re wondering … the reviewer is not someone I know 🙂

Checkout Creating Dynamic UI with Android Fragments for yourself. I’d love to hear your feedback.

Creating Dynamic UI with Fragments


Also checkout Jim’s Android courses at Pluralsight.

Jim's Android courses on Pluralsight

Jim’s Android courses on Pluralsight

Programming Stuff

Android Developers Earn More Money than iOS Developers

According to recent data, senior Android developers average $131,000 per year versus $121,000 for the same skill level on iOS.

That’s some pretty serious cash!

So what are you waiting for … clearly, it’s time to get your Android skills tuned up! 🙂

The full story is available in this Tech Week article.

Checkout Jim”s Android courses on Pluralsight.

Jim's Android courses on Pluralsight

Jim’s latest book, “Creating Dynamic UI with Android Fragments” is now available on amazon.

Creating Dynamic UI with Fragments

Programming Stuff

Android for .NET Developers Series Complete!

Part 4 of my four-part series on Android programming for developers with a .NET background just went live today.



This course delves into the unique features of the Android platform and how those features and the related components affect the way apps are created.

I hope you’ll check out this course and the whole series if you haven’t already seen it. I think you’ll be happy you did.

Here’s the complete series

Part 1: Getting Started

Android for ,NET Developer Series: Getting Started


Part 2: Building Apps with Android Studio

Apps with Android Studio


Part 3: Adopting the Android Mindset



Part 4: Understanding the Android Platform


Programming Stuff

Android Updatable Swipe Navigation with FragmentStatePagerAdapter

Android Studio makes adding swipe navigation to your Android apps easy through the “Scrollable Tabs + Swipe” option of the Navigation Type selection in the New Project Wizard. Choosing this option works great as long as you have a static list of screens that the user “swipes” between.


When Static Screen Lists Aren’t Enough

The way swipe navigation works is that each screen is represented by an instance of a Fragment-derived class. These Fragment classes are then managed by a PagerAdapter-derived class which makes them, in effect, a scrollable list. Passing that PagerAdapter to a ViewPager presents that list in a way that the user can use a swipe-motion to move between screens.

The code generated by Android Studio provides a custom PagerAdapter class that derives from  FragmentPagerAdapter. Basically all one has to do is override the getItem method and return the desired Fragment for each screen position (you’ll also need to override getCount and getPageTitle but those are super simple). What happens though is that the FragmentPagerAdapter class is designed such that once a Fragment instance is returned for a given position that Fragment is permanently in that position. Once this happens, you can, of course, make changes to the contents of the Fragment but there’s no way to provide a different Fragment instance for that position which is often what’s necessary.

The comments in the generated class indicate that using FragmentStatePagerAdapter instead of FragmentPagerAdapter as the base class allows for more dynamic management of the Fragment instances. Reading the FragmentStatePagerAdapter documentation indicates that we can notify our FragmetStatePagerAdapter instance of a change in the list of screens (in other words that we’d like to use new Fragment instances) by calling the notifyDataSetChanged method. But that’s only part of the story.

Once you call this method what you’ll normally see is that screens that were previously visited still have the old Fragment instances but screens being visited for the first time have the new Fragment instances. If you have a large number of screens and scroll back and forth between them you may see some of the older screens eventually show a new Fragment instance.

Not really the consistent user experience we’re looking for 🙂

So what’s the problem?

What’s happening is that FragmentStatePagerAdapter is trying to be efficient and only create new Fragment instances when necessary. To determine when to request new Fragment instances after a call to the notifyDataSetChanged method, FragmentStatePagerAdapter calls its getItemPosition method to see if an existing Fragment can be used in its current or possibly a different position without having to recreate it. What we have to do is tell the FragmentStatePagerAdapter instance that we don’t want to use the existing Fragment instance.

To do that we need to override getItemPosition as follows

public int getItemPosition(Object object) {
 // Causes adapter to reload all Fragments when
 // notifyDataSetChanged is called

By returning POSITION_NONE we’re telling the FragmentStatePagerAdapter instance to discard that Fragment and just create new ones for every screen position.

Summary: How To Create Updatable Swipe Navigation

To summarize what to do, here’s the list of steps…

  1. Select “Scrollable tabs + swipe” as the Navigation Type when generating your project in Android Studio
  2. Change the FragmentPagerAdapter base class to FragmentStatePagerAdapter
  3. Override the getItemPosition method to return POSITION_NONE
  4. Call notifyDataSetChanged in your code when you’d like to load new Fragment instances.

And with that, you have the ease of swipe navigation with the ability to reload Fragments instances as needed

Adapted from Jim’s Pluralsight course Android for .NET Developers: Adopting the Android Mindset


Checkout Jim’s latest book: Creating Dynamic UI with Android Fragments

Creating Dynamic UI with Fragments

Programming Stuff

Creating Dynamic UI with Android Fragments … or…

What I did on my Summer Vacation 🙂

Creating Dynamic UI with Fragments

It’s been a crazy busy Summer. Since May I’ve released 3 new Android courses for Pluralsight with a 4th coming out in a few weeks and wrote a book on Android Fragments titled Creating Dynamic UI with Android Fragments.

I’m excited to announce that the book just became available for pre-order today!!

I need to take a minute to thank my beautiful wife, Bonnie. As you might imagine, I’ve been putting in a lot of hours these past few months and would never have been able to get through it all without her. Her patience and support never end. Bonnie I love you!!

My life is so blessed, I can barely believe it.