Saturday, February 25, 2012

Android Findings

onConfigurationChanged - orientation change
Having "android:configChanges="orientation|keyboard" in manifest reloads the android activity on orientation change.
Instead the correct property is
"android:configChanges="orientation|keyboardHidden".

addJavascriptInterface - webview & javascript
When passing argument from javascript to android, pass it as string. Now if you want to convert the passed string to Integer or Long, the do not use Integer.getInteger instead use Integer.valueOf, that is, use valueOf.

Java Math.ceil with Integers
If your try to do some thing like
Integer a=1;
Integer b=5;
Integer c=0;
c=(int)Math.ceil(a/b);
You will get only 0;
Instead do something like
Integer a=1;
Integer b=5;
Integer c=0;
c=(int)Math.ceil((a * 1.0)/b);
So that you will get 1.

cursor.close() - Right place to close the sqlite cursor
Don't
if(cursor.getCount() > 0)
{
 cursor.close();
}
Do
if(cursor.getCount() > 0)
{

}
cursor.close();
Reference:https://groups.google.com/group/android-developers/browse_thread/thread/706258dfb7cbee1d

No comments: