ユーザーがアプリケーションを初めて使用しているかどうかを検出するにはどうすればよいですか?

StackOverflow https://stackoverflow.com/questions/3762300

  •  04-10-2019
  •  | 
  •  

質問

ユーザーがアプリケーションを初めて使用しているかどうかを知りたいと思います。使ってます SharedPreferences, 、しかし、私が正しいロジックを持っているかどうかはわかりません。

どうすれば設定できますか isFirstLaunched ユーザーが最初に起動したときにブールからtrueになり、その後、作業が完了した後にすぐにfalseに設定しますか?

protected void onStart() {
        super.onStart();

        if(isFirstLaunch()){
            populateDefaultQuotes();

            //Save the preferences, isFirstLaunch will now be false
            SharedPreferences settings = getSharedPreferences(Constants.PREFS_NAME, 0);
            SharedPreferences.Editor editor = settings.edit();
            editor.putBoolean("isFirstLaunch", false);
            editor.commit();
        }

        setupUI();
        checkOrientation();
        restoreCache();
    }

    private void populateDefaultQuotes(){
        System.out.println("!!!!!! FIRST TIMER !!!!!!");
    }

    private boolean isFirstLaunch() {
        // Restore preferences
        SharedPreferences settings = getSharedPreferences(Constants.PREFS_NAME, 0);
        boolean isFirstLaunch = settings.getBoolean("isFirstLaunch", false);

        return isFirstLaunch;
    }
役に立ちましたか?

解決

を交換します false 議論 getBoolean()true, 、その後、ロジックが適合します。

boolean isFirstLaunch = settings.getBoolean("isFirstLaunch", true); 

これは戻ります true そのような設定がない場合。

他のヒント

BroadCastReceiverを登録して、Intent.action_package_first_launchを聴くことができます

http://developer.android.com/reference/android/content/intent.html#action_package_first_launch

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top