Your app crashes, live with it.


Let’s say that you are a developer that actually cares about the quality of his applications, yes, you belong to the 1%, so you are using BugSense to catch all the exceptions and you get something like this:

Full Stacktrace
0 android.database.sqlite.SQLiteDiskIOException: error code 10: disk I/O error
1 at android.database.sqlite.SQLiteStatement.native_execute(Native Method)
2 at android.database.sqlite.SQLiteStatement.execute(SQLiteStatement.java:55)
3 at android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:1881)
4 at android.webkit.WebViewDatabase.removeCache(WebViewDatabase.java:668)
5 at android.webkit.CacheManager.createCacheFile(CacheManager.java:430)
6 at android.webkit.WebViewWorker.handleMessage(WebViewWorker.java:134)
7 at android.os.Handler.dispatchMessage(Handler.java:99)
8 at android.os.Looper.loop(Looper.java:123)
9 at android.os.HandlerThread.run(HandlerThread.java:60)

You’re trying to figure out what is happening, how can this be your fault, especially when you are absolutely sure that you are not using SQLite in your project!
Well, I have good news for you, it’s not your fault, but then again I have bad news for you, even if you have done serious testing, shit happens and your application is going to crash, no matter what. And I mean it. It is going to crash. Even Gmail or Facebook crashes!

Trying to catch every possibility or corner case may lead to a large and complicated source code, leading to even more crashes. General exception handling on the other side will make your application slow, so make sure you keep the balance on this.

You cannot predict what the user will do, you cannot predict the behavior of the devices out there and allow me to make it more clear with 2 examples:

The Huawei IDEOS X5 constantly crashes with random Resources NotFound Exceptions.
The Sony Ericsson X10 mini simply does not run apps, they do not even start sometimes.

The list goes on and you must accept that your application will crash, what you can do is minimize the crashes that are your fault.

Your app crashes, live with it.

(Image from Wired.com)

Share

How to sort RSS by date

So, if you’ve got one or more RSS feeds and you want to sort them according to the pubdate, do this:

Collections.sort(myFeedsList, new Comparator<RssItemModel>() {

            @Override
            public int compare(RssItemModel lhs, RssItemModel rhs) {
                SimpleDateFormat formatter = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz");
                try {
                    Date date1 = formatter.parse(rhs.getPubDate());
                    Date date2 = formatter.parse(lhs.getPubDate());
                    return date1.compareTo(date2);
                } catch (ParseException e) {
                    e.printStackTrace();
                }
                return 0;
            }
        });
Share

Check if device has Android Market

Although the majority of the Android powered devices have the Android Market installed, there are a lot of devices that are running Android but haven’t passed the Compatibility Test Suite (CTS) because they do not comply with the Android Compatibility Definition Document (CDD). (more info here). These device may have high quality hardware and software but they haven’t the Android Market installed.

In my personal experience, these devices may lead to a large number of problems.
The easiest way to determine if a device has the Android Market installed (and has passed the CTS) is via the following method:

public static boolean hasMarket(Context ctx) {
        Intent market = new Intent(Intent.ACTION_VIEW, Uri.parse("market://search?q=test"));
        PackageManager manager = ctx.getPackageManager();
        List<ResolveInfo> list = manager.queryIntentActivities(market, 0);
        for (ResolveInfo info : list)
        {
            if (info.activityInfo.packageName.startsWith("com.android."))
                return true;
        }

        return false;
    }

You may wonder why we check the package name. The answer is simple: There can be a lot of applications that can handle the “market://” view intent such as SlideMe.

Share

Presenting BugSense at Droidcon 2011

Great news, I will presenting BugSense at Droidcon 2011!

I really love the short bio:

Konstantinos is one of the earliest Android developers and evangelists of the platform in Greece. He has developed for leading enterprises and startups like Taxibeat. He also loves to hack with his friends at BugSense making sure that he delivers apps that do not suck. He is also leading the greek Android community.

It seems to be a very good conference, check out the speakers!

Share