cancel
Showing results for 
Search instead for 
Did you mean: 

loadInBackground not getting called Android

mcasanket
Champ on-the-rise
Champ on-the-rise
Dear all,

In one requirement I am trying to upload photo that is just captured by camera.

My code is as below.

ContentFile contentFile= new ContentFileImpl(finalFile);
Log.e("myApp", "cf.getLength() " + cf.getLength());// print 12232
Map<String, Serializable> props = new HashMap<String, Serializable>();
props.put(ContentModel.PROP_NAME, finalFile.getName());
DocumentCreateLoader dcl = new DocumentCreateLoader(this, session, parentFolder, finalFile.getName(), props, contentFile);

dcl.loadInBackground();
Log.e("myApp", "1 = " + dcl.isStarted()); // return false
dcl.forceLoad();
Log.e("myApp", "2 = " + dcl.isStarted()); // return false


As the loadInBackground is not getting called the file is not getting uploaded on the server.

Please help.
2 REPLIES 2

jm_pascal
Star Contributor
Star Contributor
Aloah,

You misused the Loader object.
A loader is start & manage by the LoaderManager object associated to the Fragment or Activity Object.
For more information : http://developer.android.com/guide/components/loaders.html

Furthemore your activity/fragment should implements LoaderCallbacks<LoaderResult<Document>>
and
Inside your activity/fragment you should have something like that

getLoaderManager().initLoader(DocumentCreateLoader.ID, null, this);
getLoaderManager().getLoader(DocumentCreateLoader.ID).forceLoad();


You can find some ideas : https://github.com/Alfresco/alfresco-android-sdk/blob/f82cbfeb9650960c587e8417bfdaacaa87bd4d5f/alfre...

But when I write the below code in my class named UploadService extends IntentService it works fine and uploads the documents too…


Cocde:

protected void onHandleIntent(Intent intent) {


Map<String,Serializable> props = new HashMap<String, Serializable>();
      props.put(ContentModel.PROP_NAME, "testpdf.pdf");
      DocumentCreateLoader dc = new DocumentCreateLoader(getApplicationContext(), session, destination, "TestDocByLoader.pdf", props, contentFile);
                dc.loadInBackground(); // works fine
Log.e("myApp", "isStarted: " +dc.isStarted()); // return false
}


However the log dc.isStarted() returns false! 🙂

Thanks!