Suppose there is an activation and at the beginning there is loaded for example an mp3 file for MediaPlayer, it seems to happen quickly, but let's say the file pulls up from the network and loads for a long time. Well, he booted. Now, by clicking on a certain button, I switch to a new activation, and the first one is activated by the system on onPause (as far as I know at this moment all the resources of this activation are cleared). And now, in the second activation, I create a copy of the first activation (or rather, the class) and I want to get access to the file that has long crashed and which I specifically loaded onto the splash screen. If I create an instance of the first class, I will either not have the downloaded file at all, or if its loading is not implemented in the life-cycle methods, it will start loading on a new one. (or even it will not be possible to re-create in such a way that when an instance is created it reloads). Only if I declare a resource as static, can I use it in the future. Correct my mistakes in thinking and tell me how to properly load a heavy resource on the splash screen, so that later it is convenient to refer to it?

There is no answer, I update and clarify the question.

UPD When, when opening the next activation, a heavy file is loaded from the resources into the RAM (for example, the background music file). Surely there will be a delay in the deployment of the activation until the upload is complete. As I understand, such a transfer is transferred to the Splash screen. a separate class is responsible for displaying Splash screen, it has loaded the required file into a variable and we want to receive it, this variable, next activation. But creating an instance of the class Splash screen, we will not get it, it remains to make the variable static. But is it right? Is this approach used when, for example, in a heavy game like World of Tanks, a splash screen hangs for a long time. Hardly they load a bunch of files and make them static. Below in the answers, we suggested not to change the activation, but only to change the display using setContentView (). But then the RAM was crying, variables that are no longer needed will not be killed by the garbage collector .. And on the other hand in the Splash screen there are not many variables .. All files are loaded, the display was replaced with setContentView () and it went .. The question is Is the approach correct and used by professionals?

  • 2
    through the service it is done, what you describe is not acceptable at all in android development - pavlofff
  • Please describe how this happens. Consider not the matter of downloading from the network, but you need to load from res to RAM. But do it during the splash screen. Is this also done using the service? While my activity is loading, I am uploading a file to the service class in an additional stream? And should a class of service live as long as I need access to the file? It seems that something is wrong, it will be too fat to create a service to load the file from the resources into the RAM .. - Turalllb
  • Pavlofff, when I go into the game and see the splash screen on which the loading percentages tick, the load comes from which class? Is there a service from what is activated or on the background? - Turalllb

1 answer 1

When you leave Activiti, then indeed, it becomes paused. But resources are cleared only if the system runs out of memory, if the activation is “blurred” with a finger from the task list, if in the developer settings there is a tick “kill activation right away”. So, by and large, one can hope that everything will be fine, but there is a small chance that a bug will sometimes pop up.

Another question is - how much resources did it cost us to download this file? If expensive, i.e. the user can spit and with the words "brake shit" delete our application, it makes sense to cache this file on a USB flash drive. And it doesn’t matter at all whether you are loading it inside Activiti or inside the Service (as is generally correct), the main thing is that after downloading the file will always be available and accessible quickly.

Personally, my choice is: do not smear the application functionality on the Activation pile, but do download and use inside one, periodically showing / hiding some form elements or changing the displayed views using setContentView (). And it does not matter, we loaded the file inside the activation or service itself. The main thing here is to figure out who is who and not to get lost, because if you create a new instance of a class, it is obvious that it will be pristine and there will be nothing in it (except static fields, but for them there is no need to make instances).

  • setContentView() markup with setContentView() much worse than attaching tags to views :). As a result, this practice leads to: my tablets with 1 gig of operatives, which I bought as "cool" a few years ago, are now considered "devices with a small amount of memory" - pavlofff
  • Bukkojot, that is not the question. Let the file is already in apk, let res be a heavy file. I want to download this file in advance in a hurry screen. And then in other classes to have access to the file. Those. The file should not disappear from RAM. It remains to make it static? The question is how to load resources into the RAM that need to be used further in other activations. What is the practice in order not to annoy the user by long loads of resources - Turalllb