2017-07-07 82 views
-3

我想在僅在用戶安裝應用程序時再次顯示的應用程序中進行活動。我怎樣才能做到這一點?製作只顯示一次的活動屏幕

+0

你嘗試過這麼遠嗎? – AADProgramming

+0

我做了主要活動的onCreate()內的第一步,然後添加if(preferences.getBoolean(「screen_show」,false)){ editor.putBoolean(「screen_show」,true); // App已經第一次運行; Intent IntentFirstRunAct = new Intent(MainActivity.this,FirstRunActivity.class); startActivity(IntentFirstRunAct); }它不會改變活動。請幫忙!!! – Logan

+0

你需要在你的文章中提到所有這些,以便其他人可以幫助 – AADProgramming

回答

1

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就不會再顯示。

希望它有幫助!

+0

我在主活動的onCreate()內執行了第一步,然後添加if(preferences.getBoolean(「screen_show」,false)){ 編輯器。 putBoolean(「screen_show」,true); // App已經第一次運行; Intent IntentFirstRunAct = new Intent(MainActivity.this,FirstRunActivity.class); startActivity(IntentFirstRunAct); }它不會改變活動。請幫忙!!! – Logan

+0

請張貼你的代碼你試過的東西 –

+0

謝謝你的回答,先生,真的幫助..!它解決了我的問題,認爲這是一個非常基本的問題。 – Logan

0

我的問題解決了嘗試這種

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); 
    }