Guideline for your first (Android) mobile application

by adrian vintu 5/4/2010 7:56:00 PM
I've had multiple requests on information about developing an (Android) mobile application so I decided to add my tips in this guideline.
Please mind that these tips are general and may not apply to all situations.
  1. Do create an architecture as you were designing for the desktop applications (before you jump through the ceiling read #2)
    Use MVC, MVP, IoC, inheritance, composition, frameworks, third party tools, etc.
    You need to keep the code clean and extensible. Forget about performance issues. Chances are, by the time you finish your application, the hardware capabilities of the devices will double. You will need to easily maintain your code more than handle performance issues.
  2. Do bend/break the rules
    It's the opposite of #1. You need to make a choice between performance and code architecture. Try to isolate the modules that break the good architecture code. Do everything you need to get the best performance and usability, but, in the mean time, try to stick to rule #1.
  3. Speed up your application
    The Internet connection can be pretty slow. Cache your downloaded data for the next session.
    Create thumbnails for pictures.
    Use place holders in list items and load pictures on demand - when the list items are visible.
    Connect the lists directly to the data source. If you can't, then create lightweight objects for your list items.
    Store the history of the user activity - last internet searches, pictures, etc.
    Use StringBuffer. Use SpannableString.
    If you get a lot of configuration from an xml file on start up, consider serializing the information so that on the next start up you don't parse the xml but rather deserialize objects.
    Use lazy loading as much as possible.
    Profile your application. It will give you an inside view of how Android works and will provide you most valuable information on where the bottle necks reside. Prepare for surprises.
  4. Handle exceptions gracefully
    Consider using fall back, fail safe, fail recovery techniques.
    What we certainly do not want is for the application to crash or to show 'weird' exception messages to the user.
  5. Log and send exceptions
    Log exceptions and trace your application extensively but not to the point where it interferes with performance or usability.
    Add a button to easily send the logs to the developer.
  6. Test your application
    Design your application to be testable. Use TDD if possible or post coding testing. Make a test for each bug you fix.
    Test on as many real devices as possible - device fragmentation is a real problem.
    Use different configurations for the emulator - network speed, resolution, density, etc.
  7. Security and privacy
    Require as few permissions as possible. If your application is a book reader, do not ask permissions for reading the contacts. People are paranoid about their privacy - and they should be.
    Do not cache sensitive data, track users, modify or transfer user data without letting the user know and agree to the policy - you may get sued otherwise.
    Use encryption for sensitive data.
  8. Prepare your mindset for mobile usability
    Do not try to get the same look and feel for your desktop application as for your mobile one - ie. do not clone.
    Learn from the GUI of other mobile applications. Look at what is already available on the market. Steal (in the artistic meaning, not as copyright infringement) the ideas of the interfaces, customize them, make them better.
  9. Be consistent with the GUI
    Try to use the phone native controls. Chances are you will not have enough time to make better controls anyway. Use the built-in styles - the user can change themes and if you hardcode your styles your GUI may become unreadable.
    Do not use other phones' look and feel - like putting the LWUIT or Nokia look and feel on the Android. The majority of users know how to use an Android phone, but they will most likely get confused when presented with a new interface.
  10. Polish your application
    Make your application look great. Use nice icons. Make it user friendly. Make it fast.
    People are more likely to adhere to a 'shiny' application, even if there exists a similar one, that can do the same thing even better and faster, but which looks a little bit 'shabbier'.
  11. Make your application usable out of the box
    Assume reasonable defaults for the user settings. The user should not have to configure the application before using it.
    Consider making a dialog on first run of the application where the user can choose the language or other such important settings.
  12. Make your application aware of location
    Try to make your application look and feel aware of location: language, number decimal separators, default currency, etc.
  13. Publish your application only after it passes the 'maturity' test
    Users are very annoyed with beta versions. They will easily rate your application down. Only publish after you have fully tested and polished you applications. Use your friends as beta testers.
    NB mature means, in this context, the application that has passed the quality tests. It does not imply that it is the final version to be released, but rather a version that is good enough to be released.
  14. Add features in stages
    Publish the first version of your 'mature' application containing only the bear essential features. You will add extra features regularly, based on user feedback.
    Do not try to add too many features at once and miss deadlines or delay releases. Your users may get very impatient and upset.
    Remember the 80/20 rule.
  15. Respect your users
    They can be your best friends or your worst enemies. Listen to their requests. Answers their mails as soon as possible. In case of irritated users, you have to be the humble one. Learn patience. Learn to settle a debate before getting into a fight.
    If you meet special people that help you with your application then make sure to give them credit - maybe a thanks in the application About box or on the application website.
  16. Expect bad ratings
    You will probably get down-ratings, especially right after publishing your application for the first time. That's ok. It is normal. It happened to all of us. We improved our application and then we upped our rating back. Also see #15.
  17. Advertise/Market
    Tell people about your application. Search for people that would use you niche application. Post on niche forums and groups. Put your application up for reviews - there are specialized sites that do Android software reviews. Don't spam.
  18. Make a website for your application
    Make a web page for your application - add Description, Installation, Support and Troubleshooting sections.
    Don't be surprised that the majority of your users will actually not read your website. But for those who do, it will mean a sign of respect and professionalism.
  19. Subscribe to Android groups, forums and magazines
    Become part of the community. Learn from other peoples' mistakes. Help others.
    Learn what new features the new Android versions bring. Learn about the newest Android software. Learn what the market offers and needs.
    Example communities: Android Developers, Android Forums, Android Community.
  20. Publish your application on multiple markets
    Although publishing on multiple markets will make your releases more tiresome since you have to maintain multiple markets, you still need to do this because many users prefer other markets than the Google Android Market.
    Example markets: Android Market, AndAppStore, SlideME, AppsLib.

EDIT: If you are an Android programmer, you must check this link out http://adrianvintu.com/blogengine/post/Colored-Logcat-Script-for-Windows.aspx


The Infamous 'Something wrong here, didn't expect <package name> to be resumed' Warning

by adrian vintu 4/27/2010 1:16:00 PM

I've recently come across a weird situation using the Android emulator. I started getting the infamous warning 'Something wrong here, didn't expect <package name> to be resumed'.

I have created a most basic Android project to test this. It seems the warning only appears in the emulator, but not on my Samsung Galaxy Android 1.6 device.

Unfortunately, at this time, I have no clue why this happens. I will try to get more info from the forums and post it here.


EDIT: I found the solution, please scroll to the end of the article to see the answer.


My scenario is as follows:
  • Create simple Android project
  • Sole and simple main activity MainActivity.java
    																														
    	public class MainActivity extends Activity
    	{
    		@Override
    		public void onConfigurationChanged(Configuration newConfig)
    		{
    			Log.d(TAG, "onConfigurationChanged");
    			super.onConfigurationChanged(newConfig);
    		}
    		@Override
    		public void onCreate(Bundle savedInstanceState)
    		{
    			Log.d(TAG, "onCreate");
    			super.onCreate(savedInstanceState);
    		}
    		@Override
    		protected void onPause()
    		{
    			Log.d(TAG, "onPause");
    			super.onPause();
    		}
    		@Override
    		protected void onResume()
    		{
    			Log.d(TAG, "onResume");
    			// setContentView(R.layout.main);
    			super.onResume();
    		}
    		String	TAG	= "ROT";
    	}
    	
  • AndroidManifest.xml file
    																		
    	<?xml version="1.0" encoding="utf-8"?>
    	<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    	      package="test.rotation"
    	      android:versionCode="1"
    	      android:versionName="1.0">
    	    <application android:icon="@drawable/icon" android:label="@string/app_name">
    	        <activity android:name=".MainActivity"
    	                  android:label="@string/app_name">
    	            <intent-filter>
    	                <action android:name="android.intent.action.MAIN" />
    	                <category android:name="android.intent.category.LAUNCHER" />
    	            </intent-filter>
    	        </activity>
    	    </application>
    	    <uses-sdk android:minSdkVersion="3" />
    	</manifest>
    	
  • Install on emulator and rotate a few times (Numpad 7)
  • Logcat output
    																		
    	53           PackageParser   D  Scanning package: /data/app/vmdl28266.tmp
    	53           PackageParser   I  test.rotation: compat added android.permission.WRITE_EXTERNAL_STORAGE android.permission.READ_PHONE_STATE
    	53          PackageManager   I  /data/app/vmdl28266.tmp changed; unpacking
    	32                installd   D  DexInv: --- BEGIN '/data/app/vmdl28266.tmp' ---
    	507               dalvikvm   D  DexOpt: load 37ms, verify 9ms, opt 2ms
    	32                installd   D  DexInv: --- END '/data/app/vmdl28266.tmp' (success) ---
    	32                installd   I  move /data/dalvik-cache/data@app@vmdl28266.tmp@classes.dex -> /data/dalvik-cache/data@app@test.rotation.a
    	pk@classes.dex
    	53          PackageManager   D  New package installed in /data/app/test.rotation.apk
    	501         AndroidRuntime   D  Shutting down VM
    	501               dalvikvm   D  DestroyJavaVM waiting for non-daemon threads to exit
    	501               dalvikvm   D  DestroyJavaVM shutting VM down
    	501               dalvikvm   D  HeapWorker thread shutting down
    	501               dalvikvm   D  HeapWorker thread has shut down
    	501                   jdwp   D  JDWP shutting down net...
    	501               dalvikvm   I  Debugger has detached; object registry had 1 entries
    	501               dalvikvm   D  VM cleaning up
    	501         AndroidRuntime   E  ERROR: thread attach failed
    	501               dalvikvm   D  LinearAlloc 0x0 used 621260 of 5242880 (11%)
    	53                dalvikvm   D  GC freed 6097 objects / 401832 bytes in 201ms
    	53            ResourceType   W  Resources don't contain package for resource number 0x7f060000
    	53            ResourceType   W  Resources don't contain package for resource number 0x7f060001
    	512         AndroidRuntime   D
    	512         AndroidRuntime   D  >>>>>>>>>>>>>> AndroidRuntime START <<<<<<<<<<<<<<
    	512         AndroidRuntime   D  CheckJNI is ON
    	512         AndroidRuntime   D  --- registering native functions ---
    	512               ddm-heap   D  Got feature list request
    	53         ActivityManager   I  Starting activity: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x1
    	0000000 cmp=test.rotation/.MainActivity }
    	512         AndroidRuntime   D  Shutting down VM
    	512               dalvikvm   D  DestroyJavaVM waiting for non-daemon threads to exit
    	512               dalvikvm   D  DestroyJavaVM shutting VM down
    	512               dalvikvm   D  HeapWorker thread shutting down
    	512               dalvikvm   D  HeapWorker thread has shut down
    	512                   jdwp   D  JDWP shutting down net...
    	512               dalvikvm   I  Debugger has detached; object registry had 1 entries
    	512               dalvikvm   D  VM cleaning up
    	53         ActivityManager   I  Start proc test.rotation for activity test.rotation/.MainActivity: pid=518 uid=10037 gids={1015}
    	512         AndroidRuntime   E  ERROR: thread attach failed
    	512               dalvikvm   D  LinearAlloc 0x0 used 636716 of 5242880 (12%)
    	30                dalvikvm   D  GC freed 290 objects / 11064 bytes in 345ms
    	518               ddm-heap   D  Got feature list request
    	30                dalvikvm   D  GC freed 52 objects / 2288 bytes in 353ms
    	518                    ROT   D  onCreate
    	518                    ROT   D  onResume
    	30                dalvikvm   D  GC freed 2 objects / 56 bytes in 365ms
    	53         ActivityManager   I  Displayed activity test.rotation/.MainActivity: 1335 ms (total 1335 ms)
    	93                dalvikvm   D  GC freed 13515 objects / 683152 bytes in 115ms
    	53           WindowManager   I  Setting rotation to 1, animFlags=1
    	53         ActivityManager   I  Config changed: { scale=1.0 imsi=310/260 loc=de_DE touch=3 keys=2/1/1 nav=3/1 orien=2 layout=34}
    	518                    ROT   D  onPause
    	518                    ROT   D  onCreate
    	518                    ROT   D  onResume
    	53              UsageStats   W  Something wrong here, didn't expect test.rotation to be resumed
    	53         ActivityManager   I  Config changed: { scale=1.0 imsi=310/260 loc=de_DE touch=3 keys=2/1/2 nav=3/1 orien=2 layout=34}
    	53                dalvikvm   D  GC freed 3606 objects / 190280 bytes in 187ms
    	53           WindowManager   I  Setting rotation to 0, animFlags=0
    	518                    ROT   D  onPause
    	53              UsageStats   W  Something wrong here, didn't expect test.rotation to be resumed
    	518                    ROT   D  onCreate
    	518                    ROT   D  onResume
    	53         ActivityManager   I  Config changed: { scale=1.0 imsi=310/260 loc=de_DE touch=3 keys=2/1/2 nav=3/1 orien=1 layout=34}
    	53              UsageStats   W  Something wrong here, didn't expect test.rotation to be resumed
    	518                    ROT   D  onPause
    	518                    ROT   D  onCreate
    	518                    ROT   D  onResume
    	53                dalvikvm   D  GC freed 1820 objects / 91896 bytes in 94ms
    	518                    ROT   D  onPause
    	236               dalvikvm   D  GC freed 119 objects / 4664 bytes in 80ms
    	
  • Colored logcat output screen shot

  • On each rotation, this message appears: Something wrong here, didn't expect test.rotation to be resumed
  • This rotation message does not appear on the Samsung Galaxy Android 1.6 device
  • Emulator(Target Name = Android 2.0, Platform = 2.0, API level = 2.0) configuration is as follows in the picture below

  • Link to project is here TestRotation.zip (40 KB)


