Android 让对话框在安装后显示一次
我试图让我的应用程序中的对话框在应用程序安装后只显示一次,并允许我详细说明。用户安装并首次启动应用程序后,将弹出一个对话框,但在用户单击“确定”按钮后,将关闭该对话框。这将是用户最后一次看到该对话框,除非他或她删除应用程序并再次安装。我想把它用于我的应用程序,如果这个方法需要我的对话框中的代码,我想如果有人可以帮助我下面的代码。如果你能提供任何帮助,我会非常高兴的。如果没有,可以有人指向一个教程,这样我可以进一步我的知识Android 让对话框在安装后显示一次,android,Android,我试图让我的应用程序中的对话框在应用程序安装后只显示一次,并允许我详细说明。用户安装并首次启动应用程序后,将弹出一个对话框,但在用户单击“确定”按钮后,将关闭该对话框。这将是用户最后一次看到该对话框,除非他或她删除应用程序并再次安装。我想把它用于我的应用程序,如果这个方法需要我的对话框中的代码,我想如果有人可以帮助我下面的代码。如果你能提供任何帮助,我会非常高兴的。如果没有,可以有人指向一个教程,这样我可以进一步我的知识 final AlertDialog.Builder alertDi
final AlertDialog.Builder alertDialog = new AlertDialog.Builder(this);
alertDialog.setTitle("Title");
alertDialog.setIcon(R.drawable.ic_launcher);
alertDialog.setMessage("Message1");
alertDialog.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
}
});
alertDialog.show();
首次关闭对话框时,您可以使用
SharedReferences
存储一个值,并在每次启动应用程序时检查该值是否存在:
final SharedPreferences prefs=PreferenceManager.getDefaultSharedPreferences(this);//this==context
if(!prefs.contains("FirstTime")){
//Other dialog code
alertDialog.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
Editor editor = prefs.edit();
editor.putBoolean("FirstTime",true);
editor.commit();
//more code....
}
});
}
首次关闭对话框时,您可以使用
SharedReferences
存储一个值,并在每次启动应用程序时检查该值是否存在:
final SharedPreferences prefs=PreferenceManager.getDefaultSharedPreferences(this);//this==context
if(!prefs.contains("FirstTime")){
//Other dialog code
alertDialog.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
Editor editor = prefs.edit();
editor.putBoolean("FirstTime",true);
editor.commit();
//more code....
}
});
}
如果(!prefs.contains(“FirstTime”)
会更好。和prefs.putBoolean(“FirstTime”,true)
应更改为editor.putBoolean(“FirstTime”,true)
如果(!prefs.contains(“FirstTime”)
会更好。和prefs.putBoolean(“FirstTime”,true)
应更改为editor.putBoolean(“FirstTime”,true)代码>。