0

I am building an android application in which I want to run a line of code only one single time, when the application is first installed and run. After that I want to terminate that code until I reinstall my app. Is there any way to do this? If so please help me. Thanks in advance.

Rahulkapil
  • 294
  • 4
  • 13

1 Answers1

11

When the method is first run save a boolean hasMethodRun in the shared preference. Then you may check this boolean each time the method is run. And when you uninstall the preference file associated with the application is also deleted. So no need to keep a tap on when the app is uninstalled.

Arun George
  • 18,352
  • 4
  • 28
  • 28