Probably a stupid question, but found nothing on the Internet. (
How do I know that the application is launched for the first time in the following cases:
- First install and launch.
- Reinstallation and first launch.
Probably a stupid question, but found nothing on the Internet. (
How do I know that the application is launched for the first time in the following cases:
To check on the first launch try using SharedPreferences. When you first start, write any value in them, and then check it http://startandroid.ru/ru/uroki/vse-uroki-spiskom/73-urok-33-hranenie-dannyh-preferences.html
For example:
1) Let's go to Google.
2) drive in
3) In the first link we find the following answer:
This can be done using SharedPreferences . Those. when starting the application, we check the boolean variable. If it is not there, then the first launch means (or the user deleted all application data). After changing the value of the variable and the code will not run at the next launches.
Code:
public class MyActivity extends Activity { SharedPreferences prefs = null; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); prefs = getSharedPreferences("com.mycompany.myAppName", MODE_PRIVATE); } @Override protected void onResume() { super.onResume(); if (prefs.getBoolean("firstrun", true)) { // При первом запуске (или если юзер удалял все данные приложения) // мы попадаем сюда. Делаем что-то //и после действия записывам false в переменную firstrun //Итого при следующих запусках этот код не вызывается. prefs.edit().putBoolean("firstrun", false).commit(); } } } Source: https://ru.stackoverflow.com/questions/410462/
All Articles