handler

ScoreNinja causes java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()

依然范特西╮ 提交于 2019-12-20 02:52:08
问题 I'm trying to add ScoreNinja, the global high score system, to my Android game, and it works fine when I load it on my phone, but when I release it into the wild, I got crash reports saying: java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare() Here is part of the call stack: android.os.Handler.<init>(Handler.java:121) android.app.Dialog.<init>(Dialog.java:99) android.app.AlertDialog.<init>(AlertDialog.java:65) android.app.AlertDialog.<init>

HTTP请求处理流程-SpringMvc

柔情痞子 提交于 2019-12-20 00:31:28
1、在SpringMVC的http请求处理过程中,包括了前端控制器(DispatcherServlet)、处理映射器(HandlerMapping)、处理适配器(HandlerAdapter)、处理器((Handler)Controller)、视图解析器(ViewReslover)、视图(View)这六大主要对象。他们负责对http请求做处理,具体流程如下图。 第一步:前端控制器dispatcher接受请求 Client---url--->Dispatcher 第二步:前端控制器去发起handler映射查找请求 Dispatcher---HttpServletRequest---> HandlerMapping 第三步:处理器映射器查找hanlder并返回HandlerExetuionChain Dispatcher <---HandlerExeutionChain---HandlerMapping 第四步:前端控制器发起请求处理器适配器请求执行 Dispatcher---Handler---> HandlerAdapter 第五步:处理器适配器去调用handler执行 HandlerAdapter---HttpServletRequest> Handler(Controller) 第六步:处理器处理后返回ModelAndView给HandlerAdapter

OkHttp基本使用

我是研究僧i 提交于 2019-12-19 21:05:47
OkHttp介绍 Android系统提供了两种HTTP通信类,HttpURLConnection和HttpClient,HttpURLConnection相对来说比HttpClient难用,google自从2.3版本之后一直推荐使用HttpURLConnection,并且在6.0版本的sdk中直接删掉了HttpClient类。 但是, 上面两个类库和OkHttp比起来就弱爆了, 因为OkHttp不仅具有高效的请求效率,并且节省宽带, 还提供了很多开箱即用的网络疑难杂症解决方案.(据说Android4.4的源码中可以看到OkHttp替换了HttpURLConnection) 支持HTTP/2, HTTP/2通过使用多路复用技术在一个单独的TCP连接上支持并发, 通过在一个连接上一次性发送多个请求来发送或接收数据 如果HTTP/2不可用, 连接池减少请求延迟 支持GZIP, 可以压缩下载体积 响应缓存可以避免重复请求网络 会从很多常用的连接问题中自动恢复,如果您的服务器配置了多个IP地址,当第一个IP连接失败的时候,OkHttp会自动尝试下一个IP OkHttp还处理了代理服务器问题和SSL握手失败问题 OkHttp基本使用 概述 前面的内容介绍了OkHttp,本章就来教大家okhttp的基本使用,学了这些基本东西之后,大家有其他的需求可以自行扩展。以下的所有请求都是异步请求服务器

Handler源码分析

蹲街弑〆低调 提交于 2019-12-19 19:39:11
Handler源码分析 Activity启动时的Looper 当程序运行时,会先执行 ActivityThread 的 main 方法。会执行 Looper.prepareMainLooper() 方法和 Looper.loop() 方法。 Looper.prepareMainLooper() public static void prepareMainLooper ( ) { prepare ( false ) ; synchronized ( Looper . class ) { if ( sMainLooper != null ) { throw new IllegalStateException ( "The main Looper has already been prepared." ) ; } sMainLooper = myLooper ( ) ; } } 其中又会进入 prepare 方法中,会发现调用了 sThreadLocal.set(new Looper(quitAllowed)); 其中通过 new Looper() 方法 private Looper ( boolean quitAllowed ) { mQueue = new MessageQueue ( quitAllowed ) ; mThread = Thread . currentThread

Mediaplayer and delay in playing

人走茶凉 提交于 2019-12-19 10:52:45
问题 I create small application which is media player. I have method where I have a song. I want to delay playing sound after I clicked a button. How I can do this delay. I want to click on the button and after 5 seconds music is playing. I am using: MediaPlayer.create to get song and mediaplayer.start() to start playing, but I don;t know how I can delay start playing my song. 回答1: Use a Handler in your Activity to delay events such as starting the mediaplayer in your case: private RefreshHandler

Android 2.1: Muliple Handlers in a Single Activity

女生的网名这么多〃 提交于 2019-12-19 10:27:21
问题 I've more than one Handlers in an Activity. I create all the handlers in the onCreate() of the main activity. My understanding is the handleMessage() method of each handler will never be called at the same time because all messages are put in the same queue (the Activity thread MessageQueue). Therefore, they will be executed in the order in which are put into the Queue. They will also be executed in the main activity thread. Is this correct ? public void onCreate() { this.handler1 = new

Eclipse Luna: Handlers' @CanExecute methods not called

柔情痞子 提交于 2019-12-19 09:46:47
问题 I'm having a problem with command handlers in Eclipse Luna RCP. In my E4 application model, I defined some commands and related handlers that must be enabled only under certain circumstances. For this reason, in my handler POJOs, I implemented methods annotated with @CanExecute where I check the required conditions. I also defined menu and toolbar items associated with those commands. The problem is that my @CanExecute methods aren't properly invoked and, as a consequence, menu and toolbar

android系列之BroadcastReceiver的工作过程

纵饮孤独 提交于 2019-12-19 09:38:05
一:广播的注册过程 广播的动态注册过程是从 ContextWrapper 的 registerReceiver 方法开始的.代码如下: ContextWrapper 的 registerReceiver方法并没有做实际的工作,而是把注册过程交给了 ContextImpl 来完成 public Intent registerReceiver( BroadcastReceiver receiver, IntentFilter filter) { return mBase.registerReceiver(receiver, filter); } 下面是 ContextImpl的registerRceciver方法: registerRceciver调用了registerReceiverInternal方法。 public Intent registerReceiver(BroadcastReceiver receiver, IntentFilter filter) { return registerReceiver(receiver, filter, null, null); } @Override public Intent registerReceiver(BroadcastReceiver receiver, IntentFilter filter, String

Update View at runtime in Android

戏子无情 提交于 2019-12-19 09:19:21
问题 The example is pretty straightforward: i want to let the user know about what the app is doing by just showing a text (canvas.drawText()). Then, my first message appears, but not the other ones. I mean, i have a "setText" method but it doesn't updates. onCreate(Bundle bundle) { super.onCreate(bundle); setContentView(splash); // splash is the view class loadResources(); splash.setText("this"); boundWebService(); splash.setText("that"): etc(); splash.setText("so on"); } The view's text drawing

char device catch multiple (int) ioctl-arguments

十年热恋 提交于 2019-12-19 04:09:32
问题 I have to write a linux char device, which handles ioctl (without BKL) functions per unlock_ioctl. At the moment I can receive one argument from the userspace ioctl command per __get_user(myint, (int __user *) arg); How can I receive multiple int-arguments (for example this call)?: ioctl(fp, SZ_NEW_DEV_FORMAT, 0, 1, 30); 回答1: Yes, you have to use structures. For a particular ioctl command there will be some predefined arguments. You need to wrap these all arguments into a structure object and