Friday, August 29, 2014

Is 24 Hour date format in Android using java code.

private boolean is24HourFormat(Context context) {
   Locale locale = Locale.getDefault();
   java.text.DateFormat natural =
                java.text.DateFormat.getTimeInstance(java.text.DateFormat.LONG, locale);
   String value = "";
   if (natural instanceof SimpleDateFormat) {
            SimpleDateFormat sdf = (SimpleDateFormat) natural;
            String pattern = sdf.toPattern();
            if (pattern.indexOf('H') >= 0) {
                value = "24";
            } else {
                value = "12";
            }
        } else {
            value = "12";
        }
 
        return value.equals("24");
    }

Thursday, August 14, 2014

dalvikvm: DexOpt: source file mod time mismatch

Today, When I was running my app, I started to see this error

dalvikvm: DexOpt: source file mod time mismatch
dalvikvm: Cached DEX 'aaaa.zip' (/data/dalvik-cache/aaaa.zip@classes.dex) is stale and not writable
After Googling this error I could not found anything useful. Then I took a look at the /data/dalvik-cache/. There was a aaaa.zip@classes.dex already in this folder even the application was not installed. So I removed the existing file and did a new installation. all worked fine. 

I have not seen this error in previous versions of Android (below 4.4.2) . If you are going to launch a new pre-compiled zip make sure to remove previously cached files in /data/dalvik-cache/


Thursday, August 7, 2014

NullPointerException when new PhoneStateListener

When I new PhoneStateListener() I am getting this error

java.lang.NullPointerException
  at android.os.Handler.<init>(Handler.java:229)
  at android.os.Handler.<init>(Handler.java:137)
  at android.telephony.PhoneStateListener$2.<init>(PhoneStateListener.java:420)
  at android.telephony.PhoneStateListener.<init>(PhoneStateListener.java:420)

I looked at the Handler.java:. I believe the reason for this error is mQueue = looper.mQueue; so looper is null.  Only way to fix this problem is to call Looper.prepareMainLooper(); at the beginning of the process