android-loader

Accessing a Loader created in one fragment from another fragment

£可爱£侵袭症+ 提交于 2019-12-04 15:44:34
I have an app with a fairly standard fragment layout. An expandable listview fragment on the left and a panel on the right that is used for different things depending on what the user chooses to do with the list on the left (displaying data, adding new data, etc). I'm using the LoaderManager (first time using loaders) with CommonWare's loaderex library as I have no need or desire to create a Content Provider for my database just so I can use a standard CursorLoader. This setup works great for displaying my list. The issue I am having is when I use the second fragment to add data to the

What is the advantage of loaders over Asynctask in Android?

萝らか妹 提交于 2019-12-04 02:52:11
Are there any advantages of Loaders over Async task? Also, how to make loaders compatible for phones with Android froyo. Edit: The primary problem here is that I'm not using the native DB(SqlLite). Using the DB on development server. Obviously, I can't use CursorLoader any more. AsyncTaskLoader has no examples at all. If any, please do link. Is it a better idea to load the data required onto the local DB and then query it using CursorLoader ? Yes, Loaders are more advantageous than AsyncTask as they take care of a lot of things that AsyncTask falls short of, miserably. Screen Orientation

Proper notification of AsyncTaskLoader about data changes from background thread

微笑、不失礼 提交于 2019-12-03 15:47:47
I want to implement AsyncTaskLoader for my custom data source: public class DataSource { public interface DataSourceObserver { void onDataChanged(); } ... } DataSource will keep list of registered observers and will notify them about changes. CustomLoader will implement DataSourceObserver . The question is how to properly notify CustomLoader since Loader.onContentChanged() must be called from UI thread but in my case DataSource operations (and calls to DataSourceObserver.onDataChanged() ) will be done from background threads. Updated with idea from Selvin tip : public class CustomLoader

onResume() not called on ViewPager fragment when using custom Loader

流过昼夜 提交于 2019-12-03 13:42:28
问题 Short version: I have a fragment that maintains a ViewPager for displaying two other fragments, let's call them FragmentOne and FragmentTwo . When starting the app FragmentOne is visible and FragmentTwo is off-screen, becoming visible only as one swipes the view to the left. Normally onStart() and onResume() get invoked immediately for both fragments as soon as the app gets started. The problem I have is when FragmentOne starts a custom Loader then onResume() does not get called on

Will LoaderManager.restartLoader() always result in a call to onCreateLoader()?

心已入冬 提交于 2019-12-03 08:58:21
问题 LoaderManager has this method restartLoader(): public abstract Loader<D> restartLoader (int id, Bundle args, LoaderCallbacks<D> callback) Starts a new or restarts an existing Loader in this manager, registers the callbacks to it, and (if the activity/fragment is currently started) starts loading it. If a loader with the same id has previously been started it will automatically be destroyed when the new loader completes its work. The callback will be delivered before the old loader is

Is using AsyncTask still recommended for loading listView items in the background?

狂风中的少年 提交于 2019-12-03 07:33:14
Background I've heard that there are some new solutions for loading data in the background which are more recommended than AsyncTask (like loaders ). The problem AsyncTasks are great and easy to use. However, it has some limitations: The class itself has to be modified since it's limited by the number of pending tasks (about 256 or so). Of course, in a listView's adapter, I always cancel a task if it's not needed(for example when I need to update a view that was used for a different item). I also have to cancel them all (or handle in a different way) when the activity/fragment is being re

AsyncTaskLoader onLoadFinished with a pending task and config change

混江龙づ霸主 提交于 2019-12-03 06:45:55
问题 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.

Can Honeycomb Loaders solve problems with AsyncTask + UI update?

你说的曾经没有我的故事 提交于 2019-12-03 06:01:23
问题 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

onResume() not called on ViewPager fragment when using custom Loader

此生再无相见时 提交于 2019-12-03 04:43:12
Short version: I have a fragment that maintains a ViewPager for displaying two other fragments, let's call them FragmentOne and FragmentTwo . When starting the app FragmentOne is visible and FragmentTwo is off-screen, becoming visible only as one swipes the view to the left. Normally onStart() and onResume() get invoked immediately for both fragments as soon as the app gets started. The problem I have is when FragmentOne starts a custom Loader then onResume() does not get called on FragmentTwo until it becomes fully visible. Questions: Is this a problem with my code or a bug in the Android

Loaders in Android Honeycomb

心不动则不痛 提交于 2019-12-03 03:37:52
问题 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