我想在僅在用戶安裝應用程序時再次顯示的應用程序中進行活動。我怎樣才能做到這一點?製作只顯示一次的活動屏幕
回答
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. Android splash活動只顯示一次
- 2. 如何啓動顯示「聲音和顯示」屏幕的活動
- 3. 只顯示登錄活動一次,並在下一次啓動主要活動
- 4. 顯示一次歡迎屏幕鈦
- 5. 錄製屏幕活動
- 6. 安裝時只顯示一次安卓屏幕
- 7. 介紹與指標點屏幕 - 只顯示第一次 - Android
- 8. 我想顯示登錄屏幕只有一次在IOS
- 9. 如何在屏幕上一次只顯示切換可見
- 10. 只顯示控制器的一半屏幕使用presentModalViewController
- 11. 將屏幕截圖從一個活動顯示到另一個活動
- 12. ACTION_SCREEN_ON讓屏幕顯示或只是告訴這個動作?
- 13. 上顯示屏而不是上次打開的屏幕顯示
- 14. 在一個屏幕中顯示3個活動
- 15. 每次操作時在屏幕上顯示一些東西
- 16. 使用共享首選項顯示啓動屏幕一次
- 17. Beagleboard在第一次啓動時不顯示歡迎屏幕
- 18. 如何僅顯示一次活動一次。應該只顯示第一次打開的應用程序。?
- 19. Android的活動 - 從一個屏幕到另一個屏幕
- 20. 只顯示一次?
- 21. 與活動屏幕
- 22. 只有一次歡迎屏幕上android
- 23. Android:'初始屏幕'只有一次
- 24. iphone 3gs cameraoverylay只顯示白色屏幕
- 25. 如何顯示第二屏幕再次
- 26. 單擊「通知」圖標時只顯示一次活動
- 27. Google地圖顯示空白屏幕的活動
- 28. iPhone:如何在屏幕上顯示任何活動的UIKeyboard?
- 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