摘要: service ServiceSample.javapackage com.terry;import android.app.Service;import android.content.Intent;import android.os.IBinder;import android.util.Log;public class ServiceSample extends Service {final String TAG="Service";@Overridepublic IBinder onBind(Intent intent) {// TODO Auto-generate 阅读全文
posted @ 2013-12-19 13:54 爱编程hao123 阅读(1337) 评论(0) 推荐(0) 编辑
摘要: 工程下个AndroidManifest.xml,所有的Activity都要在里面注册,其中那个Activity中含有 这些代码,那个Activity为该工程的入口,即第一个运行这个Activity 阅读全文
posted @ 2013-12-19 11:34 爱编程hao123 阅读(474) 评论(0) 推荐(0) 编辑
摘要: package com.terry;import android.app.Service;import android.content.Intent;import android.os.IBinder;import android.util.Log;public class ServiceSample extends Service {final String TAG="Service";@Overridepublic IBinder onBind(Intent intent) { //onBind(intent)// TODO Auto-generated method 阅读全文
posted @ 2013-12-19 09:40 爱编程hao123 阅读(388) 评论(0) 推荐(0) 编辑
摘要: 前两节中可以看到Activity和Service,context.startService对应着Service中的onStart()方法,context.onBindService对应的是Service中的onBind()方法。当我们继想绑定一个Service又想在Activity停止时,Service不会停止,我们可以先StartService,然后再BindService()。这时候的流程图如下所示:点击查看大图此时需要注意一个问题,当Activity退出的时候,Sercvice并不会停止,此时我们可以再进入Activity重新绑定,当这时候Service就会调用onRebind()方法, 阅读全文
posted @ 2013-12-19 09:32 爱编程hao123 阅读(701) 评论(0) 推荐(0) 编辑
摘要: android.util.Log常用的方法有以下5个:Log.v() Log.d() Log.i() Log.w() 以及 Log.e() 。根据首字母对应VERBOSE,DEBUG,INFO, WARN,ERROR。 1、Log.v 的调试颜色为黑色的,任何消息都会输出,这里的v代表verbose啰嗦的意思,平时使用就是Log.v("",""); 2、Log.d的输出颜色是蓝色的,仅输出debug调试的意思,但他会输出上层的信息,过滤起来可以通过DDMS的Logcat标签来选择; 3、Log.i的输出为绿色,一般提示性的消息information,它不 阅读全文
posted @ 2013-12-19 09:23 爱编程hao123 阅读(256) 评论(0) 推荐(0) 编辑