【发布时间】:2017-02-05 04:58:46
【问题描述】:
我为我的 Android 应用设计了一个操作栏。在此操作栏中,有一个按钮可启动用于配置我的应用程序行为的 Dialog Activity。如果我双击这个按钮的速度足够快,我可以命令 Dialog Activity 在它实际出现之前启动两次,然后它看起来是重复的并且在视觉上是重叠的,我不想要这个。我试图创建某种锁定机制,但它不起作用,因为我的 Dialog Activity 仅在我的 Main Activity 调用方法 (onOptionsItemSelected) 中的所有代码都执行后才启动。有没有办法避免这种形式发生?
我的代码是:
@Override
public boolean onOptionsItemSelected(MenuItem item) {
//ensure only one element from the option menu is launched at once (if you double click fast you could launch two)
Log.e("test", "onOptionsItemSelected ");
if(optionItemAlreadySelected == false)
{
optionItemAlreadySelected = true;
int id = item.getItemId();
if (id == R.id.action_sound_mode) {
//item.setVisible(false);
Intent intent = new Intent(this, SoundConfigurationActivity.class);
startActivity(intent);
optionItemAlreadySelected = false; //this code is executed before the activity is started!!!
return true;
}
}
return super.onOptionsItemSelected(item);
}
有没有办法知道 Dialog Activity 何时已经关闭,并在此之前锁定再次打开它的机会。
【问题讨论】:
标签: android android-activity callback android-actionbar