android-loader

AsyncTaskLoader onLoadFinished with a pending task and config change

戏子无情 提交于 2019-12-02 20:24:29
I'm trying to use an AsyncTaskLoader to load data in the background to populate a detail view in response to a list item being chosen. I've gotten it mostly working but I'm still having one issue. If I choose a second item in the list and then rotate the device before the load for the first selected item has completed , then the onLoadFinished() call is reporting to the activity being stopped rather than the new activity. This works fine when choosing just a single item and then rotating. Here is the code I'm using. Activity: public final class DemoActivity extends Activity implements

Can Honeycomb Loaders solve problems with AsyncTask + UI update?

泄露秘密 提交于 2019-12-02 19:29:47
Doing something in background and then updating UI is very hard to implement correctly in Android. It's simply badly designed. Typical example is an AsyncTask that fetches something from the web and displays the result. There are 2 problems with this: The AsyncTask has a reference to Activity (because it needs to update its UI). After screen orientation change, the Activity is restarted. But the AsyncTask still references to the old destroyed Activity therefore it can't update the UI of the new Activity. This can lead to OutOfMemoryException. Imagine that you have an Activity with lots of

Loaders in Android Honeycomb

有些话、适合烂在心里 提交于 2019-12-02 17:17:23
I'm trying to figure out how to use Loaders in Android 3.0 but can't seem to get it to work. The docs only describe using CursorLoader but I'm using AsyncTaskLoader . From the docs it seems that you should only need to implement AsyncTaskLoader.loadInBackground() but it never gets called after getLoaderManager().initLoader() and then creating the loader in the callback. I can see debug messages saying Created new loader LoaderInfo{4040a828 #0 : ArticleDataLoader{4036b350}} so it seems like it is created successfully. Is it possible that loaders are currently broken in the SDK or is there some

Inserting records via Loaders in android

谁都会走 提交于 2019-12-02 03:46:10
问题 This question would be a follow up from the one asked Content Resolver vs Cursor Loader Where the answer clearly states how to insert records into a sqlite Db using a Content Resolver . My question is the following : Can i use a loader(Normal Loader) to implement this functionality ? eg : public Loader<Cursor> onCreateLoader(int id, Bundle bundle) { switch (id) { case AppConstants.LOADER_ADD_FAV_PHONE_NUM: ContentValues values = new ContentValues(); values.put(DBHelper.TM_DB_COLUMN_PHONE

Inserting records via Loaders in android

别等时光非礼了梦想. 提交于 2019-12-02 01:39:58
This question would be a follow up from the one asked Content Resolver vs Cursor Loader Where the answer clearly states how to insert records into a sqlite Db using a Content Resolver . My question is the following : Can i use a loader(Normal Loader) to implement this functionality ? eg : public Loader<Cursor> onCreateLoader(int id, Bundle bundle) { switch (id) { case AppConstants.LOADER_ADD_FAV_PHONE_NUM: ContentValues values = new ContentValues(); values.put(DBHelper.TM_DB_COLUMN_PHONE_NUMBER, directionOrder); values.put(TransitMeDBHelper.TM_DB_COLUMN_NAME_ID, selectionArgs[0]); Uri

LoaderManager with multiple loaders: how to get the right cursorloader

China☆狼群 提交于 2019-11-30 06:09:26
问题 To me it's not clear how to get the right cursor if you have multiple Loaders. Lets say you define two different Loader with: getLoaderManager().initLoader(0,null,this); getLoaderManager().initLoader(1,null,this); then in onCreateLoader() you do different things depending on the id: @Override public Loader<Cursor> onCreateLoader(int id, Bundle arg1) { if (id==0){ CursorLoader loader = new CursorLoader(getActivity(), MaterialContentProvider.CONTENT_URI,null,null,null,null); }else{ CursorLoader

Why is onLoadFinished called again after fragment resumed?

≡放荡痞女 提交于 2019-11-29 07:45:07
问题 I have a peculiar issue with Loaders. Currently I am unsure if this is a bug in my code or I misunderstand loaders. The app The issue arises with conversations (imagine something similar to Whatsapp). The loaders I use are implemented based on the AsyncTaskLoader example. I am using the support library. In OnCreate, I start a loader to retrieve cached messages. When the CachedMessageLoader finishes, it starts a RefreshLoader to retrieve (online) the newest messages. Each loader type as a

LoaderManager with multiple loaders: how to get the right cursorloader

喜欢而已 提交于 2019-11-28 15:11:11
To me it's not clear how to get the right cursor if you have multiple Loaders. Lets say you define two different Loader with: getLoaderManager().initLoader(0,null,this); getLoaderManager().initLoader(1,null,this); then in onCreateLoader() you do different things depending on the id: @Override public Loader<Cursor> onCreateLoader(int id, Bundle arg1) { if (id==0){ CursorLoader loader = new CursorLoader(getActivity(), MaterialContentProvider.CONTENT_URI,null,null,null,null); }else{ CursorLoader loader = new CursorLoader(getActivity(), CustomerContentProvider.CONTENT_URI,null,null,null,null); };