如何跟踪应用程序的首次启动?

How can I keep track of the first launch of an application?

如何跟踪我的应用程序的首次启动并将用户重定向到另一个屏幕? 请给我示例代码。

是否使用 SharedPrefernces 来存储 FirstLogin。

SharedPreferences prefs =getSharedPreferences("packagename", MODE_PRIVATE);

    if (prefs.getBoolean("firstrun", true)) {
        // Do first run stuff here then set 'firstrun' as false
        prefs.edit().putBoolean("firstrun", false).commit();
    }
    else{
       // Do if not first launch
    }

你的意思是从一个启动器 activity 到另一个 activity?如果是这样,你可以试试这个:

在您的启动器中 Activity(MainActivity):

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    SharedPreferences preferences = this.getPreferences(MODE_PRIVATE);
    if (preferences.getBoolean("firstLaunch",false)) {
        Intent intent = new Intent(MainActivity.this,AnotherActivity.class);
        startActivity(intent);
    }else{
        preferences.edit().putBoolean("firstLaunch",true).commit();
    }
}

该代码对我有用:

    @Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    SharedPreferences prefs =getSharedPreferences("packagename", MODE_PRIVATE);
    if (prefs.getBoolean("firstrun", true)) {
        Intent intent = new Intent(MainActivity.this,AnotherActivity.class);
        startActivity(intent);
        prefs.edit().putBoolean("firstrun", false).commit();
    }
    else{}
}