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.
Asked
Active
Viewed 100 times
0
-
"and run after that i want to terminate " ? you want run only once ot run every time app started ? – Dheeresh Singh Jun 25 '12 at 11:44
-
A nice answer by **Binyamin Sharet** http://stackoverflow.com/questions/7065429/run-code-only-once-in-android – user370305 Jun 25 '12 at 11:47
1 Answers
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
-
-
Thanks @Vipul. Some one rightly said "The early bird catches the worm" :). – Arun George Jun 25 '12 at 11:55