当前位置:  编程技术>移动开发
本页文章导读:
    ▪为啥要使用service        为什么要使用service      android 中使用service主要是作一些费时的,影响用户体验的操作。但是service实际上也是运行在主线程中,你如果不再serivce中新作线程来进行以上的费时操作的话,一.........
    ▪ andorid openGL 的简略使用        andorid openGL 的简单使用 mainActivity:public class OpenGLDemoActivity extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInst.........
    ▪ Andorid课程视频       Andorid教程视频 http://v.youku.com/v_playlist/f4889604o1p1.html ......

[1]为啥要使用service
    来源: 互联网  发布时间: 2014-02-18
为什么要使用service

     android 中使用service主要是作一些费时的,影响用户体验的操作。但是service实际上也是运行在主线程中,你如果不再serivce中新作线程来进行以上的费时操作的话,一样会影响用户的操作。

     这个地方一直很疑惑?既然都是作thread来作费时的操作为什么还要作service呢。

     参阅了guide上的这篇文章《Processes and Threads》,明白了android 对老进程的销毁原则:service的重要度要大于activity,因此对于一些运行在后台的线程,应该声明在service中,以避免被系统销毁。

     以下是原文中的一段解释:

Because a process running a service is ranked higher than a process with background activities, an activity that initiates a long-running operation might do well to start a service for that operation, rather than simply create a worker thread—particularly if the operation will likely outlast the activity. For example, an activity that's uploading a picture to a web site should start a service to perform the upload so that the upload can continue in the background even if the user leaves the activity. Using a service guarantees that the operation will have at least "service process" priority, regardless of what happens to the activity. This is the same reason that broadcast receivers should employ services rather than simply put time-consuming operations in a thread.


    
[2] andorid openGL 的简略使用
    来源: 互联网  发布时间: 2014-02-18
andorid openGL 的简单使用

mainActivity:public class OpenGLDemoActivity extends Activity {

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
//        需要借助GLSurfaceView来渲染Render
        GLSurfaceView mGlSurfaceView = new GLSurfaceView(this);  
        mGlSurfaceView.setRenderer(new TriggleRender());  
       // mGlSurfaceView.setRenderMode()
        setContentView(mGlSurfaceView);
      
    }
}

 Render的实现类:

public class TriggleRender implements Renderer {

	@Override
	public void onDrawFrame(GL10 gl) {
		// TODO Auto-generated method stub

			ByteBuffer vbb= ByteBuffer.allocateDirect(vertexArray.length*4);
			vbb.order(ByteOrder.nativeOrder());
			FloatBuffer vertex = vbb.asFloatBuffer();
			vertex.put(vertexArray);
			vertex.position(0);

			gl.glLoadIdentity();
			gl.glTranslatef(0, 0, -4);

			gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);

			gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertex);
			index++;
			index%=10;
			switch(index){
			case 0:
			case 1:
			case 2:
			gl.glColor4f(1.0f, 0.0f, 0.0f, 1.0f);
			gl.glDrawArrays(GL10.GL_TRIANGLES, 0, 6);
			break;
			case 3:
			case 4:
			case 5:
			gl.glColor4f(0.0f, 1.0f, 0.0f, 1.0f);
			gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0, 6);
			break;
			case 6:
			case 7:
			case 8:
			case 9:
			gl.glColor4f(0.0f, 0.0f, 1.0f, 1.0f);
			gl.glDrawArrays(GL10.GL_TRIANGLE_FAN, 0, 6);
			break;
			}

			gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);

			} 

	@Override
	public void onSurfaceChanged(GL10 gl, int width, int height) {
		// TODO Auto-generated method stub
	//这句没有,不能显示效果	
       gl.glViewport(0, 0, width, height);
	}

	@Override
	public void onSurfaceCreated(GL10 gl, EGLConfig config) {
		// TODO Auto-generated method stub

	}
	float vertexArray[] = {
			-0.8f, -0.4f * 1.732f, 0.0f,
			0.0f, -0.4f * 1.732f, 0.0f,
			-0.4f, 0.4f * 1.732f, 0.0f,

			0.0f, -0.0f * 1.732f, 0.0f,
			0.8f, -0.0f * 1.732f, 0.0f,
			0.4f, 0.4f * 1.732f, 0.0f,
			}; 
	int index=0;
}

 

 

此类为画线段:

public class OpenGLRender implements Renderer {

	@Override
	public void onDrawFrame(GL10 gl) {
		// TODO Auto-generated method stub
		ByteBuffer vbb= ByteBuffer.allocateDirect(vertexArray.length*4);
		vbb.order(ByteOrder.nativeOrder());
		FloatBuffer vertex = vbb.asFloatBuffer();
		vertex.put(vertexArray);
		vertex.position(0);

		gl.glLoadIdentity();
		gl.glTranslatef(0, 0, -4);

		gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);

		gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertex);
		index++;
		index%=10;
		switch(index){
		case 0:
		case 1:
		case 2:
		gl.glColor4f(1.0f, 0.0f, 0.0f, 1.0f);
		gl.glDrawArrays(GL10.GL_LINES, 0, 4);
		break;
		case 3:
		case 4:
		case 5:
		gl.glColor4f(0.0f, 1.0f, 0.0f, 1.0f);
		gl.glDrawArrays(GL10.GL_LINE_STRIP, 0, 4);
		break;
		case 6:
		case 7:
		case 8:
		case 9:
		gl.glColor4f(0.0f, 0.0f, 1.0f, 1.0f);
		gl.glDrawArrays(GL10.GL_LINE_LOOP, 0, 4);
		break;
		}

		gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
	}

	@Override
	public void onSurfaceChanged(GL10 arg0, int width, int height) {
		// TODO Auto-generated method stub
		arg0.glViewport(0, 0, width, height);
	}

	@Override
	public void onSurfaceCreated(GL10 gl, EGLConfig arg1) {
		// TODO Auto-generated method stub
		// gl.glClearColor(0.9f, 0.2f, 0.2f, 1.0f);  
	    // gl.glClear(GL10.GL_COLOR_BUFFER_BIT);  
	}
	float vertexArray[] = {
			-0.8f, -0.4f * 1.732f, 0.0f,
			-0.4f, 0.4f * 1.732f, 0.0f,
			0.0f, -0.4f * 1.732f, 0.0f,
			0.4f, 0.4f * 1.732f, 0.0f,
			}; 

	int index=0;

 

 

参考自:eoeAndroid上的文章


    
[3] Andorid课程视频
    来源: 互联网  发布时间: 2014-02-18
Andorid教程视频
http://v.youku.com/v_playlist/f4889604o1p1.html

    
最新技术文章:
▪Android开发之登录验证实例教程
▪Android开发之注册登录方法示例
▪Android获取手机SIM卡运营商信息的方法
▪Android实现将已发送的短信写入短信数据库的...
▪Android发送短信功能代码
▪Android根据电话号码获得联系人头像实例代码
▪Android中GPS定位的用法实例
▪Android实现退出时关闭所有Activity的方法
php开源软件 iis7站长之家
▪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