android - AsyncTaskLoader and orienatation change -


I have an AsyncTaskLoader to do some work on the first startup. Loader has been started in the OnCreate mode of my activity

  if (! Initial Loader) {getLoaderManager () InitLoader (INITIALIZE_DB_LOADER_ID, empty, this); Startenders = true; }   

The loader is a boolean that is placed on the onsiteinstestate and has been recovered in the creation again.

This prevents my loader from restarting but now it does not distribute results via callback because my audience, which is my activity, was destroyed. Here is the code that launches my loader:

  @override public loader & lt; Boolean & gt; OnCreateLoader (int id, bundle args) {back to new initalizeDatabaseLoader (this); }   

How can I survive my AsyncTaskLoader to resume on an orientation change but still deliver the results?

You must expand the delivery result () method and get the result memory Should be kept in until the activity is not reconnected with the loader.

You can find a very good example here:

The required part is:

  / ** * When new to deliver to the client There is data. * Super class will take care to distribute it; Implementation * Here just adds a little more logic * / @ Override Public Records Deliver Result (List and Lieutenant; Appentary Additions) {if (isReset ()) // A Async Quiketer came during loader shutdown. We do not need // if the results (apps! = Null) {onReleaseResources (apps); }} List & lt; AppEntry & gt; OldApps = mApps; MApps = apps; If (Starred ()) // If the loader has started now, then we can immediately remove its results // Super.deliverResult (apps); } // At this time we can release resources associated with // 'old APPS' if necessary; Now when the new result has come out we know // it is no longer in use. If (old app! = Null) {onReleaseResources (oldApps); }}   

In addition to this, you want to extend the onStartLoading () method to immediately cache the cached results:

  / ** * Handles a request to start the loader * / @ Override protected start-up starterloading () {if (mApps! = Null) {// If any results are currently available, then immediately // Send deliverResult (mApps); } // Start to see changes to app data If (mPackageObserver == faucet) {mPackageObserver = new packagecontent receiver (this); } // Have we created an app list for the past 9 times, so has some interesting changes in the configuration? Change Boolean Config = mLastConfig.applyNewConfig (getContext (). GetResources ()); If (lentent change () || mpps == empty || config change) // If the data was last modified / changed or is not currently available, start loading. ForceLoad (); }}    

Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -