上一页 1 ··· 6 7 8 9 10 11 下一页
摘要: 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) 编辑
摘要: AndroidManifest.xml //在这个文件中建立service标签 //建立service标签名称是wudi 这个地方的名称就是 com.example.ok2中的程序.java文件名称 //建立动作名称 在程序中运行名字叫".player2"的intent 就可以调用上面的.java文件 MainActivity.java 文件package com.example.ok2;import android.os.Bundle;import android.app.Activity;import android.view.Menu;import andro... 阅读全文
posted @ 2013-12-18 17:20 爱编程hao123 阅读(305) 评论(0) 推荐(0) 编辑
摘要: //声明service时出现警告提示 在和中加入android:exported="false",就可以了android:exported="false" 不允许外部程序引用,"true" 允许外部程序引用 阅读全文
posted @ 2013-12-17 16:44 爱编程hao123 阅读(276) 评论(0) 推荐(0) 编辑
摘要: Activity1protected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);Button button=new Button(this);button.setOnClickListener(new OnClickListener(){public void onClick(View v){Intent intent=new Intent(); //声明intentintent.setClass(Main 阅读全文
posted @ 2013-12-16 15:28 爱编程hao123 阅读(620) 评论(0) 推荐(0) 编辑
摘要: 从源 Activity 中传递数据 Intent intent=new Intent(); //建立一个IntentBundle bundle=new Bundle(); //建立一个Bundlebundle.putString("key_1","这是一"); //向Bundle中放入参数值bundle.putString("key_2","这是二"); //向Bundle中放入参数值intent.putExtras(bundle); //把Bundle附加到Intent中intent.setClass(MainA 阅读全文
posted @ 2013-12-16 11:58 爱编程hao123 阅读(313) 评论(0) 推荐(0) 编辑
摘要: 主activity:MainActivity.java 代码:package com.example.wudi;import android.os.Bundle;import android.app.Activity;import android.view.Menu;import android.widget.Button;import android.view.View;import android.view.View.OnClickListener;import android.content.Intent;public class MainActivity extends Activit 阅读全文
posted @ 2013-12-16 10:02 爱编程hao123 阅读(4898) 评论(0) 推荐(0) 编辑
上一页 1 ··· 6 7 8 9 10 11 下一页