我怎样才能让安装我的Android应用程序后,在设备上我的对话框出现一次?
How can I make my dialog appear only once after my Android app is installed on the device?
使用共享preference存储 firstrun
价值,并且在对您的发射活动查询值。如果该值被设置,则没有必要显示对话框。如果别的,显示对话框,并保存 firstrun
标志中共享preference。
Use SharedPreference to store the firstrun
value, and check in your launching activity against that value. If the value is set, then no need to display the dialog. If else, display the dialog and save the firstrun
flag in SharedPreference.
恩(你启动的活动):
public void onCreate(){
boolean firstrun = getSharedPreference("PREFERENCE", MODE_PRIVATE).getBoolean("firstrun", true);
if (firstrun){
...Display the dialog
// Save the state
getSharedPreference("PREFERENCE", MODE_PRIVATE)
.edit()
.putBoolean("firstrun", false)
.commit();
}
}