我想在仅在用户安装应用程序时再次显示的应用程序中进行活动。我怎样才能做到这一点?制作只显示一次的活动屏幕
回答
1.在sharedPrefernces中存储值。
SharedPreferences preferences = this.getSharedPreferences("SoldiPreferences", Context.MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
editor.putBoolean("screen_show", false);
editor.commit();
2.从sharedPreferences
SharedPreferences preferences = this.getSharedPreferences("SoldiPreferences", Context.MODE_PRIVATE);
preferences.getBoolean("screen_show", false);
3.It GET值为false第一次总是
if(! preferences.getBoolean("screen_show", false)){
// if show screen
Intent showscreenIntent=new(this,ShowScreen_Intent.class);
startActivity(showscreenIntent);
} else {
//
}
4.after表示屏幕第一次设定在这样的共享prefernece真。
SharedPreferences preferences = this.getSharedPreferences("SoldiPreferences", Context.MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
editor.putBoolean("screen_show", true);
editor.commit();
现在,只要第3步执行else条件运行,Activity就不会再显示。
希望它有帮助!
我在主活动的onCreate()内执行了第一步,然后添加if(preferences.getBoolean(“screen_show”,false)){ 编辑器。 putBoolean(“screen_show”,true); // App已经第一次运行; Intent IntentFirstRunAct = new Intent(MainActivity.this,FirstRunActivity.class); startActivity(IntentFirstRunAct); }它不会改变活动。请帮忙!!! – Logan
请张贴你的代码你试过的东西 –
谢谢你的回答,先生,真的帮助..!它解决了我的问题,认为这是一个非常基本的问题。 – Logan
我的问题解决了尝试这种
boolean isFirstRun = getSharedPreferences("Preference", MODE_PRIVATE).getBoolean("isfirstrun",true);
if(isFirstRun){
getSharedPreferences("Preference", MODE_PRIVATE).edit().putBoolean("isfirstrun",false).commit();
Intent IntentFirstRunAct = new Intent(MainActivity.this,FirstRunActivity.class);
startActivity(IntentFirstRunAct);
}
- 1. 只会显示一次的屏幕 - UIImageView?
- 2. 登录屏幕只显示一次
- 3. Android splash活动只显示一次
- 4. 如何只显示活动一次?
- 5. 只需要新的活动来显示新的屏幕?
- 6. 如何打开只占用三分之二屏幕的活动?屏幕的其余部分显示父活动
- 7. 如何启动显示“声音和显示”屏幕的活动
- 8. 只显示登录活动一次,并在下一次启动主要活动
- 9. 制作FaceBox只显示一次
- 10. 在锁定屏幕上切换活动显示锁定屏幕
- 11. 显示一次欢迎屏幕钛
- 12. “显示一次”屏幕布尔问题
- 13. 录制屏幕活动
- 14. 如何帮助屏幕显示一次只在android
- 15. 介绍与指标点屏幕 - 只显示第一次 - Android
- 16. 安装时只显示一次安卓屏幕
- 17. 如何在屏幕上一次只显示切换可见
- 18. 我想显示登录屏幕只有一次在IOS
- 19. 只显示控制器的一半屏幕使用presentModalViewController
- 20. 将屏幕截图从一个活动显示到另一个活动
- 21. 在显示屏幕底部显示一个面板动作3
- 22. ACTION_SCREEN_ON让屏幕显示或只是告诉这个动作?
- 23. 上显示屏而不是上次打开的屏幕显示
- 24. 动作栏背景显示在屏幕
- 25. 在一个屏幕中显示3个活动
- 26. 在同一屏幕上显示多个活动
- 27. 在同一屏幕上显示两个活动
- 28. 如何强制每个占用屏幕宽度的滚动片段一次只显示一个片段?
- 29. 每次操作时在屏幕上显示一些东西
- 30. 使用共享首选项显示启动屏幕一次
你尝试过这么远吗? – AADProgramming
我做了主要活动的onCreate()内的第一步,然后添加if(preferences.getBoolean(“screen_show”,false)){ editor.putBoolean(“screen_show”,true); // App已经第一次运行; Intent IntentFirstRunAct = new Intent(MainActivity.this,FirstRunActivity.class); startActivity(IntentFirstRunAct); }它不会改变活动。请帮忙!!! – Logan
你需要在你的文章中提到所有这些,以便其他人可以帮助 – AADProgramming