handler

Handlers and memory leaks in Android

孤者浪人 提交于 2019-12-17 08:09:13
问题 Please have a look at the code below: public class MyGridFragment extends Fragment{ Handler myhandler = new Handler() { @Override public void handleMessage(Message message) { switch (message.what) { case 2: { ArrayList<HashMap<String,String>> theurls = (ArrayList<HashMap<String,String>>) message.obj; urls.addAll(theurls); theimageAdapter.notifyDataSetChanged(); dismissBusyDialog(); break; }}}}; } When I use handler like this I get a warning "handler should be static, else it is prone to

How to create a Looper thread, then send it a message immediately?

爱⌒轻易说出口 提交于 2019-12-17 08:02:02
问题 I have a worker thread that sits in the background, processing messages. Something like this: class Worker extends Thread { public volatile Handler handler; // actually private, of course public void run() { Looper.prepare(); mHandler = new Handler() { // the Handler hooks up to the current Thread public boolean handleMessage(Message msg) { // ... } }; Looper.loop(); } } From the main thread (UI thread, not that it matters) I would like to do something like this: Worker worker = new Worker();

Does jQuery have a handleout for .delegate('hover')?

流过昼夜 提交于 2019-12-17 07:17:20
问题 I am trying to use: $('mydiv').delegate('hover', function() { $('seconddiv').show(); }, function() { //For some reason jQuery won't run this line of code $('seconddiv').hide(); }); 回答1: User113716's great answer will no longer work in jQuery 1.9+ , because the pseudo-event hover is no longer supported (upgrade guide). Also since jQuery 3.0 delegate() for binding events is officially deprecated, so please use the new on()(docs) for all event binding purposes. You can easily migrate user113716

TimerTask vs Thread.sleep vs Handler postDelayed - most accurate to call function every N milliseconds?

你离开我真会死。 提交于 2019-12-17 06:29:50
问题 What is the most accurate way to call a function every N milliseconds? Thread with Thread.sleep TimerTask Handler with postDelayed I modified this example using Thread.sleep and it's not very accurate. I'm developing a music app that will play sounds at a given BPM. I understand it's impossible to create an entirely accurate metronome and I don't need to - just looking to find the best way to do this. Thanks 回答1: There are some disadvantages of using Timer It creates only single thread to

Session,有没有必要使用它?

我的未来我决定 提交于 2019-12-17 03:09:59
原文地址: http://www.cnblogs.com/fish-li/archive/2011/07/31/2123191.html 阅读目录 开始 Session的来龙去脉 Session对并发访问的影响 Session的缺点总结 不使用Session的替代方法 Asp.net MVC 中的Session 现有的代码怎么办? 今天来说说 Session 。这个东西嘛,我想每个Asp.net开发人员都知道它,尤其是初学Asp.net时,肯定也用过它,因为用它保存会话数据确实非常简单。 与前二篇博客不同,这次我不打算细说它的使用,而是打算说说它的缺点,同时我还会举个实际的例子,来看看它到底有什么不好的影响。 当然了,光批评是没有意义,事情也得解决,没有会话也不行,所以,本文将也给出一个自认为能替代Session的解决方案。 回到顶部 Session的来龙去脉 当我们新建一个网站时,VS20XX 生成的网站模板代码中,Session就是打开。 是的,如果你没有关闭它,Session其实是一直在工作着。 您只需要在Page中用一行代码就能判断您的网站是否在使用Session, Session["key1"] = DateTime.Now; 很简单,就是写一下Session,如果代码能运行,不出现异常,就表示您的网站是支持Session的。我们可以去web.config从全局关闭它,

Jetty架构解析及应用示例

家住魔仙堡 提交于 2019-12-17 01:01:35
Jetty 是一个 Web server/servlet container, 支持 SPDY , WebSocket , OSGi , JMX , JNDI , JAAS 。Jetty非常高效而且灵活,Google App Engine 选择了Jetty,而放弃了Tomcat,或是其他的服务器。 Jetty has a slogan, "Don't deploy your application in Jetty, deploy Jetty in your application." What this means is that , putting an HTTP module into your application, rather than putting your application into an HTTP server. Jetty的口号是:“不要把你的程序部署到Jetty里,而是把Jetty部署到你的程序里”,意味着,你可以把Jetty当成程序的一个HTTP模块放到你的程序里。 本文先通过一个简单的HelloWorld示例,展示了java应用中的Jetty是如何启动的;接着详细分析了Jetty的整体架构;最后展示了用Jetty启动一个标准的Java web app。 Hello World 示例 需要的jar包: jetty-server-8.1.11

STM32启动过程简图

早过忘川 提交于 2019-12-16 19:57:34
STM32启动过程简图 以STM32F407为例,用一个简图介绍STM32的启动过程。如下: 对应的启动文件startup_stm32f40_41xxx.s的代码如下: ;******************** (C) COPYRIGHT 2013 STMicroelectronics ******************** ;* File Name : startup_stm32f40_41xxx.s ;* Author : MCD Application Team ;* Version : V1.2.1 ;* Date : 19-September-2013 ;* Description : STM32F40xxx/41xxx devices vector table for MDK-ARM toolchain. ;* This module performs: ;* - Set the initial SP ;* - Set the initial PC == Reset_Handler ;* - Set the vector table entries with the exceptions ISR address ;* - Configure the system clock and the external SRAM mounted on ;* STM324xG

Android常见内存泄漏的原因

删除回忆录丶 提交于 2019-12-16 17:38:58
内存泄漏概念:内存泄漏(Memory Leak)是指程序中己动态分配的堆内存由于某种原因程序未释放或无法释放,造成系统内存的浪费,导致程序运行速度减慢甚至系统崩溃等严重后果。 一、单例模式使用Activity作为Context 单例模式中应该避免使用Activity作为传入的Context,否则,单例模式会持有这个Activity的引用,导致它无法释放,造成内存泄漏。应该使用ApplicationContext作为Context传入。如果一定要使用Activity的话,要使用弱引用WeakReference。 二、未关闭资源或者没有反注册 BroadcastReceiver,File,Cursor,IO流等资源在 Activity 的onDestroy必须unregister 或者 close ,否则这个 Activity 类会被 system 强引用,不会被内存回收。关闭的语句必须在finally中进行关闭,否则有可能因为异常未关闭资源,致使activity泄漏。 三、Handler造成内存泄漏 只要 Handler 发送的 Message 尚未被处理,则该 Message 及发送它的 Handler 对象将被线程 MessageQueue 一直持有。特别是handler执行延迟任务。所以,Handler 的使用要尤为小心,否则将很容易导致内存泄露的发生。 public

设计模式--责任链模式

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-16 14:37:56
责任链模式: 在责任链模式里,很多对象由每一个对象对其下家的引用而连接起来形成一条链。请求在这个链上传递,直到链上的某一个对象决定处理此请求。发出这个请求的客户端并不知道链上的哪一个对象最终处理这个请求,这使得系统可以在不影响客户端的情况下动态地重新组织和分配责任。 组成结构: 抽象处理者(Handler)角色:定义出一个处理请求的接口。如果需要,接口可以定义 出一个方法以设定和返回对下家的引用。这个角色通常由一个Java抽象类或者Java接口实现。上图中Handler类的聚合关系给出了具体子类对下家的引用,抽象方法handleRequest()规范了子类处理请求的操作。 具体处理者(ConcreteHandler)角色:具体处理者接到请求后,可以选择将请求处理掉,或者将请求传给下家。由于具体处理者持有对下家的引用,因此,如果需要,具体处理者可以访问下家。 类图: 代码实现: public abstract class Handler { public Handler successor; public abstract void handleRequest(); public void setSuccessor(Handler successor) { this.successor = successor; } } public class ConcreteHandlerA

Spring MVC源码阅读笔记

主宰稳场 提交于 2019-12-16 12:38:07
刷了一遍spring mvc源码,记录一下,写的可能有点乱。 DispatcherServlet的核心方法为doDispatch,上图中的流程基本都在doDispatch中完成,下面贴上源码 /** * Process the actual dispatching to the handler. * <p>The handler will be obtained by applying the servlet's HandlerMappings in order. * The HandlerAdapter will be obtained by querying the servlet's installed HandlerAdapters * to find the first that supports the handler class. * <p>All HTTP methods are handled by this method. It's up to HandlerAdapters or handlers * themselves to decide which methods are acceptable. * @param request current HTTP request * @param response current HTTP response *