交互服务交互式网站是什么意思思

2012年10月 其他开发语言大版内专家分月排行榜第二2011年7月 其他开发语言大版内专家分月排行榜第二2010年3月 其他开发语言大版内专家分月排行榜第二2007年10月 其他开发语言大版内专家分月排行榜第二2007年9月 其他开发语言大版内专家分月排行榜第二2005年3月 Windows专区大版内专家分月排行榜第二2005年2月 Windows专区大版内专家分月排行榜第二2005年6月 扩充话题大版内专家分月排行榜第二2006年9月 其他开发语言大版内专家分月排行榜第二2006年5月 其他开发语言大版内专家分月排行榜第二2006年3月 其他开发语言大版内专家分月排行榜第二2006年2月 其他开发语言大版内专家分月排行榜第二2005年12月 其他开发语言大版内专家分月排行榜第二2005年4月 其他开发语言大版内专家分月排行榜第二2004年11月 其他开发语言大版内专家分月排行榜第二2005年3月 硬件使用大版内专家分月排行榜第二
2011年11月 其他开发语言大版内专家分月排行榜第三2011年8月 其他开发语言大版内专家分月排行榜第三2008年10月 其他开发语言大版内专家分月排行榜第三2004年9月 硬件/嵌入开发大版内专家分月排行榜第三
2012年10月 其他开发语言大版内专家分月排行榜第二2011年7月 其他开发语言大版内专家分月排行榜第二2010年3月 其他开发语言大版内专家分月排行榜第二2007年10月 其他开发语言大版内专家分月排行榜第二2007年9月 其他开发语言大版内专家分月排行榜第二2005年3月 Windows专区大版内专家分月排行榜第二2005年2月 Windows专区大版内专家分月排行榜第二2005年6月 扩充话题大版内专家分月排行榜第二2006年9月 其他开发语言大版内专家分月排行榜第二2006年5月 其他开发语言大版内专家分月排行榜第二2006年3月 其他开发语言大版内专家分月排行榜第二2006年2月 其他开发语言大版内专家分月排行榜第二2005年12月 其他开发语言大版内专家分月排行榜第二2005年4月 其他开发语言大版内专家分月排行榜第二2004年11月 其他开发语言大版内专家分月排行榜第二2005年3月 硬件使用大版内专家分月排行榜第二
2011年11月 其他开发语言大版内专家分月排行榜第三2011年8月 其他开发语言大版内专家分月排行榜第三2008年10月 其他开发语言大版内专家分月排行榜第三2004年9月 硬件/嵌入开发大版内专家分月排行榜第三
本帖子已过去太久远了,不再提供回复功能。xxx服务标记为交互服务。但是系统配置成不允许交互服务。这项服务可能无法正常操作。
来源:博客园
【这个哪里设置
这个哪里设置
这个哪里设置
这个哪里设置】
服务属性对话框里面
免责声明:本站部分内容、图片、文字、视频等来自于互联网,仅供大家学习与交流。相关内容如涉嫌侵犯您的知识产权或其他合法权益,请向本站发送有效通知,我们会及时处理。反馈邮箱&&&&。
学生服务号
在线咨询,奖学金返现,名师点评,等你来互动服务设计中交互式信息的应用分析_赵佳佳_百度文库
两大类热门资源免费畅读
续费一年阅读会员,立省24元!
服务设计中交互式信息的应用分析_赵佳佳
阅读已结束,下载文档到电脑
想免费下载更多文档?
定制HR最喜欢的简历
你可能喜欢Service Activity的三种交互方式(详解)
投稿:jingxian
字体:[ ] 类型:转载 时间:
下面小编就为大家带来一篇Service Activity的三种交互方式(详解)。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧
service有两种类型:
本地服务(Local Service):用于应用程序内部
远程服务(Remote Sercie):用于android系统内部的应用程序之间
前者用于实现应用程序自己的一些耗时任务,比如查询升级信息,并不占用应用程序比如Activity所属线程,而是单开线程后台执行,这样用户体验比较好。
后者可被其他应用程序复用,比如天气预报服务,其他应用程序不需要再写这样的服务,调用已有的即可。
编写不需和Activity交互的本地服务示例
本地服务编写比较简单。首先,要创建一个Service类,该类继承android的Service类。这里写了一个计数服务的类,每秒钟为计数器加一。在服务类的内部,还创建了一个线程,用于实现后台执行上述业务逻辑。
Service代码:
import android.app.S
import android.content.I
import android.os.IB
import android.util.L
public class CountService extends Service {
private boolean threadD
public IBinder onBind(Intent intent) {
public void onCreate() {
super.onCreate();
new Thread(new Runnable() {
public void run() {
while (!threadDisable) {
Thread.sleep(1000);
} catch (InterruptedException e) {
System.out.println(" CountService Count is " + count);
}).start();
public void onDestroy() {
super.onDestroy();
this.threadDisable =
Log.v(" CountService ", " on destroy ");
将该服务注册到配置文件AndroidManifest.xml中
&service android:name="CountService" /&
在Activity中启动和关闭本地服务
import android.app.A
import android.content.I
import android.os.B
public class LocalServiceDemoActivity extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
this.startService(new Intent(this, CountService.class));
protected void onDestroy() {
super.onDestroy();
this.stopService(new Intent(this, CountService.class));
编写本地服务和Activity交互的示例
上面的示例是通过startService和stopService启动关闭服务的。适用于服务和activity之间没有调用交互的情况。如果之间需要传递参数或者方法调用。需要使用bind和unbind方法。
具体做法是,服务类需要增加接口,比如ICountService,另外,服务类需要有一个内部类,这样可以方便访问外部类的封装数据,这个内部类需要继承Binder类并实现ICountService接口。还有,就是要实现Service的
onBind方法,不能只传回一个null了。
新建立的接口代码:
public interface ICountService {
public abstract int getCount();
CountService代码:
import android.app.S
import android.content.I
import android.os.B
import android.os.IB
import android.util.L
public class CountService extends Service implements ICountService {
private boolean threadD
private ServiceBinder serviceBinder = new ServiceBinder();
public class ServiceBinder extends Binder implements ICountService {
// @Override
public int getCount() {
public IBinder onBind(Intent intent) {
return serviceB
public void onCreate() {
super.onCreate();
new Thread(new Runnable() {
// @Override
public void run() {
while (!threadDisable) {
Thread.sleep(1000);
} catch (InterruptedException e) {
System.out.println("CountService Count is " + count);
}).start();
public void onDestroy() {
super.onDestroy();
this.threadDisable =
Log.v(" CountService ", " on destroy ");
// @Override
public int getCount() {
服务的注册也要做改动,AndroidManifest.xml文件:
&service android:name="CountService" &
&intent-filter&
&action android:name="com.phone.jiaohuservice.CountService" /&
&/intent-filter&
&/service&
Acitity代码不再通过startSerivce和stopService启动关闭服务,另外,需要通过ServiceConnection的内部类实现来连接Service和Activity。
import android.app.A
import ponentN
import android.content.I
import android.content.ServiceC
import android.os.B
import android.os.IB
public class LocalServiceDemoActivity extends Activity {
private ServiceConnection serviceConnection = new ServiceConnection() {
// @Override
public void onServiceConnected(ComponentName name, IBinder service) {
countService = (ICountService)
System.out.println(" CountService on serivce connected, count is "
+ countService.getCount());
// @Override
public void onServiceDisconnected(ComponentName name) {
countService =
private ICountService countS
/** Called when the activity is first created. */
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
this.bindService(new Intent("com.phone.jiaohuservice.CountService"),
this.serviceConnection, BIND_AUTO_CREATE);
protected void onDestroy() {
this.unbindService(serviceConnection);
super.onDestroy(); // 注意先后
编写传递基本型数据的远程服务
上面的示例,可以扩展为,让其他应用程序复用该服务。这样的服务叫远程(remote)服务,实际上是进程间通信(RPC)。
这时需要使用android接口描述语言(AIDL)来定义远程服务的接口,而不是上述那样简单的java接口。扩展名为aidl而不是java。可用上面的ICountService改动而成ICountSerivde.aidl,eclipse会自动生成相关的java文件。
远端代码:
ICountService.aidl
package com.phone.remoteservice.
interface ICountService {
int getCount();
CountService.java
import com.phone.remoteservice.aidl.ICountS
import android.app.S
import android.content.I
import android.os.IB
import android.os.RemoteE
import android.util.L
public class CountService extends Service {
private boolean threadD
private ICountService.Stub serviceBinder = new ICountService.Stub() {
// @Override
public int getCount() throws RemoteException {
// @Override
public IBinder onBind(Intent intent) {
return serviceB
public void onCreate() {
super.onCreate();
new Thread(new Runnable() {
// @Override
public void run() {
while (!threadDisable) {
Thread.sleep(1000);
} catch (InterruptedException e) {
Log.i("aa", "---" + count + "---");
}).start();
// @Override
public void onDestroy() {
super.onDestroy();
this.threadDisable =
Log.v(" CountService ", " on destroy ");
&配置文件AndroidManifest.xml
&service android:name=".CountService" &
&intent-filter&
&action android:name="com.phone.remoteservice.CountService" /&
&/intent-filter&
&/service&
本地代码:
拷贝远端代码gen:com.phone.remoteservice.aidl包名及内部生成的ICountService.java文件到本地,注意包名不要变,java文件名也不要变。
import com.phone.remoteservice.aidl.ICountS
import android.os.B
import android.os.IB
import android.os.RemoteE
import android.app.A
import ponentN
import android.content.I
import android.content.ServiceC
import android.view.M
public class RemoteServiceTest extends Activity {
private ICountService countS
private boolean SreviceD
/** Called when the activity is first created. */
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
bindService(new Intent("com.phone.remoteservice.CountService"),
this.serviceConnection, BIND_AUTO_CREATE);
protected void onDestroy() {
this.unbindService(serviceConnection);
SreviceDisable =
super.onDestroy(); // 注意先后
private ServiceConnection serviceConnection = new ServiceConnection() {
public void onServiceConnected(ComponentName name, IBinder service) {
countService = ICountService.Stub.asInterface(service);
new Thread(new Runnable() {
// @Override
public void run() {
while (!SreviceDisable) {
System.out
.println(" CountService on serivce connected, count is "
+ countService.getCount());
} catch (RemoteException e) {
e.printStackTrace();
Thread.sleep(1000);
} catch (InterruptedException e) {
}).start();
public void onServiceDisconnected(ComponentName name) {
countService =
在Activity中使用服务的差别不大,只需要对ServiceConnection中的调用远程服务的方法时,要捕获RemoteException 异常。
这样就可以在同一个应用程序中使用远程服务的方式和自己定义的服务交互了。 如果是另外的应用程序使用远程服务,需要做的是复制上面的aidl文件和相应的包构到应用程序中,其他调用等都一样。
编写传递复杂数据类型的远程服务
远程服务往往不只是传递java基本数据类型。这时需要注意android的一些限制和规定:
1. android支持String和CharSequence
2. 如果需要在aidl中使用其他aidl接口类型,需要import,即使是在相同包结构下;
3. android允许传递实现Parcelable接口的类,需要import;
4. android支持集合接口类型List和Map,但是有一些限制,元素必须是基本型或者上述三种情况,不需要import集合接口类,但是需要对元素涉及到的类型import;
5. 非基本数据类型,也不是String和CharSequence类型的,需要有方向指示,包括in、out和inout,in表示由客户端设置,out表示由服务端设置,inout是两者均可设置。
这里将前面的例子中返回的int数据改为复杂数据类型:
import android.os.P
import android.os.P
public class CountBean implements Parcelable {
public static final Parcelable.Creator & CountBean & CREATOR = new Creator & CountBean & () {
public CountBean createFromParcel(Parcel source) {
CountBean bean = new CountBean();
bean.count = source.readInt();
public CountBean[] newArray( int size) {
return new CountBean[size];
public void writeToParcel(Parcel dest, int flags) {
dest.writeInt( this .count);
public int describeContents() {
return 0 ;
以上就是小编为大家带来的Service Activity的三种交互方式(详解)的全部内容了,希望对大家有所帮助,多多支持脚本之家~
您可能感兴趣的文章:
大家感兴趣的内容
12345678910
最近更新的内容
常用在线小工具

我要回帖

更多关于 交互体验是什么意思 的文章

 

随机推荐