handler

Check if Android handler has callbacks

Deadly 提交于 2019-12-22 04:53:08
问题 I have some code which sets a timer, but if a user sets the timer while it is in use I need to remove the runnable which runs the timer and start it again. But when no handler callback runnable exists and this code is called it crashes my application. So I need to check if a handler is running, if so then end it and restart it, but looking through the documentation and other Stackoverflow questions, I cannot see if this is possible. Here is my code, I have commented around the code which

How to create multiple timer handler in vb.net

穿精又带淫゛_ 提交于 2019-12-22 01:13:37
问题 I have to create multiple timer "n" times with handler. Which will be stored for a row in my DataGrid. For each row there will be a timer that works seperately. What I thought of looks like: Private Sub CreateTimer() Dim tmr As New Timer tmr.Interval = 1000 '1 Second tmr.Enabled = True AddHandler tmr.Tick, AddressOf GlobalTimerTick End Sub 'A timer tick handler that would work for each timer I add with the sub above 'All timers I created should work seperately Private Sub GlobalTimerTick

Accessing UI view in another thread does *not* cause a crash. Why?

孤街浪徒 提交于 2019-12-21 20:56:04
问题 All: I really don't grok handlers yet. I thought that the code below -- modified so that, instead of using a handler, the UI widget (progress bar) was accessed directly -- would cause a cross-threading exception. But it doesn't. So, my question is, shouldn't this code crash? And if it doesn't, then when do I need to use a handler? public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); progress = 0; progressBar = (ProgressBar)

Passing context to Handler

时光总嘲笑我的痴心妄想 提交于 2019-12-21 17:39:09
问题 Is it possible to pass arguments to an Android Handler?? I have two pieces of code. new Thread(){ public void run(){ for(;;){ uiCallback.sendEmptyMessage(0); Thread.sleep(2000); //sleep for 2 seconds } } }.start(); private Handler uiCallback = new Handler(){ public void handleMessage(Message msg){ //add a new blossom to the blossom ArrayList!! blossomArrayList.add(new Blossom(context, R.drawable.blossom)); } }; I of course get an error because the Handler method cannot see my context. This is

Android中的Handler, Looper, MessageQueue和Thread

狂风中的少年 提交于 2019-12-21 14:20:21
前几天,和同事探讨了一下 Android 中的消息机制,探究了消息的发送和接收过程以及与线程之间的关系。虽然我们经常使用这些基础的东西,但对于其内部原理的了解,能使我们更加容易、合理地架构系统,并避免一些低级错误。 对于这部分的内容,将分成 4 小节来描述: 1.职责与关系 2.消息循环 3.线程与更新 4.几点小结 -------------------------------------------------------------------------------------------------- 1 ) 接下来,我们开始这部分的内容,首先了解一下各自的职责及相互之间的关系。 职责 Message :消息,其中包含了消息 ID ,消息处理对象以及处理的数据等,由 MessageQueue 统一列队,终由 Handler 处理。 Handler :处理者,负责 Message 的发送及处理。使用 Handler 时,需要实现 handleMessage(Message msg) 方法来对特定的 Message 进行处理,例如更新 UI 等。 MessageQueue :消息队列,用来存放 Handler 发送过来的消息,并按照 FIFO 规则执行。当然,存放 Message 并非实际意义的保存,而是将 Message 以链表的方式串联起来的,等待 Looper 的抽取。

Does the memory get released when I throw an exception?

我怕爱的太早我们不能终老 提交于 2019-12-21 12:09:17
问题 I was debating with some colleagues about what happens when you throw an exception in a dynamically allocated class. I know that malloc gets called, and then the constructor of the class. The constructor never returns, so what happens to the malloc ? Consider the following example: class B { public: B() { cout << "B::B()" << endl; throw "B::exception"; } ~B() { cout << "B::~B()" << endl; } }; void main() { B *o = 0; try { o = new B; } catch(const char *) { cout << "ouch!" << endl; } } What

python模块 ---logging模块

情到浓时终转凉″ 提交于 2019-12-21 07:04:55
摘要by crazyhacking: 与log4cxx一样,分为三个部分,logger, handler,formatter. 详细内容参考:1官网 http://docs.python.org/2/howto/logging.html#formatters 2 log4cxx http://blog.csdn.net/crazyhacking/article/category/1536605 一 简单示例 import logging logger = logging.getLogger() # 生成一个日志对象 # logfile是一个全局变量,它就是一个文件名,如:'crawl.log' logfile = 'test.log' # 生成一个Handler。logging支持许多Handler, # 象FileHandler, SocketHandler, SMTPHandler等,我由于要写 # 文件就使用了FileHandler。 hdlr = logging.FileHandler('sendlog.txt') # 成一个格式器,用于规范日志的输出格式。如果没有这行代码,那么缺省的 # 格式就是:"%(message)s"。也就是写日志时,信息是什么日志中就是什么, # 没有日期,没有信息级别等信息。logging支持许多种替换值,详细请看 #

Android postDelayed Handler Inside a For Loop?

[亡魂溺海] 提交于 2019-12-21 05:16:16
问题 Is there any way of running a handler inside a loop? I have this code but is not working as it does not wait for the loop but executes the code right way: final Handler handler = new Handler(); final Runnable runnable = new Runnable() { public void run() { // need to do tasks on the UI thread Log.d(TAG, "runn test"); // for (int i = 1; i < 6; i++) { handler.postDelayed(this, 5000); } } }; // trigger first time handler.postDelayed(runnable, 0); Of course when I move the post delayed outside

事件兼容函数

不打扰是莪最后的温柔 提交于 2019-12-21 03:30:08
var EventUtil={ //目标元素 事件类型 事件处理程序 addEvent:function (ele,type,handler) { if(ele.addEventListener){ //DOM2级事件处理程序 ele.addEventListener(type,handler,false); }else if(ele.attachEvent){ //IE级事件处理程序 ele.attachEvent('on'+type,handler); }else{ ele['on'+type]=handler; //DOM0级事件处理程序 } }, deleteEvent:function (ele,type,handler) { if(ele.removeEventListener()){ ele.removeEventListener(type,handler,false); }else if(ele.detachEvent()){ ele.detachEvent('on'+type,handler); }else{ ele['on'+type]=null; } } } function event() { alert(this); } var oBtn=document.querySelector('#btn'); EventUtil.addEvent(oBtn,

Android Async, Handler or Timer?

蓝咒 提交于 2019-12-21 01:12:34
问题 Every 5 seconds, I want to call my webservice and get text (not images), then display it in my ImageAdapter. What would be the best way to accomplish this? 回答1: It depends if you want to use a different thread or not. Do you want the user to be able to interact with the application on the UI Thread while the images are downloading? If so, then I would definitely use an AsyncTask with a small ProgressBar ( style="@android:style/Widget.ProgressBar.Small" ) If you don't care about threading then