文章标题 android服务Service 的一些基本简介和用法
2017-02-13 18:42
603 查看
1、服务简介
执行耗时操作(后台),耗时操作不能写到了主线程, 需要一个子线程进行耗时操作
在MainActivity中的一些用法,主要有onCreate,start,stop
执行耗时操作(后台),耗时操作不能写到了主线程, 需要一个子线程进行耗时操作
服务和Thread的区别? 1.服务不是单一的进程。服务没有自己的进程,应用程序可以不同,服务运行在相同的进程中。 2.服务不是线程。可以在线程中工作。
一、服务的生命周期总共有4个, onCreate onStartCommand onDestroy onBind 二、本地服务 onStartCommand返回值3 三、服务的停止 stopService stopSelf stopSelf()主要是当一个进程停止后,后面的进程也停止; stopSelf(id)主要是所有进程都停止
在MainActivity中的一些用法,主要有onCreate,start,stop
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); intent = new Intent(this,MyServices2.class); } public void start(View view){ intent.putExtra("data","下载的路径"); startService(intent); } public void stop(View view){ stopService(intent); }
相关文章推荐
- android学习十八(Service服务的基本用法)
- Android Service(服务)详解·(二)Service基本用法
- Android之Service(二):服务的基本用法
- android---(Service服务的基本用法)
- Android Service 服务的基本用法
- 文章标题 Android系统广播的发送短信和接收短信的一些用法
- Android中的Service的用法之绑定服务
- 关于Android Service的基本用法(下)(转)
- Android - 位置定位(Location)服务(Service)类的基本操作
- android: 服务的基本用法
- Android中的Service的用法 开启服务,下一篇讲绑定服务
- Android Service的基本用法
- android中Service的基本用法和IntentService的使用
- android基本组件 Service 简介
- android glide的一些基本用法
- Android之Service(一):服务简介
- Android - 位置定位(Location)服务(Service)类的基本操作
- Android中service基本用法,生命周期2
- Android Volley学习1---简介及基本用法
- android 学习笔记 服务的基本用法