CloudStorageAccount.Parse – Azure SDK 1.8

November 5, 2012 12:56 by wjchristenson2

Just a quick heads up to anyone that is trying to code against their development machine’s storage emulator and recently upgraded their Azure SDK to 1.8 (October 2012).  There is a nasty bug with the development storage connection string “UseDevelopmentStorage=true”.  You will likely get the following error: “The given key was not present in the dictionary.” when trying to parse the cloud storage account connection string like below.

 

// Retrieve storage account from connection string.
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("StorageConnectionString"));

 

To get around this issue, add the following to your development connection string “DevelopmentStorageProxyUri=http://127.0.0.1”.  Here’s the full connection string: “UseDevelopmentStorage=true;DevelopmentStorageProxyUri=http://127.0.0.1”.  This did the trick for me.  Hope it helps!

 

Bookmark and Share

Debugging Web Requests with Fiddler for Android

May 4, 2012 08:18 by wjchristenson2

Fiddler is a popular web traffic debugging tool which lets you inspect web requests.  This ability is very helpful when developing applications which consume web services.  I’ve been working with a team on an Android application and I needed to use Fiddler with Android.  In this post, I’m going to show you how to setup Fiddler to inspect web traffic from an Android device running Ice Cream Sandwich.

 

1) First, if you don’t have Fiddler yet, you can download it here.

2) Second, you need to set and take note of some Fiddler options.  Check the “Allow remote computers to connect”.  This option will allow your Android device to connect to Fiddler via your computer’s local IP address and proxy port.  You can see and/or configure what port Fiddler listens on as shown below.  The default proxy port is 8888.

3) Restart Fiddler so that it loads your new configuration options.

4) Next, you’ll need to setup your Android device to run it’s connectivity through Fiddler.  Navigate to Settings >> Wireless & Networks >> WiFi.  Select the network you are using.  If you are debugging your Android application, you’ll probably be using your local wireless connection.

5) Enter the basic settings and check “Show Advanced Options”.

6)  Under Proxy Settings, select “Manual” so we can manually enter the IP address & proxy port which Fiddler is running on.

7) Enter the IP Address and Proxy Port information where Fiddler is running.  Most likely Fiddler will be running on your local development machine.  If using Windows, you can find your IP address by going to the command prompt and using ipconfig (Start >> Run >> “cmd” >> “ipconfig”).

 

That’s all there is to it.  After you have this setup, make sure that Fiddler is running and web traffic from your Android device should be routed through Fiddler.  Happy web traffic inspecting!

 

Bookmark and Share

Breakpoints not hit while Debugging an AsyncTask in Eclipse for Android

May 1, 2012 03:10 by wjchristenson2

I ran into an issue yesterday where my breakpoints in an AsyncTask doInBackground method were not being hit.  After an hour of troubleshooting, I found two situations that can cause this issue.

1.  The doInBackground method is running before the Android debugger can attach to the process. Add the following to the beginning of your doInBackground method to see if this is the case.  If not, see cause 2 below.

 

@Override
protected Void doInBackground(Void... params) {
	android.os.Debug.waitForDebugger();
	
	// TODO Auto-generated method stub
	return null;
}

 

2.  An AsyncTask cannot execute another AsyncTask within the doInBackground method.  This was my problem.  An AsyncTask must be executed from the main (UI) thread.  So AsyncTask “A” cannot execute AsyncTask “B” in its doInBackground method as this is running on a background thread.

 

Bookmark and Share

Performance Tips for Loading Objects with a SQLiteCursor

April 22, 2012 07:02 by wjchristenson2

This last week, I ran into poor performance loading Java objects on Android using SQLiteCursors.  I needed to load a hierarchy of objects.  This hierarchy was 4 levels deep and contained around 1,000 objects.  I tried a few approaches to see what method could load these objects the fastest.

In my first approach, I decided to de-normalize my results to limit the number of database hits.  Instead of 100’s of database hits (queries), I returned 3 large result sets.  Then, I thought I’d loop the cursors to fill the hierarchy starting with the top levels and working to the detail levels.  Loading the objects took 50.9 seconds…  Ouch.

