[英]How to create pop-up when first open app in Android?
我編寫了一個應用程序,我想獲取一個電話號碼,但是getline1number()
在任何設備上均不起作用。
因此,我想創建一個彈出窗口以輸入電話號碼並提交進行保存,並且在下次打開的應用程序中不顯示。
像這樣:
您始終可以使用SharedPreferences
來執行以下操作:
SharedPreferences sp = getSharedPreferences("FirstTimeFile", Context.MODE_PRIVATE);
/**
* when the app is opened for the first time, no such variable
* (appIsOpenedForTheFirstTime) exists. So, it becomes true.
*/
boolean appIsOpenedForTheFirstTime = sp.getBoolean("IsAppOpenedForFirstTime",true);
//since it is true, it will be set to false after the execution of following block:
if(appIsOpenedForTheFirstTime) {
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putBoolean("IsAppOpenedForFirstTime", false);
editor.commit();
//PUT THE CODE FOR YOUR POPUP HERE
}
由於即使關閉應用程序后, SharedPreferences
值仍保留在應用程序數據中,因此下次打開應用程序時, appIsOpenedForTheFirstTime
的值將為false,因此將不會執行彈出代碼。
啊,作為一個旁注,如果您清除應用程序數據,所有內容都會被清除-包括SharedPreferences。 閱讀此官方文章可獲得更深入的了解。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.