android - Fragment and Service are working with same resources -


I am creating an Android app in which a user can work with small images

in the app Backend (parse.com) is where images are located, so I can add and delete some images. The client side is stored on SD (files) in the image and has a skeleton table where the filespace is located.

There is a piece in the app that takes all the available images and shows them in the gridview with the imageview. I am using the SQLiteCursorLoader / CursorAdapter to get FilePaths and then just load the bitmap into ImageViews.
Also I have IntentService, sync images with backend by timer. Its loads and SDs save new images and delete files of images, which were deleted. It also modifies SQL Tables with file paths of images.

The problem is: IntentService can start its work at the same time when the user works with fragmentation. The user can choose an email, which has already been removed from the intent service.

Does the fragment (or other data consumers) have any possibility of intasive service to check for work now? Does the Intent Service stop working in that case? Is there a 'good practice' to solve such issues?

I would be grateful for any help

From your database to your database My favorite way to keep up to date is to implement the content to be used temporarily and to follow it using the changes.

Your piece will look something like this:

  Applies some of the public category fragment fragments LoaderManager.LoaderCallbacks & lt; Cursor & gt; {Private cursor adapter mAdapter; // ... @Override Public Zero Viewed (View View) {// ... mAdapter = New Resource cursor adapter (hangActivity), Hang R. my_layout, empty, incorrect); // Add the adapter to your grid-view ... getLoaderManager (). InitLoader (0, empty, this); } @ Override Public Loader & lt; Cursor & gt; OnCreateLoader (int id, bundle algus) {new cursor loader (activity received), MY_IMAGE_MODEL_URI, empty, empty, empty, blank); } @ Override Public Wide Onload Load (Loader & lt; Cursor> Loader, cursor cursor) {// it automatically reloads your adapter and updates your grid-view mAdapter.swapCursor (cursor) ; } @ Override Public Wide Onloader Reset (Loader & lt; Cursor> Loader) {mAdapter.swapCursor (null); }}   

Note that the URI that goes to Cursor Loader will be celebrated for changes when a change is detected, then the loader is specified Uri asks after which is called onLoadFinished . But it can only detect changes if you inform the system that the change occurred on that URI you typically do this within your content provider, when you update, insert or delete it, but it is in your Even after deletion by IntentService , your data can be inserted or updated.

The code will look something like this:

  getContentResolver (). Inform (MY_IMAGE_MODEL_URI, null);    

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -