[英]Making Atom/RSS Reader Speed and Reliability
我最近做了“ Atom Reader的閱讀困難 ”問題。 現在,我正在考慮有關我制作的博客應用程序(從Android Froyo到Jellybean)的最大兼容性的問題。 問題是我在使用StrictMode進行檢查時收到錯誤通知。 我正在通過Windows 7 OS運行Eclipse IDE。
//-----[ 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,這會發生什么,您將看到紅線顯示的錯誤:
如果通過Android Manifest將最低SDK版本設置為11,就會發生以下情況:
另外,當我使用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);
}
}
當我還原並運行此xp.Get_Parse_Feed(URL_link, is, lm.headlines, lm.links);
onCreate()上的代碼作為主線程,有時我們可以很快地正確加載鏈接。 問題是我應該管理哪一個,以及如何使此博客應用程序與Android 2.1及更高版本兼容?
如果將最低SDK版本設置為7,這會發生什么,您將看到紅線顯示的錯誤:
發生這種情況的原因是Gingerbread(API級別10)引入了StrictMode
,並且您的SDK版本最低為7。在這種情況下, Lint
會提示您如果遇到以下錯誤就會遇到問題(應用程序將崩潰):姜餅以下平台上的應用程序。 當您將最低版本設置為11時,不會發生錯誤,因為StrictMode
可用於該API級別及更高級別。
要保持7的最低SDK版本,請將StrictMode
代碼包裝為if
條件,以便僅在Gingerbread及更高版本上運行該應用程序時使它可用:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) {
// Strict mode available
}
或者您告訴Lint
在使用更高API級別的類時將其警告而不是錯誤。 由於您可能會忘記在分發應用程序時刪除StrictMode
參考,請選擇第一個選項。
另外,當我使用AsyncTask運行它時,它會變慢,變快或滯后。
什么變得越來越慢? 如果你想幫助你應該解釋好得多什么用任務時發生的,什么是朝着線的時候發生onCreate
方法,任何異常等。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.