android-loadermanager

android - CursorLoader & SQLite without Content Provider

六月ゝ 毕业季﹏ 提交于 2019-11-26 18:48:57
问题 I know this has been discussed yet I wanted to ask about the current state of the matter. Do i have to create a ContentProvider to use CursorLoader in connection with a sqlite database? I found CursorLoader usage without ContentProvider Looks exactly what I was hoping for yet as Emmby commented Users should be aware of one limitation, which is that it has no mechanism to refresh on data changes (as Loaders are supposed to do) So another solution is mentioned https://github.com/commonsguy/cwac

AsyncTaskLoader vs AsyncTask

喜你入骨 提交于 2019-11-26 18:12:38
Since Honeycomb and the v4 Compatibility Library it is possible to use AsyncTaskLoader . From what I understand, the AsyncTaskLoader can survive through config changes like screen flips. Is it recommended to use AsyncTaskLoader instead of AsyncTask ? Does LoaderManager get in the picture too? But I haven't found any good example(s) about how to correctly use the AsyncTaskLoader . The docs also provide no examples. Can anyone provide some good examples. You can have a look at the compatibility library's source code to get more info. What a FragmentActivity does is: keep a list of LoaderManager

Initializing a Loader in an Activity

安稳与你 提交于 2019-11-26 16:13:22
问题 I am currently trying to learn how to use Loaders and am having trouble starting a Loader in my activity. import android.support.v4.app.LoaderManager; import android.support.v4.content.Loader; public class ASwitchActivity extends Activity implements LoaderManager.LoaderCallbacks<SampleLoader.SampleLoaderResult> { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); getLoaderManager().initLoader(0, null, this); } public Loader

Is it OK to have one instance of SQLiteOpenHelper shared by all Activities in an Android application?

泄露秘密 提交于 2019-11-26 11:55:43
问题 Would it be OK to have a single instance of SQLiteOpenHelper as a member of a subclassed Application, and have all Activities that need an instance of SQLiteDatabase get it from the one helper? 回答1: Having a single SQLiteOpenHelper instance can help in threading cases. Since all threads would share the common SQLiteDatabase , synchronization of operations is provided. However, I wouldn't make a subclass of Application . Just have a static data member that is your SQLiteOpenHelper . Both

AlphabetIndexer with Custom Adapter managed by LoaderManager

╄→尐↘猪︶ㄣ 提交于 2019-11-26 11:23:19
I am trying to implement AlphabetIndexer with Custom Adapter like this AlphabetIndexer with Custom Adapter My class ContactsCursorAdapter extends SimpleCursorAdapter and implements SectionIndexer and I am using a LoaderManager to manage my adapter's cursor so i have overridden the swapCursor() method like the second answer to the example above indicates. public class ContactsCursorAdapter extends SimpleCursorAdapter implements SectionIndexer{ private LayoutInflater mInflater; private Context mContext; private AlphabetIndexer mAlphaIndexer; public ContactsCursorAdapter(Context context, int

How do CursorLoader automatically updates the view even if the app is inactive?

谁都会走 提交于 2019-11-26 10:22:17
问题 I have been working on a small To-Do list app. I used CursorLoader to update the ToDolistview from a content provider. I have a written a function onNewItemAdded() , which is called when user enters a new item in the text view and clicks enter. Refer below: public void onNewItemAdded(String newItem) { ContentResolver cr = getContentResolver(); ContentValues values = new ContentValues(); values.put(ToDoContentProvider.KEY_TASK, newItem); cr.insert(ToDoContentProvider.CONTENT_URI, values); //

Using Singleton design pattern for SQLiteDatabase

感情迁移 提交于 2019-11-26 09:57:49
I'm rather newbie on Android, and I'm working on a simple application to get some basic experience. My app is pretty simple and consists among other things of a broadcast receiver and some activities. Both components make use of a single database, so in theory it could happen that both try to access the db concurrently. Currently I'm simply instantiating the db object (which is-a SQLite db helper class) each time I need it, and performing the needed operations: query, insert, etc. From what I've been reading here and in some other documents, this has the problem of getting a "db locked"

AsyncTaskLoader vs AsyncTask

一世执手 提交于 2019-11-26 06:14:47
问题 Since Honeycomb and the v4 Compatibility Library it is possible to use AsyncTaskLoader . From what I understand, the AsyncTaskLoader can survive through config changes like screen flips. Is it recommended to use AsyncTaskLoader instead of AsyncTask ? Does LoaderManager get in the picture too? But I haven\'t found any good example(s) about how to correctly use the AsyncTaskLoader . The docs also provide no examples. Can anyone provide some good examples. 回答1: You can have a look at the

AlphabetIndexer with Custom Adapter managed by LoaderManager

不羁的心 提交于 2019-11-26 02:23:08
问题 I am trying to implement AlphabetIndexer with Custom Adapter like this AlphabetIndexer with Custom Adapter My class ContactsCursorAdapter extends SimpleCursorAdapter and implements SectionIndexer and I am using a LoaderManager to manage my adapter\'s cursor so i have overridden the swapCursor() method like the second answer to the example above indicates. public class ContactsCursorAdapter extends SimpleCursorAdapter implements SectionIndexer{ private LayoutInflater mInflater; private Context

CursorLoader usage without ContentProvider

孤街浪徒 提交于 2019-11-25 23:33:46
问题 Android SDK documentation says that startManagingCursor() method is depracated: This method is deprecated. Use the new CursorLoader class with LoaderManager instead; this is also available on older platforms through the Android compatibility package. This method allows the activity to take care of managing the given Cursor\'s lifecycle for you based on the activity\'s lifecycle. That is, when the activity is stopped it will automatically call deactivate() on the given Cursor, and when it is