Search code examples
javaandroidasynchronousreliabilityandroid-strictmode

Making Atom/RSS Reader Speed and Reliability


I recently did from the "Difficulty Reading with Atom Reader" question. Now, I'm figuring something about maximum compatibility for the blog app I made, from Android Froyo to Jellybean. The problem is that I got notified by errors while checking using StrictMode. I'm running Eclipse IDE via Windows 7 OS.

    //-----[ UI Thread Debug Setup ]-----
    if(DEVELOPER_MODE)
    {
        /*
         * 
         *             Manage main thread control for Android 3.0 and later. Not work on Android 2.3.3 and below, otherwise, you will get an error 
         *          for changing minimum SDK version at manifest. If you want to publish this project as an Android app (APK)  that  will  run  on 
         *          Android 3.0 or later, set DEVELOPER_MODE to "true", otherwise, will not work. (App for Boy Kuripot [Ver. 1])
         * 
         */

        StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().detectDiskReads().detectDiskWrites().detectAll().penaltyLog().build());
        StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder().detectLeakedSqlLiteObjects().detectLeakedClosableObjects().penaltyLog().penaltyDeath().build());
    }

Here's what happen if I set the minimum SDK version to 7 and you'll see the errors apeared in red line:

enter image description here

And here's what happen if I set the minimum SDK version to 11 via Android Manifest:

enter image description here

Also, when I run it using AsyncTask, it gets either slower, faster, or just lagging.

//TODO _________________________[ Activity Starter Subclass ]_________________________
private class Post_Task extends AsyncTask<String, Integer, String> // --> This class will be revised and to be used for next version. (Compatible now with Android 2.1 and later.)
{
    @Override
    protected void onPreExecute()
    {
        super.onPreExecute();
    }

    @Override
    protected String doInBackground(String... params) 
    {
        //-----[ RSS Feed Setup ]-----
        xp.Get_Parse_Feed(URL_link, is, lm.headlines, lm.links);

        return "All done!";
    }

    @Override
    protected void onProgressUpdate(Integer... values)
    {
        super.onProgressUpdate(values);
    }

    @Override
    protected void onPostExecute(String result)
    {
        super.onPostExecute(result);
    }
}

When I revert and run this xp.Get_Parse_Feed(URL_link, is, lm.headlines, lm.links); code at onCreate() as main thread, sometimes the links we're loaded properly in just a snap. The question is which one should I manage and how to make this blog app compatible with Android 2.1 and up?


Solution

  • Here's what happen if I set the minimum SDK version to 7 and you'll see the errors apeared in red line:

    That is happening because StrictMode was introduced in Gingerbread(API level 10) and you have a minimum SDK version of 7. In this case Lint is noticing you trough an error that you'll have problems(the app will crash) if you run the app on platforms below Gingerbread. When you set the minimum version to 11 the error will not happen as StrictMode is available for that API level and above.

    To keep the minimum SDK version of 7 either wrap the StrictMode code in an if condition so you only make it available when running the app on Gingerbread and above:

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) {
        // Strict mode available            
    }
    

    or you tell Lint to make it a warning and not an error when using classes from higher API levels. As you'll probably forget to remove the StrictMode reference when distributing your app, go with the first option.

    Also, when I run it using AsyncTask, it gets either slower, faster, or just lagging.

    What is getting slower or faster? If you want help you should explain much better what is happening when using the task, what is happening when moving the line in the onCreate method, any exception etc.