如何跟踪我的应用的首次启动并将用户重定向到另一个屏幕? 请给我示例代码。
答案 0 :(得分:3)
你的意思是从发射器活动到anthor活动吗?如果是这样,你可以试试这个:
@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();
}
}
答案 1 :(得分:1)
使用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
}
答案 2 :(得分:1)
该代码对我有用:
@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{}
}