handler

Passing context to Handler

岁酱吖の 提交于 2019-12-04 09:52:28
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 probably because of this piece of code public BoardView(Context context){ super(context); Context is

Update UI in the main activity through handler in a thread (Android)

天大地大妈咪最大 提交于 2019-12-04 09:47:40
问题 I try to make several connection in a class and update the multiple progressbar in the main screen. But I've got the following error trying to use thread in android : Code: 05-06 13:13:11.092: ERROR/ConnectionManager(22854): ERROR:Can't create handler inside thread that has not called Looper.prepare() Here is a small part of my code in the main Activity public class Act_Main extends ListActivity { private ConnectionManager cm; public void onCreate(Bundle savedInstanceState) { super.onCreate

springmvc-拦截器

血红的双手。 提交于 2019-12-04 09:46:49
1. Spring MVC 的处理器拦截器类似于 Servlet 开发中的过滤器 Filter,用于对处理器进行预处理和后处理。 用户可以自己定义一些拦截器来实现特定的功能。 谈到拦截器,还要向大家提一个词——拦截器链(Interceptor Chain)。拦截器链就是将拦截器按一定的顺 序联结成一条链。在访问被拦截的方法或字段时,拦截器链中的拦截器就会按其之前定义的顺序被调用。 说到这里,可能大家脑海中有了一个疑问,这不是我们之前学的过滤器吗?是的它和过滤器是有几分相似,但 是也有区别,接下来我们就来说说他们的区别: 过滤器是 servlet 规范中的一部分, 任何 java web 工程都可以使用。 拦截器是 SpringMVC 框架自己的,只有使用了 SpringMVC 框架的工程才能用。 过滤器在 url-pattern 中配置了/*之后,可以对所有要访问的资源拦截。 拦截器它是只会拦截访问的控制器方法,如果访问的是 jsp, html,css,image 或者 js 是不会进行拦 截的。 它也是 AOP 思想的具体应用。 我们要想自定义拦截器, 要求必须实现: HandlerInterceptor 接口。 2.作用过程 拦截器的作用对象的controller,拦截器有个放行的功能,可以在放行之前和之后编写一些代码 预处理,在请求controller之前,会先经过拦截器

SpringMVC的执行流程

拟墨画扇 提交于 2019-12-04 09:32:53
一、核心模块 数据库访问技术与集成:JDBC、XML等 Web与远程调用技术:SpringMVC、WebServlet、WebSocket等 面向切面编程:AOP 基础设施:Tomcat Spring核心容器:Beans、Core、Context、Expression、ContestSupport 测试:Test 二、执行流程 1.用户通过页面发送Ajax之类的请求,DispatcherServlet捕获并解析用户发来的请求URL,得到请求资源标识符URI 2.DispatcherServlet根据URI调用HandlerMapping,HandlerMapping根据请求URL查找Handler,并将请求映射为HandlerExecutionChain处理器执行链(包含处理器拦截器和处理器对象) 3.HandlerMapping返回HandlerExecutionChain给DispatcherServlet 4.DispatcherServlet根据获得的Handler选择HandlerAdapter,通过处理器适配器调用具体的处理器,HandlerAdapter把处理器包装为适配器,并开始执行拦截器的preHandler()方法,并根据适配器的结果调用真正的处理器的功能处理方法 5.调用具体的处理器Handler,在填充Handler的入参过程中spring将会进行

Which thread does Runnable run on?

让人想犯罪 __ 提交于 2019-12-04 09:25:59
I want to update UI every 100ms. After searching in StackOverflow, I found a solution using Runnable and Handler like this final Handler handler = new Handler(); Runnable runnable = new Runnable() { @Override public void run() { //update UI here handler.postDelayed(this, 100); } }; runnable.run(); It works! But I have some questions: Which thread does this Runnable run on? MainThread or another thread? Here is the docs about postDelay Handler is attached MainThread, so is Runnable running on MainThread? If Runnable is running on MainThread, why needs Handler ? According to my knowledge,

logging模块

女生的网名这么多〃 提交于 2019-12-04 09:09:25
介绍 Python的logging模块提供了通用的日志系统,可以方便第三方模块或者是应用使用。这个模块提供不同的日志级别,并可以采用不同的方式记录日志,比如文件,HTTP GET/POST,SMTP,Socket等,甚至可以自己实现具体的日志记录方式 logging模块与log4j的机制是一样的,只是具体的实现细节不同。模块提供logger,handler,filter,formatter。 logger:提供日志接口,供应用代码使用。logger最长用的操作有两类:配置和发送日志消息。可以通过logging.getLogger(name)获取logger对象,如果不指定name则返回root对象,多次使用相同的name调用getLogger方法返回同一个logger对象。 handler:将日志记录(log record)发送到合适的目的地(destination),比如文件,socket等。一个logger对象可以通过addHandler方法添加0到多个handler,每个handler又可以定义不同日志级别,以实现日志分级过滤显示。 filter:提供一种优雅的方式决定一个日志记录是否发送到handler。 formatter:指定日志记录输出的具体格式。formatter的构造方法需要两个参数:消息的格式字符串和日期字符串,这两个参数都是可选的。 与log4j类似

Buuctf刷题(持续更新)

坚强是说给别人听的谎言 提交于 2019-12-04 09:07:08
前言 希望自己能够更加的努力,希望通过多刷大赛题来提高自己的知识面。(ง •_•)ง easy_tornado 进入题目 看到render就感觉可能是模板注入的东西 hints.txt给出提示,可以看到url中的filehash 呢么意思就是如果知道cookie_secret的话,再结合md5的filename就可以读到/flllllag了把 其实到这里我就没什么思路了,对于render肯定存在模板的问题,百度了一下标题tornado Tornado 是一种 Web 服务器软件的开源版本。Tornado 和现在的主流 Web 服务器框架(包括大多数 Python 的框架)有着明显的区别:它是非阻塞式服务器,而且速度相当快。 一搜,render组合tornado,全是这道题的题解,我惊了。。那就看着WP来复现把,而不是自己做出来。。。 随便删除了filehash后,跳到了这个页面。 可以看到msg参数,传入了Error,页面就显示Error,通过一般常用的{{}}来测试 通过查阅Tornado官方文档可以发现cookie_secret存在于 RequestHandler中 我们查阅资料发现 cookie_secret在RequestHandler.settings中 在 官方文档 中可以看到,在Tornado的前端页面模板中,Tornado提供了一些对象别名来快速访问对象。

Making changes to Main Activity UI from thread in Service

随声附和 提交于 2019-12-04 09:03:00
I've been looking for quite some time for some good documentation or a good example of this. I need to make changes to my main activity UI from the worker thread in my service which is running in the background. As far as I understand I know that I am suppose to work with some sort of Handler but I am not sure exactly how to approach this. Does anyone have any ideas or good examples that they could direct me to? The UI element I am changing is a TextView that is simply informing the user of the status of the thread. Thanks for your help. All you have to do is to create a Handler on the UI

logging模块

南楼画角 提交于 2019-12-04 07:56:31
logging模块 一、低配logging 日志总共分为以下五个级别,这个五个级别自下而上进行匹配 debug-->info-->warning-->error-->critical,默认最低级别为warning级别。 1.1 v1 import logging logging.debug('调试信息') logging.info('正常信息') logging.warning('警告信息') logging.error('报错信息') logging.critical('严重错误信息') WARNING:root:警告信息 ERROR:root:报错信息 CRITICAL:root:严重错误信息 v1版本无法指定日志的级别;无法指定日志的格式;只能往屏幕打印,无法写入文件。因此可以改成下述的代码。 1.2 v2 import logging # 日志的基本配置 logging.basicConfig(filename='access.log', format='%(asctime)s - %(name)s - %(levelname)s -%(module)s: %(message)s', datefmt='%Y-%m-%d %H:%M:%S %p', level=10) logging.debug('调试信息') # 10 logging.info('正常信息') # 20

我的vc笔记心得

点点圈 提交于 2019-12-04 07:52:56
位图 1. 准备图片: 下载好图片,另存为桌面,右击编辑,另存为 2. 创建单文档项目: 点击菜单项 插入-〉资源-〉Bitmap-〉引用 ,选择 全部文件,并选择创建好的 16位图 ondraw插入如下代码: void CBitmaptestView::OnDraw(CDC* pDC) { CBitmaptestDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); CBitmap Bitmap; Bitmap.LoadBitmap (IDB_BITMAP1); CDC MemDC; MemDC.CreateCompatibleDC(pDC); CBitmap * OldBitmap = MemDC.SelectObject(&Bitmap); BITMAP bm; Bitmap.GetBitmap(&bm); pDC->BitBlt(0,0,bm.bmWidth,bm.bmHeight,&MemDC,0,0,SRCCOPY); pDC->SelectObject(OldBitmap); // TODO: add draw code for native data here } 文字操作 1. 创建单文档项目: void CRrView::OnDraw(CDC* pDC) { CRrDoc* pDoc = GetDocument();