Skip to content

Commit

Permalink
处理编译异常.
Browse files Browse the repository at this point in the history
  • Loading branch information
kifile committed Dec 1, 2015
1 parent df93bc9 commit b6ae2e1
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,6 @@ public abstract class AbstractDataProvider<DATA> implements DataProvider<DATA> {
// 由于数据加载需要通过异步线程调用,因此在此处创建一个静态的Handler,专门负责主线程通信。
protected static Handler sHandler = new Handler();

private final Runnable mRefreshTask = new Runnable() {
@Override
public void run() {
if (mFetcher != null) {
setData(mFetcher.fetch());
}
}
};

/**
* When you extends AbstractDataProvider, don't make the constructor having any argument.
* <p/>
Expand Down Expand Up @@ -85,9 +76,22 @@ public void registerDataObserver(final DataObserver<DATA> observer) {
@Override
public void refresh() {
if (mIsAsync) {
executeFetchTask(mRefreshTask);
executeFetchTask(new Runnable() {
@Override
public void run() {
try {
setData(mFetcher.fetch());
} catch (Exception e) {
handleException(e);
}
}
});
} else {
mRefreshTask.run();
try {
setData(mFetcher.fetch());
} catch (Exception e) {
handleException(e);
}
}
}

Expand Down Expand Up @@ -144,6 +148,10 @@ public void release() {
mData = null;
}

protected void handleException(Exception e) {
e.printStackTrace();
}

/**
* Check if it is running on main thread, keep thread-safe.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,21 @@ public void loadPage(final int page) {
@Override
public void run() {
if (mFetcher != null) {
setPageData(page, mFetcher.fetch());
try {
setPageData(page, mFetcher.fetch());
} catch (Exception e) {
handleException(e);
}
}
}
});
} else {
if (mFetcher != null) {
setPageData(page, mFetcher.fetch());
try {
setPageData(page, mFetcher.fetch());
} catch (Exception e) {
handleException(e);
}
}
}
}
Expand Down

0 comments on commit b6ae2e1

Please sign in to comment.