一次调用方法 [英] Calling a Method Once

查看:77
本文介绍了一次调用方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当条件达到多次时,我遇到了如何调用一次方法的问题!例如:

I am having a problem of how to call a method once when the condition achieves many times! for example:

public void onLocaitonChanged(Location location){

  // this if statement may achieve the condition many times
  if(somethingHappened){

       callAMethodOnce();// this method is called once even if the condition achieved again
  }

}

请帮助

推荐答案

public void onLocaitonChanged(Location location){

  // this if statement may achieve the condition many times
  if(somethingHappened){

       if (!isAlreadyCalled){   
           callAMethodOnce();// this method is called once even if the condition achieved again
           isAlreadyCalled = true;
       }
  }

}

这篇关于一次调用方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