編輯:關於Android編程
在使用AsyncTaskLoader時,當手機解鎖後,會重復加載數據,代碼如下:
static class CouponShopQueryLoader extends AsyncTaskLoader> { private int couponId; public CouponShopQueryLoader(Context context, int couponId) { super(context); this.couponId = couponId; } @Override protected void onStartLoading() { forceLoad(); } @Override public List
loadInBackground() { //查詢數據加載 } }
static class CouponShopQueryLoader2 extends AsyncTaskLoader修改後,重復加載的現象解決了,究其原因是沒有重寫> { private List
mData; private int couponId; public CouponShopQueryLoader2(Context context, int couponId) { super(context); this.couponId = couponId; } // final ForceLoadContentObserver mObserver; /* Runs on a worker thread */ @Override public List loadInBackground() { mData = ds.queryShopByCoupon(couponId, pageNo, PAGE_SIZE); return mData; } /* Runs on the UI thread */ @Override public void deliverResult(List data) { if (isReset()) { return; } if (isStarted()) { super.deliverResult(data); } } /** * Starts an asynchronous load of the contacts list data. When the * result is ready the callbacks will be called on the UI thread. If a * previous load has been completed and is still valid the result may be * passed to the callbacks immediately. * * Must be called from the UI thread */ @Override protected void onStartLoading() { if (mData != null) { deliverResult(mData); } if (takeContentChanged() || mData == null) { forceLoad(); } } /** * Must be called from the UI thread */ @Override protected void onStopLoading() { Log.d(sss, onStopLoading); // Attempt to cancel the current load task if possible. cancelLoad(); } @Override public void onCanceled(List cursor) { Log.d(sss, onCanceled); } @Override protected void onReset() { super.onReset(); Log.d(sss, onReset); // Ensure the loader is stopped onStopLoading(); mData = null; } }
/** * Must be called from the UI thread */ @Override protected void onStopLoading() { Log.d(sss, onStopLoading); // Attempt to cancel the current load task if possible. cancelLoad(); }
cardView:添加依賴:在Studio搜索cardview即可 在V7包中或者直接在gradle中添加compile 'com.android.support
本文實例為大家分享了Android Chronometer計時器基本使用方法,供大家參考,具體內容如下在默認情況下,Chronometer組件只輸出MM:SS或H:MM:
作為一名Android開發人員,相信大家對圖片OOM的問題已經耳熟能詳了,關於圖片緩存和解決OOM的開源項目也是相當的多,被大家熟知的就是Un
實現的效果,是一個滾動的公告欄,是這樣的:可以看到這個公告欄一方面是滾動,另外一方面是可點擊。實現的思路:1.textView放在ViewFlipper中實現滑動效果(可