Android中action的定义
来源:互联网 发布:2017旅行软件比例 编辑:程序博客网 时间:2024/06/05 17:54
一、在AndroidManifest.xml中定义action事件
<serviceandroid:name=".service.NettyService"> <intent-filter> <action android:name="com.hovans.netty.ACTION_CHECK_SESSION" /> <action android:name="com.hovans.netty.ACTION_HEARTBEAT" /> <action android:name="com.hovans.netty.ACTION_CONNECT_SESSION" /> <action android:name="com.hovans.netty.ACTION_DISCONNECT_SESSION" /> </intent-filter> </service>
二、定义一个Intent类
public class NettyIntent {public static final String ACTION_CHECK_SESSION = "com.hovans.netty.ACTION_CHECK_SESSION";public static final String ACTION_HEARTBEAT = "com.hovans.netty.ACTION_HEARTBEAT";public static final String ACTION_CONNECT_SESSION = "com.hovans.netty.ACTION_CONNECT_SESSION";public static final String ACTION_DISCONNECT_SESSION = "com.hovans.netty.ACTION_DISCONNECT_SESSION";}
三、action出发示例代码:
public void onStartClick(View view) {System.out.println("duanliang,HomeActivity.onStartClick");startService(new Intent(NettyIntent.ACTION_CONNECT_SESSION));}
四、action响应示例代码:
public void onWorkerRequest(Intent intent, int i) {if (NettyIntent.ACTION_CONNECT_SESSION.equals(intent.getAction())) {if(mChannel != null) {disconnectSessionIfItNeeds();}connectSessionIfItNeeds();} else if(NettyIntent.ACTION_HEARTBEAT.equals(intent.getAction())) {if(checkConnection() == false) {connectSessionIfItNeeds();}} else if(NettyIntent.ACTION_CHECK_SESSION.equals(intent.getAction())) {scheduleToReconnect();} else if(NettyIntent.ACTION_DISCONNECT_SESSION.equals(intent.getAction())) {disconnectSessionIfItNeeds();}}
其中onWorkerRequest(Intent intent, int i)的定义见博文(待补充)
0 0
- Android中action的定义
- GC action的定义
- 在action中定义的方法一定要注意的事项
- ACTION中定义的变量,如何传值到JSP页面?
- ACTION中定义的变量,怎么传值到JSP页面
- ACTION中定义的变量,怎么传值到JSP页面
- Android中全局变量的定义
- android中颜色的定义
- Android中applicationId的定义
- Permission、action的定义方式
- Android中两个ACTION常量的说明
- android.provider.Settings中常见的Action
- Android中Action Bar的使用
- Android中Intent的Action和权限
- Android中常用Action
- Android 中 Intent.Action
- struts2.xml配置了defaultStack时action中定义的字段无法接收值的解决方法
- 在jsp的<s:iterator>标签中获取action中的定义的成员变量
- 程序设计第二题
- 身心
- 王垠的「40 行代码」真如他说的那么厉害吗?
- 发挥巨大设计好的就撒谎的
- php获取文章上一页与下一页的方法
- Android中action的定义
- 飞机和大家爱回家的挥洒
- Android优化之优化Java代码
- 字符串长度计算
- ELF结构详细分析(1)---elf32_hdr
- 房价会打架撒活动就撒谎
- R语言中的线性判别分析
- ewqeqwfdfsdfzsd
- 数据结构(C++)课程设计 3号题