Akavache icon indicating copy to clipboard operation
Akavache copied to clipboard

Android: no ability to re-init Akavache on Activity re-start

Open bnvmxm opened this issue 8 years ago • 7 comments

  1. On a root view, tap Back button
  2. Android gets to the Home, the main activity is stopped & destroyed
  3. OnStop() shuts down Akavache in my case
  4. Then I use the Android App Stack button and choose my app again
  5. Android re-creates the main activity
  6. But Akavache static BlobCache is actually ShutdownBlobCache already and there's no way to re-init Akavache. It's EnsureInitialized() does nothing as all the init logic is in the static constructor

Why not get the initialization lazy and re-enterable via EnsureInitialized()?

bnvmxm avatar Jan 12 '17 15:01 bnvmxm

Hi, did you find a solution or workaround? I'm running in the same issue....

CR4567 avatar Jan 20 '17 15:01 CR4567

Actually, not. For now, just need to ask user to explicitly re-start the app (yeap, ugly). Considering to fork and move the initialization from the static ctor to a dedicated method..

bnvmxm avatar Jan 24 '17 12:01 bnvmxm

I would also appreciate it if Akavache would offer a possibility to shutdown and initialize a BlobCache again. We ran into problems with our tests because some of the tests need a Blobcache with a different EncryptionProvider. Unfortunatelly if the Blobcache is already created, you can not change the EncryptionProvider again. So it would be very practical to dispose the Blobcahe after every testcase and then initialize it again.

KarinBerg avatar Feb 02 '17 10:02 KarinBerg

I use Flush instead of shutdown just to ensure everything in flight gets pushed and so far haven't seen any issues..

As far as for testing maybe just don't use the static stuff and just instantiate your own?

What's this Global Variable nonsense? Why can't I use $FAVORITE_IOC_LIBRARY

You totally can. Just instantiate SQLitePersistentBlobCache or SQLiteEncryptedBlobCache instead - the static variables are there just to make it easier to get started.

If you set the static properties to something it will just use those instead

So like in my unit tests I have this inside TestCleanup

    BlobCache.LocalMachine.InvalidateAll().Wait();
    BlobCache.InMemory.InvalidateAll().Wait();
    BlobCache.Secure.InvalidateAll().Wait();

And then this inside TestInitialize

  BlobCache.InMemory = new InMemoryBlobCache(TestScheduler);
  BlobCache.LocalMachine = new InMemoryBlobCache(TestScheduler);
  BlobCache.Secure = new InMemoryBlobCache(TestScheduler);

So in your case when the test initializes you could just instantiate a new static property. Or just don't use the static access methods and just create the Blob Cache's yourself

PureWeen avatar Feb 09 '17 21:02 PureWeen

Seems, with the #342 ticket, we have a solution. As recommended, just manage the instancing and flushing of IBlobCache explicitly.

bnvmxm avatar Feb 16 '17 14:02 bnvmxm

I changed the ShutDown to Flush only and everything is working fine.

rahamohebbi avatar Apr 15 '17 17:04 rahamohebbi

@PureWeen @rahamohebbi where do you use flush in your app? Can we use in app.xaml.cs OnSleep and re-initiliza onStart or OnResume?

EmilAlipiev avatar Dec 11 '17 17:12 EmilAlipiev