CatchLog 关键字搜索(往service传值,service取值)
来源:互联网 发布:阿里云域名绑定服务器 编辑:程序博客网 时间:2024/05/22 09:55
记录一点:某项工作做到一定程度之后,如果要修改一定要备份一下,无聊是个工程还是个txt!
首先学习到的是,通过intent发送值给service。
public void onClick(DialogInterface dialog, int whichButton) {EditText keyWordText = (EditText) view.findViewById(R.id.input_keyword_edittext);String keyWord=keyWordText.getText().toString(); //获取输入的关键字Toast.makeText(MainActivity.this, "开始关键字"+keyWord+"搜索", Toast.LENGTH_SHORT).show();bundle=new Bundle();bundle.putString("keyWord", keyWord);keyWordIntent=new Intent();keyWordIntent.putExtras(bundle);keyWordIntent.setClass(MainActivity.this, SearchKeyWordService.class);startService(keyWordIntent);registerLogBroadcastReceiver();startBtn.setEnabled(false);stopBtn.setEnabled(true);logTag=keyWordLog; //设置标识为关键字搜索log信息}
但是从service里读取值的时候并不是像网上说的intent.getIntent().getExtras()。因为在onCreate里甚至没有getIntent()这个函数可以调用。可以采用onStart()(2.0之前?)函数,或者onStartCommand()函数,参考如下。
public int onStartCommand(Intent intent, int flags, int startId) {// TODO Auto-generated method stubBundle getBundle = intent.getExtras(); //获取关键字keyWord=getBundle.getString("keyWord"); return super.onStartCommand(intent, flags, startId);}
- CatchLog 关键字搜索(往service传值,service取值)
- Service
- Service
- service
- Service
- service
- Service
- Service
- service
- Service
- Service
- Service
- service
- service
- Service
- Service
- Service
- Service
- 第2.3节 android目录中manifest的介绍
- Struts中<logic:present><logic:iterator>的使用
- POJ 2175 Evacuation Plan 最小费用流 消负圈
- JS 技巧小全
- 遍历文件夹读取文件夹中图片并分页显示图片
- CatchLog 关键字搜索(往service传值,service取值)
- 存储引擎基础知识]InnoDB与MyISAM的六大区别
- nyist 21 三个水杯(BFS)
- android平台下使用点九PNG技术
- android onActivityResult
- 将eclipse java程序打包成jar的总结(包括工程中没有引用外部jar包和有引用外部jar包两种情况)
- Android:Fast ListView scroll without ViewHolder Pattern
- CSVreader和POI操作用法比较,以及CSVReader的坑
- fork和vfork与进程和子进程