如何在用戶安裝我的應用程序時顯示啓動畫面。每次用戶打開時,我都不想顯示啓動畫面,但只有在USER將其安裝在手機上並第一次打開時才顯示啓動畫面。如何實現這一目標?如何在App上顯示一次Splash Screen?
0
A
回答
1
你需要檢查每次當應用程序將打開,這是它的第一次啓動的應用程序?如果是,那麼顯示你的一次閃屏其他顯示主要活動
你可以使用共享首選項來存儲有關第一次啓動的數據。
0
在您每次啓動應用程序時都會顯示的主要活動中,請嘗試以下邏輯。
SharedPreferences mPrefs;
final String splashScreenPref= "SplashScreenShown";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mPrefs = PreferenceManager.getDefaultSharedPreferences(this);
Boolean splashScreenShown= mPrefs.getBoolean(splashScreenPref, false);
if (!splashScreenShown) {
Intent intent=new Intent(MainActivity.this,SplashScreenActivity.class);
startActivity(intent);
SharedPreferences.Editor editor = mPrefs.edit();
editor.putBoolean(splashScreenShown, true);
editor.commit();
finish();
}
}
0
這裏,
您應該創建應用類別及需要打電話給你需要從應用程序類活動onCreate方法。
public class Appli extends android.app.Application {
@Override
public void onCreate() {
super.onCreate();
//manage base on your requirement,you can use share preference for splash screen track
Intent intent = new Intent(this,Main2Activity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}
清單:
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:name=".Appli"
android:theme="@style/AppTheme">
</application>
上面的代碼肯定的工作,我已經測試。
相關問題
- 1. shared splash with splash screen
- 2. Splash Screen&Premise Screen - Android
- 3. Android Splash Screen
- 4. Android Splash Screen Bug
- 5. LaunchScreen&Splash Screen
- 6. iOS Splash Screen沒有顯示在設備上 - 奇怪的問題
- 7. 如何在Android中創建Motion Splash Screen?
- 8. Android Splash Screen to FragmentActivity
- 9. Android Splash Screen WepApp Sencha
- 10. iOS Wierd Splash Screen Bug
- 11. Android splash活動只顯示一次
- 12. NetBeans的Splash Screen功能如何工作?
- 13. iPhone Webapp Splash Screen White-Space
- 14. 爲什麼我的Delphi Splash Screen上的圖標和信息只顯示第一次?
- 15. Android,如何製作一個沒有白屏的Splash Screen aka Launch Screen?
- 16. 在iOS Splash Screen中會發生什麼?
- 17. 在App中顯示UIAlert一次
- 18. 爲android平臺定製cordova Splash Screen
- 19. Android Splash Screen ProgressBar顏色不變
- 20. 如何僅執行一次splash片段?
- 21. 當啓動定時器線程時,Android Splash Screen不顯示內容
- 22. 如何設置適用於所有設備的Perfect Splash Screen
- 23. 如何從我的iOS版本中刪除Unity Splash Screen?
- 24. 如何正確地從splash Screen重定向到tabBarController?
- 25. 傳出頁面和加載頁面上的「Splash Screen Div」
- 26. Codename One:Android上的iOS屏幕截圖/ Splash Screen
- 27. 如何顯示messageBox一次?
- 28. 如何在android Splash Screen中使用帶有動畫taf的SVG文件
- 29. 如何在Windows 8應用程序中保留Splash Screen的圖像?
- 30. Metro App Pin/Unpin to Start screen
可能的重複[如何使閃屏?](http://stackoverflow.com/questions/5486789/how-do-i-make-a-splash-screen?rq=1)或[如何僅當應用程序啓動「新鮮」時才顯示啓動畫面?](http://stackoverflow.com/questions/7682439/how-to-show-splash-screen-only-when-the-app-starts-fresh?rq = 1) –
您可以使用相同的共享首選項。 –