当前位置:  c/c++ iis7站长之家
本页文章导读:
    ▪搜集的两个比较好的andriod视频下载链接        收集的两个比较好的andriod视频下载链接 http://edu.csdn.net/news/2012822/94c48aab2574.shtml     http://bbs.itheima.com/thread-60883-1-1.html?130809fstedm ......
    ▪ 访问当地服务里面的方法        访问本地服务里面的方法原理图: 步骤: 调用服务里面的方法: 1 设计一个接口:IStudentQueryService   Student queryStudent(int no); 2 在activity里面进行绑定操作:   bindService(intent,conn,flag); 3 写一.........
    ▪ 一个公司的治理之三:在公布任何的任命、制度之前一定要三思       一个公司的管理之三:在公布任何的任命、制度之前一定要三思       今天吸取了一个教训,任何的任命和公布制度之前一定要想好进路和退路,进路当然不用特意去想就能知道,这个人上.........

[1]搜集的两个比较好的andriod视频下载链接
    来源: 互联网  发布时间: 2014-02-18
收集的两个比较好的andriod视频下载链接

http://edu.csdn.net/news/2012822/94c48aab2574.shtml

 

 

http://bbs.itheima.com/thread-60883-1-1.html?130809fstedm


    
[2] 访问当地服务里面的方法
    来源: 互联网  发布时间: 2014-02-18
访问本地服务里面的方法

原理图:



步骤:

调用服务里面的方法:
1 设计一个接口:IStudentQueryService   Student queryStudent(int no);
2 在activity里面进行绑定操作:
  bindService(intent,conn,flag);
3 写一个连接实现类:
    private final class MyServiceConnection implements ServiceConnection{


public void onServiceConnected(ComponentName name, IBinder service) {
// TODO Auto-generated method stub
ibinder = (IStudnetQueryService) service;
}


public void onServiceDisconnected(ComponentName name) {
// TODO Auto-generated method stub
conn = null;
ibinder = null;
}
   
    }
4 在activity里面用IStudentQueryService 来接收onServiceConnected(ComponentName name, IBinder service)
  返回过来的IBinder对象。


5 写一个StudentService  extends  Service  ,重写onBind()
  编译一个内部类StudentBinder extends Binder  implements IStudnetQueryService


6  创建StudentBinder的对象,通过onBind()方法返回。
7  在activity通过onBind()返回的对象调用服务里面的方法。



代码如下:

1、main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >
    
    <TextView 
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="学号"
        />
    
    <EditText 
        android:id="@+id/et_no"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:inputType="number"
        />
    
    <Button 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="查询"
        android:onClick="query1"
        />
    
    <TextView  
        android:id="@+id/tv_info"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        />
    
</LinearLayout>


2、MainActivity

package com.njupt.studentquery1;

import android.os.Bundle;
import android.os.IBinder;
import android.app.Activity;
import android.content.ComponentName;
import android.content.Intent;
import android.content.ServiceConnection;
import android.view.Menu;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

public class MainActivity extends Activity {

	private EditText et_no;
	private TextView tv_info;
	private MyServiceConnection conn;
	private IStudentQueryService ibinder;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
	    
		et_no = (EditText) findViewById(R.id.et_no);
		tv_info = (TextView) findViewById(R.id.tv_info);
		conn = new MyServiceConnection();
		
		Intent intent = new Intent(this,StudentService.class);
		bindService(intent,conn,BIND_AUTO_CREATE);
	}

	private class MyServiceConnection implements ServiceConnection{
		@Override
		public void onServiceConnected(ComponentName name, IBinder service) {
			ibinder = (IStudentQueryService) service;
		}
		
		@Override
		public void onServiceDisconnected(ComponentName name) {
			ibinder = null;
			conn = null;
		}
	}
	
	@Override
	protected void onDestroy() {
		super.onDestroy();
	    
		unbindService(conn);
	}
	
	public void query1(View v){
		String no = et_no.getText().toString();
		Student student = ibinder.queryStudent(Integer.parseInt(no));
		tv_info.setText(student.toString());
		
	}
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

}


3、StudentService

package com.njupt.studentquery1;

