I have a piece of code that I only want to run the very first time a particular OnCreate() method is called (per app session), as opposed to every time the activity is created. Is there a way to do this in Android?
use static
variable.
static boolean checkFirstTime;
protected void onCreate(Bundle savedInstanceState)
has all you need.
If savedInstanceState == null
then it is the first time.
Hence you do not need to introduce extra -static- variables.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With