Service的开启和停止以及生命周期
1、清单文件
<service android:name=".TestService"></service>
2、开启Service
Intent intent = new Intent(this, TestService.class);
startService(intent);
3、停止服务
Intent intent = new Intent(this, TestService.class);
stopService(intent);
4、Service的开启和停止所显示的生命周期
package com.example.testservice; import android.app.Service;
import android.content.Intent;
import android.os.IBinder; public class TestService extends Service { @Override
public IBinder onBind(Intent intent) {
// TODO Auto-generated method stub
return null;
} @Override
public void onCreate() {
// TODO Auto-generated method stub--1
System.out.println("onCreate");
super.onCreate(); } @Override
@Deprecated
public void onStart(Intent intent, int startId) {
// TODO Auto-generated method stub--3
System.out.println("onStart");
super.onStart(intent, startId); } @Override
public int onStartCommand(Intent intent, int flags, int startId) {
// TODO Auto-generated method stub--2
System.out.println("onStartCommand");
return super.onStartCommand(intent, flags, startId); } @Override
public void onDestroy() {
// TODO Auto-generated method stub--4
System.out.println("onDestroy");
super.onDestroy();
} }
注意:--n显示是它们的执行顺序
Service的开启和停止以及生命周期的更多相关文章
- Service的两种用法及其生命周期
先来一点基础知识: Service 是android的四大组件之一,与Activity同属于一个级别,它是运行在后台进行服务的组件(例如在后台播放的音乐,播放音乐的同时并不影响其他操作).Servic ...
- Android服务Service具体解释(作用,生命周期,AIDL)系列文章-为什么须要服务呢?
Android服务Service具体解释(作用,生命周期,AIDL) 近期沉迷于上班,没有时间写博客了.解衣入睡,未眠.随起床写一篇博客压压惊! ##我们android系统为什么须要服务Service ...
- Android -- Service的开启关闭与生命周期
Service是Android 系统中的四大组件之一,是在一段不定的时间运行在后台,不和用户交互应用组件. service可以在很多场合的应用中使用,比如播放多媒体的时候用户启动了其他Activity ...
- Android activity和service的生命周期对比
1Activity生命周期 七个方法 1. void onCreate(Bundle savedInstanceState) 当Activity被第首次加载时执行.我们新启动一个程序的时候其主窗体的o ...
- service的生命周期
Managing the Lifecycle of a Service service的生命周期,从它被创建开始,到它被销毁为止,可以有两条不同的路径: A started service 被开启的s ...
- android基础---->service的生命周期
服务是一个应用程序组件代表应用程序执行一个长时间操作的行为,虽然不与用户交互或供应功能供其它应用程序使用.它和其他的应用对象一样,在他的宿主进程的主线程中运行.今天我们开始android中普通serv ...
- Activity和Service的生命周期(图)
1.Activity的生命周期 情形一.一个单独的Activity的正常的生命过程是这样的:onCreate->onStart->onPause->onStop->onDest ...
- Android 中Service生命周期
使用context.startService() 启动Service 其生命周期为context.startService() ->onCreate()- >onStart()->S ...
- 8.1.1 Service的生命周期
2010-06-21 16:57 李宁 中国水利水电出版社 字号:T | T <Android/OPhone开发完全讲义>第8章Android服务,本章主要介绍了Android系统 中的服 ...
随机推荐
- 建立dblink,clob
建立dblink的方法, 如果有个测试库A,要访问生产库里的数据,那么可以直接在测试库A里建立一个dblink,然后数据库A就可以直接访问测试库B的数据了. -- 删除已有的dblink drop d ...
- VIM用法
突然感觉vim像是linux上默认的文本编辑器,所以熟悉下用法吧. 1,set nu 显示行号. 2, /word 搜索文本word,n查找下一个. :set hlsearch--高亮显示搜索 ...
- spring 事务 笔记3.1
Spring事务 以前的事务都是编程式事务,需要开启和关闭,然后程序写在这里面 spring,声明式事务 Spring事务隔离级别 DEFAULT 使用数据库默认隔离级别 READ_UNCOMMITT ...
- Java学习笔记51:数组转ArrayList和ArrayList转数组技巧
ArrayList转数组: public class Test { public static void main(String[] args) { List<String> list = ...
- 啊华北哦好咕~~(╯﹏╰)b
http://v.qq.com/boke/page/c/h/0/c01173tzeh0.html http://v.qq.com/boke/page/r/7/x/r0117l07r7x.html ht ...
- CMake学习小结
假定有vegagis工程,工程的目录结构如下: #--vegagis# |--src 源文件目录# |--gui 界面工程,输出类型:dll,依赖于QT的QtCore.QtGui.QtXml ...
- Muduo 网络编程示例之零:前言
陈硕 (giantchen_AT_gmail)Blog.csdn.net/Solstice Muduo 全系列文章列表: http://blog.csdn.net/Solstice/category/ ...
- 点菜系统 pickview的简单实用
使用pickview的时候多想想tableview的使用,观察两者的相同之处 pickview的主要用途用于选择地区 生日年月日 和点餐 示例代码 简单的pickview点餐系统// ViewC ...
- 11427 - Expect the Expected(概率期望)
11427 - Expect the Expected Some mathematical background. This problem asks you to compute the expec ...
- Android之drawable state各个属性具体解释
我们在定义一个drawable的时候能够通过xml定义的drawable对象.它使得一个图片能在不同的状态下显示不同的图案,比方一个Button,它有pressed.focused,或者其他状态,通过 ...