2013-02-23 55 views
0

我最近从“Difficulty Reading with Atom Reader”的问题做过。现在,我正在计划一些关于我从Android Froyo到Jellybean创建的博客应用的最大兼容性。问题是我在使用StrictMode进行检查时收到错误通知。我通过Windows 7 OS运行Eclipse IDE。制作Atom/RSS阅读器速度与可靠性

//-----[ 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()); 
    } 

这里是发生什么事,如果我设定的最低SDK版本7,你会看到一个错误的红线apeared:

enter image description here

下面是发生什么事,如果我设定的最低SDK通过Android清单版本以11:

enter image description here

此外,当我运行它使用AsyncTask,它变得更慢,更快,或者仅仅滞后。

//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); 
    } 
} 

当我恢复,并在的onCreate()作为主线程运行此xp.Get_Parse_Feed(URL_link, is, lm.headlines, lm.links);代码,有时我们在短短的瞬间正确加载的链接。问题是我应该管理哪一个以及如何使这个博客应用程序与Android 2.1兼容?

回答

0

这里是发生什么事,如果我设定的最低SDK版本7,你会 看到错误的红线apeared:

因为StrictMode在姜饼(API级别10中引入正在发生),并且您的SDK版本最低为7.在这种情况下,如果您在Gingerbread下的平台上运行应用程序,则Lint会注意到您会遇到问题(应用程序将崩溃)。当您将最低版本设置为11时,错误不会发生,因为StrictMode可用于该API级别及以上。

为了保持7的最低SDK版本无论是包裹StrictMode代码在if条件,所以你只有让它运行在姜饼及以上的应用程序时,可供选择:

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

,或者你告诉Lint使它在使用更高API级别的课程时发出警告而不是错误。由于您在发布应用程序时可能会忘记删除StrictMode参考,请使用第一个选项。

另外,当我使用AsyncTask运行它时,它会变得更慢,更快,或者仅仅滞后。

什么变得越来越慢? 如果你需要帮助,你应该解释很多更好使用任务时发生了什么,在onCreate方法中移动行时发生了什么,任何异常等