【3D技术宅公社】XR数字艺术论坛  XR技术讨论 XR互动电影 定格动画

 找回密码
 立即注册

QQ登录

只需一步,快速开始

调查问卷
论坛即将给大家带来全新的技术服务,面向三围图形学、游戏、动画的全新服务论坛升级为UTF8版本后,中文用户名和用户密码中有中文的都无法登陆,请发邮件到324007255(at)QQ.com联系手动修改密码

3D技术论坛将以计算机图形学为核心,面向教育 推出国内的三维教育引擎该项目在持续研发当中,感谢大家的关注。

查看: 1741|回复: 0

Android 的 Remote Service 开发实例

[复制链接]
发表于 2013-1-24 18:03:21 | 显示全部楼层 |阅读模式
[文件] RemoteService.zip ~ 47KB    下载(285)
[文件] RemoteServiceClient.zip ~ 61KB    下载(283)
  1. private void startService(){
  2.      if (started) {
  3.        Toast.makeText(RemoteServiceClient.this, "Service already started", Toast.LENGTH_SHORT).show();
  4.      } else {
  5.        Intent i = new Intent();
  6.        i.setClassName("com.collabera.labs.sai", "com.collabera.labs.sai.RemoteService");
  7.        startService(i);
  8.        started = true;
  9.        updateServiceStatus();
  10.        Log.d( getClass().getSimpleName(), "startService()" );
  11.       }
  12.                  
  13.   }

  14. private void bindService() {
  15.      if(conn == null) {
  16.         conn = new RemoteServiceConnection();
  17.         Intent i = new Intent();
  18.         i.setClassName("com.collabera.labs.sai", "com.collabera.labs.sai.RemoteService");
  19.         bindService(i, conn, Context.BIND_AUTO_CREATE);
  20.         updateServiceStatus();
  21.         Log.d( getClass().getSimpleName(), "bindService()" );
  22.      } else {
  23.        Toast.makeText(RemoteServiceClient.this, "Cannot bind - service already bound", Toast.LENGTH_SHORT).show();
  24.      }
  25. }

  26. private void invokeService() {
  27.      if(conn == null) {
  28.         Toast.makeText(RemoteServiceClient.this, "Cannot invoke - service not bound", Toast.LENGTH_SHORT).show();
  29.      } else {
  30.         try {
  31.             int counter = remoteService.getCounter();
  32.             TextView t = (TextView)findViewById(R.id.notApplicable);
  33.             t.setText( "Counter value: "+Integer.toString( counter ) );
  34.             Log.d( getClass().getSimpleName(), "invokeService()" );
  35.         } catch (RemoteException re) {
  36.             Log.e( getClass().getSimpleName(), "RemoteException" );
  37.         }
  38.      }
  39. }     

  40. private void releaseService() {
  41.       if(conn != null) {
  42.             unbindService(conn);
  43.             conn = null;
  44.             updateServiceStatus();
  45.             Log.d( getClass().getSimpleName(), "releaseService()" );
  46.       } else {
  47.             Toast.makeText(RemoteServiceClient.this, "Cannot unbind - service not bound", Toast.LENGTH_SHORT).show();
  48.       }
  49. }


  50. private void stopService() {
  51.       if (!started) {
  52.             Toast.makeText(RemoteServiceClient.this, "Service not yet started", Toast.LENGTH_SHORT).show();
  53.       } else {
  54.             Intent i = new Intent();
  55.             i.setClassName("com.collabera.labs.sai", "com.collabera.labs.sai.RemoteService");
  56.             stopService(i);
  57.             started = false;
  58.             updateServiceStatus();
  59.             Log.d( getClass().getSimpleName(), "stopService()" );
  60.       }
  61. }
复制代码


您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|3D数字艺术论坛 ( 沪ICP备14023054号 )

GMT+8, 2025-5-6 14:22

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表