如何在首次导航到另一个 activity 时在 android 中显示对话框?
How to show a dialog in android on navigating to another activity for the first time?
如何在 android 中仅在第一次导航到另一个 activity 时显示对话框?我不想把它放在 activity 的 onResume() 中,因为每次我导航到那个 activity.
时,对话框都会出现
在 onCreate 处理程序中使用此函数
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
...
if (isFirstTime()) {
// show dialog
}
...
}
/***
* Checks that application runs first time and write flag at SharedPreferences
* @return true if 1st time
*/
private boolean isFirstTime()
{
SharedPreferences preferences = getPreferences(MODE_PRIVATE);
boolean ranBefore = preferences.getBoolean("RanBefore", false);
if (!ranBefore) {
// first time
SharedPreferences.Editor editor = preferences.edit();
editor.putBoolean("RanBefore", true);
editor.commit();
}
return !ranBefore;
}
如何在 android 中仅在第一次导航到另一个 activity 时显示对话框?我不想把它放在 activity 的 onResume() 中,因为每次我导航到那个 activity.
时,对话框都会出现在 onCreate 处理程序中使用此函数
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
...
if (isFirstTime()) {
// show dialog
}
...
}
/***
* Checks that application runs first time and write flag at SharedPreferences
* @return true if 1st time
*/
private boolean isFirstTime()
{
SharedPreferences preferences = getPreferences(MODE_PRIVATE);
boolean ranBefore = preferences.getBoolean("RanBefore", false);
if (!ranBefore) {
// first time
SharedPreferences.Editor editor = preferences.edit();
editor.putBoolean("RanBefore", true);
editor.commit();
}
return !ranBefore;
}