EDIT: The gurus on the Google Android-Developers group have helped me with this issue. It seems there is nothing to worry about. I will copy/paste some answers.

Mark Murphy: The solution appears to be: ignore the message. Other apps, such as the built-in Launcher (home screen), Calculator, Contacts, and Music apps exhibit the same behavior.

Dianne Hackborn: Sorry yes the message is just some code in the system that gets out of sync (and at that point is fixing itself). It is nothing to worry about.

The link to the android-developers group post is this http://groups.google.com/group/android-developers/browse_thread/thread/9ead1c255898e099?hl=en


EDIT 2: If you are getting recurring "Something wrong here..." messages and your application keeps restarting then please check out the article at http://adrianvintu.com/blogengine/post/Force-Locale-on-Android.aspx


EDIT 3: You may also try this link for some more info http://stackoverflow.com/questions/2174865/something-wrong-here-didnt-expect-package-to-be-resumed-error-in-andorid-logc

Comparison of Android vs iPhone vs Nokia vs BlackBerry vs Windows Mobile 7

by adrian vintu 4/13/2010 8:29:00 PM

I have previously published an Android vs IPhone comparison and many people requested that I do a comparison of Android vs iPhone vs Nokia vs BlackBerry vs Windows Mobile 7. So here goes.

Android

  • open platform http://source.android.com
  • can compile custom firmwares - good for hackers and other
  • good framework, extended on each new firmware
  • supports multitasking
  • nice IDE - Eclipse, NetBeans
  • development SDK is free
  • easy to debug, can send logs to developers
  • programming language is Java but bridges from other languages exist (C# .net - Mono, etc)
  • Java is a high level language that appeared in 1995. Android supports Java 1.5 and translates the byte code to its own custom Dalvik byte code optimized for mobile devices.
  • for the hardcore programmers, Android offers the possibility of programming in C using the native dev kit NDK
  • can run script languages like LUA, Perl, Python, etc
  • can install third party applications from sdcard, random sites - not locked to a specific market
  • applications can hook and override everything - email interface, SMS sending, custom keyboards, etc
  • supports widgets
  • can publish applications on the Android market instantly - initial one time registration fee is 25E
  • user has access to the sdcard and can use it as a USB disk
  • no Adobe Flash support yet. Probably will be available in Q2 of this year.

iPhone

  • closed platform
  • no multitasking except for some Apple applications. multitasking is probably going to be introduced in the next vertion of the iPhone, the iPhone 4
  • development kit costs ~90E
  • More...

Nokia 6131 NFC and 6212 NFC crash and reset the phone

by adrian vintu 4/12/2010 7:15:00 PM

I found a very annoying "bug" on the Nokia 6212 NFC and Nokia 6131 NFC.

I was building an obfuscated MIDlet when all of a sudden it started crashing on the NFC phones mentioned above. The 6212 and 6131 were crashing before starting the application, so it got me thinking that it might be a verification issue.The crash was followed by a warm reset of the phone and after 4 consecutive crashes by a cold reset of the phone.

I tested in the emulator and everything was fine. I tested on other phones and again, no problem.

I tried to exclude classes from the build that I thought were not verified correctly but I had to give up because of the huge number of classes ~approx 500.

I removed the code requiring permissions and signed the MIDlet. Still no luck.

I started looking at the SVN, since I knew the application was previously working. I noticed something. The icon.png of the MIDlet used to be 24 bits of color and now it was 32 bits. Somebody has changed the icon. I knew the Nokia 6131 NFC and 6212 NFC don't support such a high image depth so I rolled back the icon to 24 bits. TADAAA, I was now able to successfully obfuscate and run the application on the NFC phones.

This has been a really annoying and difficult to spot bug.

Interesting facts:

More...

User Dictionary Manager for Android (UDM)

by adrian vintu 3/3/2010 11:13:00 PM

Today I released another Android application.
User Dictionary Manager for Android is an application that allows you to export/import/delete/clean the user dictionary words found on your Android phone.
This special version also includes a built in list of approx 2000 most used words/expressions in the Romanian language.
I hope you will enjoy the application as much as I am and will take advantage of this useful tool.
The User Dictionary Manager for Android home page is http://udm.adrianvintu.com

EDIT: If you are an Android programmer, you must check this link out http://adrianvintu.com/blogengine/post/Colored-Logcat-Script-for-Windows.aspx

Screen shots


More...

Force Locale on Android

by adrian vintu 1/14/2010 8:51:00 PM
While playing with localization on the Android for my app I came upon an annoying bug.
It seems running on Motorola Milestone the fonts were getting smaller on each locale update.

I use the following code for locale changing (from http://almondmendoza.com/2009/01/28/force-localize-an-application-on-android/):
String languageToLoad  = "de";
Locale locale = new Locale(languageToLoad);
Locale.setDefault(locale);
Configuration config = new Configuration();
config.locale = locale;
getBaseContext().getResources().updateConfiguration(config, getBaseContext().getResources().getDisplayMetrics());
Also in the AndroidManifest.xml I have (without this entry you get "Something wrong here, didn't expect "mypackagename" to be resumed"):
<activity
  android:label="@string/app_name"
  android:name=".Dex"
  android:configChanges="locale">
Here is how my screen should look like:



And here is how it was looking on Motorola Milestone.



After changing the Locale from Preferences the fonts keep gettting smaller and smaller



This was very annoying. I did not know exactly why this was happening.
More...

Comparison of Android vs IPhone

by adrian vintu 1/14/2010 7:22:00 PM
Today I made a comparison of Android vs IPhone. I made the list together with an IPhone enthusiast. The results were surprising for both of us. If fact, they were so surprising that the IPhone user is now inclined to go for the Android on the next phone purchase.
Here is the comparison of Android vs IPhone.

Pros for Android
  1. SMS delivery report - for the IPhone you need a third party apparently
  2. notifications without INTERNET - one of the biggest drawback of the IPhone is that you cannot have notifications without Internet -> the notifications are stored on the Apple servers
  3. can install applications from any site - IPhone applications can only be installed from the Apple store (unless the phone is jail broken)
  4. multiple physical menu buttons - used for navigation and quick shortcuts, allows greater screen size (no more software menus)
  5. physical menu button allows recent 6 tasks (like ALT+TAB in Windows) - absolutely useful
  6. the Home screen is organized in 3, 4 or 5 virtual screens, the rest of the applications lie in a list - usability, quick to access most used apps - on the IPhone there are "limitless" virtual screens on Home
  7. can install on the Home screen - widgets, shortcuts, folders
  8. physical keyboard - on some models
  9. open source OS
  10. can install different/homebrewed firmwares
  11. can install home brewed apps
  12. background apps/ multitasking
  13. can make own application to hook into anything - calling, traffic, media, encryption, etc
  14. dev SDK is free and cross platform. IPhone is for $100+ and only works on MAC.
  15. programming is done in Java, bridges exist from J2ME, C#, etc. IPhone uses Objective C
  16. programming - can run interpreters. IPhone only allows running Objective C byte code
  17. easy access to the SD card (both from computer and from the phone). can copy MP3s, read ebooks, etc
  18. cheaper than the IPhone
  19. easy removable/replaceable battery.
  20. 5 mega pixel camera + blitz/flash
Pros for IPhone
  1. screen brightness/clarity
  2. bigger sofware keyboard - because of the wider screen
  3. great 3D apps and harware
  4. easy data synchronization
  5. proximity sensor - saves battery and "locks" the screen
  6. zoom using two fingers - pictures, browser, etc - though some Android phones also support multi touch

EDIT: An update comparison of Android vs iPhone vs Nokia vs BlackBerry vs Windows Mobile 7 is avalilable here http://adrianvintu.com/blogengine/post/Comparison-of-Android-vs-IPhone-vs-Nokia-vs-BlackBerry-vs-Windows-Mobile-7.aspx

About Adrian Vintu

Adrian Vintu I am a computer software professional lately designing and programming .NET and Android applications.
Send mail

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2008 - 2010

Sign in