標籤:
/** Return the intent that started this activity. */
public Intent getIntent() {
return mIntent;
}
public void setIntent(Intent newIntent) {
mIntent = newIntent;
}
/** Return the application that owns this activity. */
public final Application getApplication() {
return mApplication;
}
/** Is this activity embedded inside of another activity? */
public final boolean isChild() {
return mParent != null;
}
/** Return the parent activity if this view is an embedded child. */
public final Activity getParent() {
return mParent;
}
/** Retrieve the window manager for showing custom windows. */
public WindowManager getWindowManager() {
return mWindowManager;
}
public Window getWindow() {
return mWindow;
}
/**
* Return the LoaderManager for this activity, creating it if needed.
*/
public LoaderManager getLoaderManager() {
if (mLoaderManager != null) {
return mLoaderManager;
}
mCheckedForLoaderManager = true;
mLoaderManager = getLoaderManager("(root)", mLoadersStarted, true);
return mLoaderManager;
}
LoaderManager : 首先是查詢資料的邏輯放在了UI產生的同個線程中,這個就意味著在查詢資料的時候,UI頁面產生的工作被阻塞住了。UI一旦被阻塞使用者就會被感知出來了,因此就會出現各種無相應頁面(Application Not Response),或者activity頁面延遲的現象,這對使用者體驗來說是不可接受的。
其次是在渲染頁面的時候需要固定需要進行一次資料查詢,但是這個是很不節省資源的。假如一個Activity從一個停止狀態回到前台,那麼這個時候儘管資料並沒有變化,但是也需要進行一次query操作。在浪費資源的同時也再次增加了頁面渲染失敗的風險。
還有就是當資料變化的時候如何通知頁面進行修改呢?這個時候往往就又要建立一個monitor的角色,來當資料來源變化的時候來讓頁面重新調用requery。
因此在Android的越來越提倡使用者體驗的今天,載入器和載入管理器(Loader,LoaderManager)就出現了。
Loader有什麼作用?1 在單獨的線程中讀取資料2 監視資料的更新
而LoaderManager就是載入器的管理器,一個LoaderManager可以管理一個或多個Loader,一個Activity或者Fragment只能有一個LoadManager。LoaderManager管理Loader的初始化,重啟和銷毀操作。
activiti 裡面各個方法理解