How to display a view only once on application first run?

android

Solution

Use `SharedPreference` to store a `firstboot` value, and check in the activity against that value. If the value is set, then the application has been launched before. Otherwise, you will display the activity and setthe `firstrun` flag in the `SharedPreference`.

For example, your your launched activity might look something like this,

public void onCreate(){
    boolean firstboot = getSharedPreference("BOOT_PREF", MODE_PRIVATE).getBoolean("firstboot", true);

    if (firstboot){
        // 1) Launch the authentication activity

        // 2) Then save the state
        getSharedPreference("BOOT_PREF", MODE_PRIVATE)
            .edit()
            .putBoolean("firstboot", false)
            .commit();
    }
}

Problem

I want to develop an application that shows an authentication screen one time after installing it, and then other screens on subsequent runs. Is there a way to do it?

Original source