handler

Handler----MessageQueue----Looper的解析

心已入冬 提交于 2019-12-25 03:39:15
一、Handler使用 (1)handler的初始化 Handler mHandler=new Handler(){ @Override public void handleMessage(Message msg) { super.handleMessage(msg); } }; 注:初始化handler时可以传入looper,如果没有传入,则使用的是当前线程的looper。 (2)handler发送消息方式,基本上是两种方式 mHandler.sendEmptyMessage(0); mHandler.sendEmptyMessageDelayed(0,500); mHandler.sendMessage(message); mHandler.sendMessageDelayed(message,500); mHandler.post(new Runnable() { @Override public void run() { } }); mHandler.postDelayed(new Runnable() { @Override public void run() { } },500); 二、Handler、MessageQueue、Looper三者的关系 1、要想使用Handler,必须先创建Looper;app启动时

Handler post delay not work in for loop

三世轮回 提交于 2019-12-25 03:38:10
问题 Spannable WordtoSpan; TextView tvView; public void btnStart(View v) { tvView = (TextView)findViewById(R.id.tvTest); changeColorOfText("I know just how to whisper, And I know just how to cry,I know just where to find the answers."); } int sIndexOfWord; int fIndexOfWord; private void changeColorOfText(String sentences) { String[] arrWords = sentences.split(" "); WordtoSpan = new SpannableString(sentences); int k = 1; for(String word : arrWords) { sIndexOfWord = sentences.indexOf(word);

“this” inside event handler from HTML attribute

本小妞迷上赌 提交于 2019-12-25 03:15:55
问题 I thought I understood wel the "this" keyword until I saw this code : <body> <button onclick="go()">clic1</button> <button id="btn">clic2</button> <script> function go() { console.log(this); } var btn = document.getElementById("btn"); btn.onclick = function() { console.log(this) } </script> </body> I have a HTML document with two buttons that do the same thing when clicked :they log the "this" keyword. I'm very surprised they don't show the same result : For the button "clic1" : this = Window

The operation is not valid for the state of the transaction when trying to make Bus.SendLocal in Handler (local Azure worker)

折月煮酒 提交于 2019-12-25 02:29:27
问题 I have a next code: class ProcessHandler : IHandleMessages<StartProcess> { public IBus Bus { get; set; } public void Handle(StartProcess message) { //some long living process (over 3 min) Bus.SendLocal(new SameMessage()); //get error here } } error message: The operation is not valid for the state of the transaction. stack trace: *at System.Transactions.TransactionState.EnlistVolatile(InternalTransaction tx, IEnlistmentNotification enlistmentNotification, EnlistmentOptions enlistmentOptions,

Android threading and Handler not working

倾然丶 夕夏残阳落幕 提交于 2019-12-25 02:17:56
问题 I recently refactored an old project and found that a particular portion no longer wants to run properly no matter what I do. Essentially, I have an Activity with a TextView. This view is updated at timed intervals from a thread invoked within the same class. The pause is accomplished with a Thread.sleep and a Handler is used to trigger the update of the UI. The thing is, now I either get a CalledFromWrongThreadException saying that I cannot manipulate the View from another thread, a long

How to initialize handlers from separated threads?

让人想犯罪 __ 提交于 2019-12-25 01:36:22
问题 I am coding an application where a remote service has to run at all time and to perform these taks : Create and keep a bluetooth connection to another device Ask this device for informations periodically (1 second) Get GPS Location periodically (1 second) Write previous datas in a text file every 1 second For this, I created from my remote service 2 Threads : one for the data request (loopThread) and one for the GPS Location (gpsThread). The loopThread, after getting the datas from the

跨浏览器事件处理程序

蹲街弑〆低调 提交于 2019-12-25 00:31:15
浏览器的差异导致需要针对不同版本的浏览器编写不同的事件处理函数,恰当使用能力检测,保证处理事件的代码能在大多数的浏览器下一致地运行。 1.创建addHandler()方法,它的职责是分情况使用DOM0级方法、DOM2级方法或IE方法来添加事件。addHandler()方法接收的参数如下: element:要操作的元素 type:事件名称 handler:事件处理函数 2.另一个创建的方法是removeHandler()方法,与addHandler()方法相反,它是移除对应的方法函数。 var EventUtil = { addHandler:function (element,type,handler) { if(element.addEventListener){ element.addEventListener(type,handler,false) }else if(element.attachEvent){ element.attachEvent("on"+type,handler) }else{ element["on"+type] = handler } }, removeHandler:function (element,type,handler) { if(element.removeEventListener){ element

why is this problem “Can't create handler inside thread” happening on realtime database?

天大地大妈咪最大 提交于 2019-12-24 23:26:48
问题 so i'm trying to call realtime database from inside a firebasemessagingservice to get some infos from the database but each and every time the app is on background this error is happening 09-17 19:27:21.596 4083-4140/? E/AndroidRuntime: FATAL EXCEPTION: Firebase-MyFirebaseMessagingService Process: com.kirtu.simpletexts.texts, PID: 4083 java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare() at android.os.Handler.<init>(Handler.java:200) at android

PDF Handler Problem with Chrome & Firefox

拥有回忆 提交于 2019-12-24 21:22:43
问题 Well I solved the problem of running out of memory when accessing the PDF files, but now it seems that when I try to access big files via Chrome or Firefox I get gibberish. It doesn't open Adobe, it just display it as a page with millions of characters. Im using the code below to get it to the user, any ideas on why it would be doing this? case "PDF": context.Response.ContentType = "application/pdf"; context.Response.AddHeader("content-disposition", "inline; filename=" + asset.A_Name); }

Javascript Proxy对象 简介

故事扮演 提交于 2019-12-24 18:58:34
Javascript Proxy对象 简介 Javascript Proxy对象 改变你操作对象的方式 Proxies 是Javasript对象的中间件 ...或者说至少是那种很早的版本。 ES6 中引入Proxies,让你可以自定义 Object 的基本操作。例如, get 就是 Object 的基础操作方法。 const obj = { val: 10 }; console.log(obj.val); 这里, console.log() 表达式在对象 obj 上执行 get 方法来获取 val 的值。 另一个对象的基本操作方法是 set 。 const obj = { val: 10 }; obj.val2 = 20; 这里, set 方法用来给对象 obj 设置一个新的值。 如何创建Proxy? const proxiedObject = new Proxy(initialObj, handler); 调用Proxy构造函数, new Proxy() 将返回一个对象,不仅包含了 initialObj 里的值,而且其基本操作(如 get 和 set )现在可以通过 handler 对象来指定一些自定义逻辑。 我们写个例子来理解这个概念, const handler = { get: function() { console.log('A value has been