2021年1月20日星期三

How to fix error handling timer () run many times in kotlin?

class HomeActivity : BaseActivity(), View.OnClickListener,      NavigationView.OnNavigationItemSelectedListener {     private var mTimer:Timer? = null     private var mTimerTask: TimerTask? = null       override fun onCreate(savedInstanceState: Bundle?) {          super.onCreate(savedInstanceState)          // todo ..          syncLocationToServer()          // todo...     }       private fun syncLocationToServer() {                 mTimer = Timer()          mTimerTask = object : TimerTask(){                  override fun run() {                          Log.d("test", getDateTimeLocal())                  }          }        mTimer?.schedule(mTimerTask, 0, 60000L)      }  }  

I want to ask. In the code above, I want to execute Log.d ("test", getDateTimeLocal ()) every 1 minute.

But sometimes when 1 minute occurs, Log.d ("test", getDateTimeLocal ()) is called many times. I don't understand why, please help me??

https://stackoverflow.com/questions/65820530/how-to-fix-error-handling-timer-run-many-times-in-kotlin January 21, 2021 at 10:51AM

没有评论:

发表评论