I use four fragment in mainactivity and each has it's class with mainactivity class.
I have elements in fragment1 class, when I create them inside onCreateView method they are creating each time when I open the fragment.
I tried to create elements in onStart method in fragment class, nothing changes. I tried to create elements in onCreate method in fragment class, it stops the app.
When I create the elements in onCreate, onStart method in MainActivity, it stops the app.
So, basically I want to create element only once, and when app start they has to be created.
How can I solve this problem? Thanks for help.
The easiest way would be to add a simple check for if they’re null or not before creating them:
For this method you would make sure the variables are in the scope of your entire class:
Otherwise you could rewrite the code to use static variables.