[Android Pro] Service (startservice , bindservice , unbindservice, stopService)

1: startService -------stopService (this will call onDestroy)

2: bindService -------unbindService    (this will call onDestroy)

3: startService---bindService----stopService (nothing happen,  shoud call unbindService)

4: startService---bindService----unbundService --- stopService (this will call onDestroy)

5: startService---bindService----stopService-----unbindService  (this will call onDestroy)

6: bindService---startService---stopService (nothing happen,  shoud call unbindService)

7: bindService---startService---unbindService----stopService  (this will call onDestroy)

7: bindService---startService----stopService---unbindService  (this will call onDestroy)

时间: 2024-08-28 06:36:59

[Android Pro] Service (startservice , bindservice , unbindservice, stopService)的相关文章

Android里Service的bindService()和startService()混合使用深入分析

先讲讲怎么使用bindService()绑定服务 应用组件(客户端)可以调用bindService()绑定到一个service.Android系统之后调用service的onBind()方法,它返回一个用来与service交互的IBinder绑定是异步的.bindService()会立即返回,它不会返回IBinder给客户端.要接收IBinder,客户端必须创建一个ServiceConnection的实例并传给bindService().ServiceConnection包含一个回调方法,系统调

Android中Service使用bindService

前面已经对Service的startServer方式启动一个服务了解过了,现在来看一下Service的另一种启动方式→bindServer bindServer使用场景 1.在同个app之间调用(即是同一个进程中) 2.在不同app之间调用(即是跨进程间通信) 同个app间调用(只有一次启动该服务) BinderActicityA public class BinderActicityA extends Activity implements View.OnClickListener { pri

[Android Pro] service中显示一个dialog 或者通过windowmanage显示view

转载: http://blog.csdn.net/huxueyan521/article/details/8954844 通过windowmananger来在窗口上添加view的时候,需要设置alert参数,而且要添加alert权限 mLayoutParams = new WindowManager.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, LayoutParams.TYPE_SYSTEM_ALERT,

android 远程Service以及AIDL的跨进程通信

在Android中,Service是运行在主线程中的,如果在Service中处理一些耗时的操作,就会导致程序出现ANR. 但如果将本地的Service转换成一个远程的Service,就不会出现这样的问题了. 转换成远程Service非常简单,只需要在注册Service的时候将他的android:process的属性制定成 :remote就可以了. 重新运行项目,你会发现,不会出现ANR了. 为什么将MyService转换成远程Service后就不会导致程序ANR了呢?这是由于,使用了远程Serv

Android总结 - Service

Service是一个长时间操作的后台服务,也可以做IPC操作. Service有两种启动模式:Started和Bound.所谓"started"就是通过调用startService()而Bound就是通过调用bindService(). Service的生命周期 通过Service的生命周期可以得到Server的几个重要的回调函数: onStartCommand() 当其他组件,如 activity 请求服务启动时,系统会调用这个方法.一旦这个方法执行,服务就开始并且无限期的执行.如果

(六)Android中Service通信

一.启动Service并传递参数 传递参数时只需在startService启动的Intent中传入数据便可,接收参数时可在onStartCommand函数中通过读取第一个参数Intent的内容来实现 1.MainActivity.java package com.example.shiyanshi.serviceconnected; import android.app.Activity;import android.content.Intent;import android.os.Bundle

Android中Service的使用

我个人的理解是:我们平时使用的android系统的app的后台应用,就是这个原理 可以利用Service实现程序在后台运行,依照这个原理,可以通过Service来实现关键代码的运行与实现. <一>下面大体说一下我在极客学院跟着视频做的一个Service的小实现 1,首先点击左上角file->new往下拉,看到一个Service,创建MyService.java 这个就是我们的Service服务. 后续可以在这其中添加想要在后台运行的关键代码等. 2,首先创建项目后,在layout或中的x

Android中Service的一个Demo例子

Android中Service的一个Demo例子  Service组件是Android系统重要的一部分,网上看了代码,很简单,但要想熟练使用还是需要Coding.  本文,主要贴代码,不对Service做过多讲解.  代码是从网上找的一个例子,Copy下来发现代码不完全正确,稍微修改了下.  AndroidManifest.xml <application android:icon="@drawable/ic_launcher" android:label="@stri

android的service

package com.service.service; import com.example.service.R; import android.app.Activity; import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.content.ServiceConnection; import android.os.B