import android.app.Service;
import android.content.Intent;
import android.os.Binder;
import android.os.IBinder;

public class StudentService extends Service {

	private StudentBinder ibinder = new StudentBinder();
	private Student[] students = new Student[]{
		new Student(1,"章泽天",21),
		new Student(2,"刘诗诗",22),
		new Student(3,"allen",21)
	};
	
	@Override
	public IBinder onBind(Intent intent) {
		return ibinder;
	}
	
	private class StudentBinder extends Binder implements IStudentQueryService{
		public Student queryStudent(int no){
			return query(no);
		}
	}

	public Student query(int no){
		return students[no - 1];
	}
	
}


4、IStudentQueryService

package com.njupt.studentquery1;

public interface IStudentQueryService {

	public Student queryStudent(int no);
}


5、Student

package com.njupt.studentquery1;

public class Student {

	private int id;
	private String name;
	private int age;
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public int getAge() {
		return age;
	}
	public void setAge(int age) {
		this.age = age;
	}
	public Student(int id, String name, int age) {
		super();
		this.id = id;
		this.name = name;
		this.age = age;
	}
	public Student() {
		super();
	}
	@Override
	public String toString() {
		return "Student [id=" + id + ", name=" + name + ", age=" + age + "]";
	}
	
	
}


6、AndroidManifest.xml

记得在清单文件中吧service 给注册上去

<service android:name="com.njupt.studentquery1.StudentService"/>



    
[3] 一个公司的治理之三:在公布任何的任命、制度之前一定要三思
    来源: 互联网  发布时间: 2014-02-18
一个公司的管理之三:在公布任何的任命、制度之前一定要三思
       今天吸取了一个教训,任何的任命和公布制度之前一定要想好进路和退路,进路当然不用特意去想就能知道,这个人上任或制度推出效果比较理想,那么如果不理想呢,是否知道接下来改如何去做呢?后面一点非常重要,有时候我们在考虑任命和制度的时候老给自己套个框框,按照自己理想化的思维去考虑问题,其实多数情况下事情的发展是不会随着我们的意志做转移的,那么我们至少要做到想好的方面也要考虑到坏的方面,我们想前一步也要考虑好退一步怎么办。所谓三思就是这个意思!这样也算是管理上做到游刃有余了!一点感受仅供参考,欢迎轻喷!

    
最新技术文章:
▪Android开发之登录验证实例教程
▪Android开发之注册登录方法示例
▪Android获取手机SIM卡运营商信息的方法
▪Android实现将已发送的短信写入短信数据库的...
▪Android发送短信功能代码
▪Android根据电话号码获得联系人头像实例代码
▪Android中GPS定位的用法实例
▪Android实现退出时关闭所有Activity的方法
▪Android实现文件的分割和组装
▪Android录音应用实例教程
▪Android双击返回键退出程序的实现方法
▪Android实现侦听电池状态显示、电量及充电动...
▪Android获取当前已连接的wifi信号强度的方法
▪Android实现动态显示或隐藏密码输入框的内容
▪根据USER-AGENT判断手机类型并跳转到相应的app...
▪Android Touch事件分发过程详解
▪Android中实现为TextView添加多个可点击的文本
▪Android程序设计之AIDL实例详解
▪Android显式启动与隐式启动Activity的区别介绍
▪Android按钮单击事件的四种常用写法总结
▪Android消息处理机制Looper和Handler详解
▪Android实现Back功能代码片段总结
▪Android实用的代码片段 常用代码总结
▪Android实现弹出键盘的方法
▪Android中通过view方式获取当前Activity的屏幕截...
▪Android提高之自定义Menu(TabMenu)实现方法
▪Android提高之多方向抽屉实现方法
▪Android提高之MediaPlayer播放网络音频的实现方法...
▪Android提高之MediaPlayer播放网络视频的实现方法...
▪Android提高之手游转电视游戏的模拟操控
 


站内导航:


特别声明:169IT网站部分信息来自互联网,如果侵犯您的权利,请及时告知,本站将立即删除!

©2012-2021,,E-mail:www_#163.com(请将#改为@)

浙ICP备11055608号-3