Can I have an android activity run only on the first time an application is opened?

后端 未结 5 827
时光说笑
时光说笑 2020-12-08 05:17

OK, so I\'m playing around with an android app.

The 90% use case is that users want to go straight to the primary list screen to find what they\'re looking for. Tha

5条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-08 06:17

    String VersionValue = "v.1.0"; final String PREFS_NAME = "MyPrefsFile";

        SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
    
        if (settings.getBoolean(VersionValue, true)) {
            //the app is being launched for first time, do something        
            NewDialogFragment newFragment = new NewDialogFragment();
            newFragment.show(getFragmentManager(), "New");
            // record the fact that the app has been started at least once
            settings.edit().putBoolean(VersionValue, false).commit(); 
        }
    

    You could do it this way and still get the same result I tried it its a small workaround if u do not fully understand how to check if the app is updated. Instead with this code you can just simply change the String VersoinValue to your current app version and android will think the app is a new first time app and will only display the code u wrote once until you change VersionValue on your next update. (:

提交回复
热议问题