I knew that all 3 queries took < 1 second.  So I looked at the loading of each object.  I thought part of my problem was the SQLiteCursor.getColumnIndex() method.  I’ve read that this method can be very taxing.  So I thought I’d create a HashMap of the column indexes and then pass that to the loading of each object so I didn’t have to call the getColumnIndex() method for each property for each object.  A coworker of mine made me a bet that the SQLiteCursor already lazy loaded the column indexes so subsequent calls wouldn’t have to loop the column names each call.  He was right.  So creating a HashMap of column names to indexes would not help.

My next thought was that looping SQLiteCursors over and over was not a good idea.  So I had a better idea.  Load the objects from the cursor with one loop into a generic ArrayList, then assemble the hierarchy/relationships. 

I’m used to .NET and disconnected Datasets and DataTables.  I’d usually load a DataTable then run DataTable.Select() filters on it to get my data subsets to build object hierarchies… but Android doesn’t have such mechanisms.  So I decided to add helper properties to my objects so that I could load a generic ArrayList of my objects from cursors and then assemble them after the database querying was done.  This proved to be a very good idea.  3 queries with loading of 3 generic ArrayLists of my objects ran in just over 1 second.  That proved that the SQLiteCursor.getColumnIndex() is not as taxing as I thought.

Assembling the objects into the hierarchy then boiled down to nested loops and setting the appropriate object relationship properties.  Total cost: < 3 seconds after a 50.9 second first try.  Much better… I want it in ~1 second.  We’ll see where I go from here.

Lesson: Don’t use SQLiteCursors in nested loops to build object hierarchies.  Get the data in the least number of database hits that you can, load your objects from a cursor in a single loop, close your cursor, and then assemble the object hierarchies after.  Also, remember if you are running multiple select statements to run them under one transaction.  Multiple transactions for multiple queries is more taxing than one transaction for multiple queries.  Remember that SQLite implicitly creates a transaction for each query ran unless you explicitly create one and run all queries under it.

 

Bookmark and Share

Peer Interview Tips

February 26, 2012 06:03 by wjchristenson2

This last week, I had the privilege of speaking at SBU (Southwest Baptist University) with HealthMEDX on technical/peer interviews.  I thought I'd share some of my interview tips and hopefully they can help you land the job.

Don't say that you are proficient at a technology and/or programming language if you aren't.  It's better to be conservative than vice versa.  The peer interviewers typically have a higher skill-set than you and they will find out the truth.  You don't want to leave a bad impression with stating you know more than what you really do.

Ensure your social networking and public search information is professional.  Facebook, MySpace, Google+, etc all have a vast amount of information on people these days.  When reviewing your resume, companies will usually try and search for additional information on you.  A lot can be said about you if the company can find your social networking profile.

Focus on your soft skills.  Software development is continuing to evolve into agile/team environments.  Being able to effectively communicate technically and non-technically is extremely important.  You'll be working with analysts, support, quality assurance, etc.  These skills are vital to your success and companies look for these skills coupled with your technical skills.

Bring some code or examples of your work that you are proud of.  One, it demonstrates that you know the technology or programming language.  Second, having pride in your work is a plus.  It shows the peer interviewers that you care about what you create and it gives you satisfaction when you create something awesome.

Know their culture and ask them about it.  It shows them that you want to ensure that it is a good fit for both parties.  I currently work for HealthMEDX which has a casual/fun culture.  We wear shorts, t-shirts, flip-flops, etc.  When interviewees come to interview with a full suite, it is a little awkward on both sides.  Is that a good fit for you?  Are you willing to work in an environment which is casual?  You want to work for a place that is a good fit for you.  So know the culture before interviewing.  It will help you know if the company is a good fit for you and help you "bond" with the interviewers a bit more.

Know what technologies the company employs.  Even if you don't know the technology or language, you can research it ahead of time and it will help you communicate what you know and how it may relate to their technologies.

Don't project yourself as being entitled to the job.  I've seen many college students think that they are the bomb...  That's not a team attitude and that will turn off companies very fast.  Remember that it's you that is wanting the job/offer.  Being humble will go a long way.

Be positive.  Don't rag on your old job and how awful it is.  It may project that you are a negative person.  Negative people will fail anywhere they go.  So make sure that you are positive, cheerful, and fun to be around.

Send a thank you note.  Even if the interviewer(s) throw your note in the trash, it gives your name visibility.  If you are lucky, it will leave a positive impression on you and may be the final straw to get you that job.

Bookmark and Share