Domanda

I want that my Android app unzips a compressed archive. My concern is what happens if lifecycle stages of the activity occurr during the unzipping, like i.e. onStop(), onPause(), onDestroy() methods. In my app it doesn't matter blocking the UI while unzipping, instead it is so by design, the user awaits while a progress dialog with progress bar displays the progress. But I would like to be sure the unzipping is completed. How to get that?

È stato utile?

Soluzione

You should always do things like this async-ly. What if the user accidentally attempts to unzip a huge zip file and they want to stop it before they run out of storage? A service is the best solution. It runs in background and the system will only kill it when the memory is critically low, ie. even if your activity is not visible, it will continue to run. It can communicate with your UI thread to display a progress bar via a handler and it can be cancelled at will.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top