• Android组件通信——Service(二十七)


    1. Service

    1.1 知识点

    (1)掌握Service与Activity的区别;

    (2)掌握Service的定义及使用;

    (3)可以使用ServiceConnection 接口绑定一个Service;

    (4)了解系统提供的Service程序。

    1.2 具体内容

    Service是Android四大组件之一,和Activity最大的区别在于一个有界面,一个没有界面。

    如果在程序中要实现Services的操作的话,需要定义一个Services类的子类,并且有这个子类复写相应的操作方法。

    范例:定义后台服务

           对于后台服务就是指我们Services程序,肯定是没有界面去显示的,就是在后台运行。

    1. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    2. xmlns:tools="http://schemas.android.com/tools"
    3. android:layout_width="match_parent"
    4. android:layout_height="match_parent"
    5. android:orientation="vertical">
    6. <Button
    7. android:id="@+id/start"
    8. android:layout_width="match_parent"
    9. android:layout_height="wrap_content"
    10. android:text="启动Services" />
    11. <Button
    12. android:id="@+id/stop"
    13. android:layout_width="match_parent"
    14. android:layout_height="wrap_content"
    15. android:text="停止Services" />
    16. </LinearLayout>

    关键肯定是要编写我们Services程序。

    1. package com.example.servicesproject;
    2. import android.app.Service;
    3. import android.content.Intent;
    4. import android.os.IBinder;
    5. public class MyServices extends Service {
    6. @Override
    7. public IBinder onBind(Intent intent) {//绑定Activity
    8. return null;
    9. }
    10. @Override
    11. public void onCreate() {//创建时调用
    12. System.out.println("============Service被创建============");
    13. }
    14. @Override
    15. public void onDestroy() {//销毁时调用
    16. System.out.println("============Service被销毁============");
    17. }
    18. @Override
    19. public int onStartCommand(Intent intent, int flags, int startId) {//开始Services
    20. System.out.println("============Service启动============intent = " + intent + "startId="+startId);
    21. return Service.START_CONTINUATION_MASK;//表示Service继续执行
    22. }
    23. }

    对于Service,本身并没有界面,只是提供了一个后台的操作,本身需要依靠Activity程序去启动。

    1. package com.example.servicesproject;
    2. import android.app.Activity;
    3. import android.content.Intent;
    4. import android.os.Bundle;
    5. import android.view.View;
    6. import android.view.View.OnClickListener;
    7. import android.widget.Button;
    8. public class ServicesActivity extends Activity {
    9. private Button start = null;
    10. private Button stop = null;
    11. @Override
    12. protected void onCreate(Bundle savedInstanceState) {
    13. super.onCreate(savedInstanceState);
    14. super.setContentView(R.layout.activity_services);
    15. this.start = (Button) super.findViewById(R.id.start);
    16. this.stop = (Button) super.findViewById(R.id.stop);
    17. this.start.setOnClickListener(new StartOnClickListenerImpl());
    18. this.stop.setOnClickListener(new StopOnClickListenerImpl());
    19. }
    20. private class StartOnClickListenerImpl implements OnClickListener {
    21. public void onClick(View v) {
    22. //启动Service
    23. ServicesActivity.this.startService(new Intent(ServicesActivity.this,MyServices.class));
    24. }
    25. }
    26. private class StopOnClickListenerImpl implements OnClickListener {
    27. public void onClick(View v) {
    28. //停止Service
    29. ServicesActivity.this.stopService(new Intent(ServicesActivity.this,MyServices.class));
    30. }
    31. }
    32. }

    通过Activity程序去控制Service的开始和停止,既然Service程序是一个没有界面的Activity,那么肯定也需要在AndroidMainFest.xml里面进行配置。

    1. android:name="com.example.servicesproject.MyServices">

    如果说一个Activity和Service要进行绑定的话,必须要使用到ServiceConnection这个接口,这个接口中有两个方法,一个是建立连接的时候使用,第二个是取消连接的时候使用, 但是一定要注意,连接是触发的操作中,还有一个IBinder接口对象。

    既然IBinder是一个接口,那么这个接口中肯定存在大量的抽象方法,所以按照正常的思路肯定是会去覆写IBinder接口中所有的抽象方法,现在我们可以继承它,我们就可以覆写指定的方法。

    1. package com.example.servicesproject;
    2. import android.app.Service;
    3. import android.content.Intent;
    4. import android.os.Binder;
    5. import android.os.IBinder;
    6. public class MyServices extends Service {
    7. private IBinder myIBinder = new Binder(){
    8. @Override
    9. public String getInterfaceDescriptor() {//取得接口的描述信息
    10. return "MyServices.class";
    11. }
    12. };
    13. @Override
    14. public IBinder onBind(Intent intent) {//绑定Activity
    15. System.out.println("===========onBind==========intent="+intent);
    16. return myIBinder;
    17. }
    18. @Override
    19. public boolean onUnbind(Intent intent) {//解除绑定
    20. System.out.println("===========onUnbind==========intent="+intent);
    21. return super.onUnbind(intent);
    22. }
    23. @Override
    24. public void onRebind(Intent intent) {
    25. System.out.println("===========onRebind==========intent="+intent);
    26. super.onRebind(intent);
    27. }
    28. @Override
    29. public void onCreate() {//创建时调用
    30. System.out.println("============Service被创建============");
    31. }
    32. @Override
    33. public void onDestroy() {//销毁时调用
    34. System.out.println("============Service被销毁============");
    35. }
    36. @Override
    37. public int onStartCommand(Intent intent, int flags, int startId) {//开始Services
    38. System.out.println("============Service启动============intent = " + intent + "startId="+startId);
    39. return Service.START_CONTINUATION_MASK;//表示Service继续执行
    40. }
    41. }

    而后的Activity程序中增加一些操作按钮。

    1. package com.example.servicesproject;
    2. import android.app.Activity;
    3. import android.content.ComponentName;
    4. import android.content.Context;
    5. import android.content.Intent;
    6. import android.content.ServiceConnection;
    7. import android.os.Bundle;
    8. import android.os.IBinder;
    9. import android.os.RemoteException;
    10. import android.view.View;
    11. import android.view.View.OnClickListener;
    12. import android.widget.Button;
    13. public class ServicesActivity extends Activity {
    14. private Button start = null;
    15. private Button stop = null;
    16. private Button bind = null;
    17. private Button unbind = null;
    18. private ServiceConnection serviceConnection = new ServiceConnection(){
    19. @Override
    20. public void onServiceConnected(ComponentName name, IBinder service) {
    21. try {
    22. System.out.println("==========连接到Service==========" + service.getInterfaceDescriptor());
    23. } catch (RemoteException e) {
    24. e.printStackTrace();
    25. }
    26. }
    27. @Override
    28. public void onServiceDisconnected(ComponentName name) {
    29. System.out.println("=================取消Service=============");
    30. }
    31. };
    32. @Override
    33. protected void onCreate(Bundle savedInstanceState) {
    34. super.onCreate(savedInstanceState);
    35. super.setContentView(R.layout.activity_services);
    36. this.start = (Button) super.findViewById(R.id.start);
    37. this.stop = (Button) super.findViewById(R.id.stop);
    38. this.start.setOnClickListener(new StartOnClickListenerImpl());
    39. this.stop.setOnClickListener(new StopOnClickListenerImpl());
    40. this.bind =(Button) super.findViewById(R.id.bind);
    41. this.unbind = (Button) super.findViewById(R.id.unbind);
    42. this.bind.setOnClickListener(new BindOnClickListenerImpl());
    43. this.unbind.setOnClickListener(new UNBindOnClickListenerImpl());
    44. }
    45. private class StartOnClickListenerImpl implements OnClickListener {
    46. public void onClick(View v) {
    47. //启动Service
    48. ServicesActivity.this.startService(new Intent(ServicesActivity.this,MyServices.class));
    49. }
    50. }
    51. private class StopOnClickListenerImpl implements OnClickListener {
    52. public void onClick(View v) {
    53. //停止Service
    54. ServicesActivity.this.stopService(new Intent(ServicesActivity.this,MyServices.class));
    55. }
    56. }
    57. private class BindOnClickListenerImpl implements OnClickListener{
    58. @Override
    59. public void onClick(View v) {
    60. //进行Service绑定
    61. ServicesActivity.this.bindService(new Intent(ServicesActivity.this,MyServices.class), ServicesActivity.this.serviceConnection, Context.BIND_AUTO_CREATE);
    62. }
    63. }
    64. private class UNBindOnClickListenerImpl implements OnClickListener{
    65. @Override
    66. public void onClick(View v) {
    67. //取消绑定
    68. ServicesActivity.this.unbindService(ServicesActivity.this.serviceConnection);
    69. }
    70. }
    71. }

    此时的Activity程序就已经完成,下面我们来观察运行消息打印的流程。

    ·启动Service

    1. 01-27 01:07:36.243: INFO/System.out(487): ============Service被创建============
    2. 01-27 01:07:36.243: INFO/System.out(487): ============Service启动============intent = Intent { cmp=com.example.servicesproject/.MyServices }startId=1

    ·绑定Service

    1. 01-27 01:08:29.583: INFO/System.out(487): ===========onBind==========intent=Intent { cmp=com.example.servicesproject/.MyServices }
    2. 01-27 01:08:29.583: INFO/System.out(487): ==========连接到Service==========MyServices.class

    通过打印,可以清楚的发现,出现了onBind之后,会返回到ServiceConnection中执行onServiceConnected()方法。

    ·如果不启动直接绑定

    1. 01-27 01:11:22.652: INFO/System.out(877): ============Service被创建============
    2. 01-27 01:11:22.652: INFO/System.out(877): ===========onBind==========intent=Intent { cmp=com.example.servicesproject/.MyServices }
    3. 01-27 01:11:22.672: INFO/System.out(877): ==========连接到Service==========MyServices.class

    如果直接绑定,则直接调用OnCreate()、onBind()、ServiceConnection中的onServiceConnected()

    ·不停止,直接退出

    1. 01-27 01:12:39.733: I/System.out(877): ===========onUnbind==========intent=Intent { cmp=com.example.servicesproject/.MyServices }
    2. 01-27 01:12:39.733: I/System.out(877): ============Service被销毁============

    不停止直接退出,会先取消绑定,再销毁。

    ·返回到Activity,同时再设置绑定

    1. 01-27 01:13:50.274: INFO/System.out(877): ============Service被创建============
    2. 01-27 01:13:50.274: INFO/System.out(877): ===========onBind==========intent=Intent { cmp=com.example.servicesproject/.MyServices }
    3. 01-27 01:13:50.292: INFO/System.out(877): ==========连接到Service==========MyServices.class

    ·解除绑定

    1. 01-27 01:14:19.702: INFO/System.out(877): ===========onUnbind==========intent=Intent { cmp=com.example.servicesproject/.MyServices }
    2. 01-27 01:14:19.702: INFO/System.out(877): ============Service被销毁============

    也就是说,我们在操作之中,主应该注意的方法是:OnCreate()、onBind()、onUnbind(),onDestroy()。

    虽然,以上的程序已经进行了绑定,但是还存在一个问题 。

    定义一个空的接口,作为一个标识。

    1. public interface IService {
    2. }

    此接口中不需要编写任何的操作方法。

    1. package com.example.servicesproject;
    2. import android.app.Service;
    3. import android.content.Intent;
    4. import android.os.Binder;
    5. import android.os.IBinder;
    6. public class MyServices extends Service {
    7. private IBinder myIBinder = new IBinderImpl();
    8. private class IBinderImpl extends Binder implements IService{
    9. @Override
    10. public String getInterfaceDescriptor() {//取得接口信息
    11. return "MyServices.class";
    12. }
    13. }
    14. @Override
    15. public IBinder onBind(Intent intent) {//绑定Activity
    16. System.out.println("===========onBind==========intent="+intent);
    17. return myIBinder;
    18. }
    19. @Override
    20. public boolean onUnbind(Intent intent) {//解除绑定
    21. System.out.println("===========onUnbind==========intent="+intent);
    22. return super.onUnbind(intent);
    23. }
    24. @Override
    25. public void onRebind(Intent intent) {
    26. System.out.println("===========onRebind==========intent="+intent);
    27. super.onRebind(intent);
    28. }
    29. @Override
    30. public void onCreate() {//创建时调用
    31. System.out.println("============Service被创建============");
    32. }
    33. @Override
    34. public void onDestroy() {//销毁时调用
    35. System.out.println("============Service被销毁============");
    36. }
    37. @Override
    38. public int onStartCommand(Intent intent, int flags, int startId) {//开始Services
    39. System.out.println("============Service启动============intent = " + intent + "startId="+startId);
    40. return Service.START_CONTINUATION_MASK;//表示Service继续执行
    41. }
    42. }

    大家一定要记住,IBinderImpl一定要是Binder和IService共同子类。

    1. package com.example.servicesproject;
    2. import android.app.Activity;
    3. import android.content.ComponentName;
    4. import android.content.Context;
    5. import android.content.Intent;
    6. import android.content.ServiceConnection;
    7. import android.os.Bundle;
    8. import android.os.IBinder;
    9. import android.os.RemoteException;
    10. import android.view.View;
    11. import android.view.View.OnClickListener;
    12. import android.widget.Button;
    13. public class ServicesActivity extends Activity {
    14. private Button start = null;
    15. private Button stop = null;
    16. private Button bind = null;
    17. private Button unbind = null;
    18. private IService service = null;
    19. private ServiceConnection serviceConnection = new ServiceConnectionImpl();
    20. private class ServiceConnectionImpl implements ServiceConnection{
    21. @Override
    22. public void onServiceConnected(ComponentName name, IBinder service) {
    23. try {
    24. System.out.println("==========连接到Service==========" + service.getInterfaceDescriptor());
    25. } catch (RemoteException e) {
    26. e.printStackTrace();
    27. }
    28. }
    29. @Override
    30. public void onServiceDisconnected(ComponentName name) {
    31. System.out.println("=================取消Service=============");
    32. }
    33. }
    34. @Override
    35. protected void onCreate(Bundle savedInstanceState) {
    36. super.onCreate(savedInstanceState);
    37. super.setContentView(R.layout.activity_services);
    38. this.start = (Button) super.findViewById(R.id.start);
    39. this.stop = (Button) super.findViewById(R.id.stop);
    40. this.start.setOnClickListener(new StartOnClickListenerImpl());
    41. this.stop.setOnClickListener(new StopOnClickListenerImpl());
    42. this.bind =(Button) super.findViewById(R.id.bind);
    43. this.unbind = (Button) super.findViewById(R.id.unbind);
    44. this.bind.setOnClickListener(new BindOnClickListenerImpl());
    45. this.unbind.setOnClickListener(new UNBindOnClickListenerImpl());
    46. }
    47. private class StartOnClickListenerImpl implements OnClickListener {
    48. public void onClick(View v) {
    49. //启动Service
    50. ServicesActivity.this.startService(new Intent(ServicesActivity.this,MyServices.class));
    51. }
    52. }
    53. private class StopOnClickListenerImpl implements OnClickListener {
    54. public void onClick(View v) {
    55. //停止Service
    56. ServicesActivity.this.stopService(new Intent(ServicesActivity.this,MyServices.class));
    57. }
    58. }
    59. private class BindOnClickListenerImpl implements OnClickListener{
    60. @Override
    61. public void onClick(View v) {
    62. //进行Service绑定
    63. ServicesActivity.this.bindService(new Intent(ServicesActivity.this,MyServices.class), ServicesActivity.this.serviceConnection, Context.BIND_AUTO_CREATE);
    64. }
    65. }
    66. private class UNBindOnClickListenerImpl implements OnClickListener{
    67. @Override
    68. public void onClick(View v) {
    69. if(null != ServicesActivity.this.service){
    70. //取消绑定
    71. ServicesActivity.this.unbindService(ServicesActivity.this.serviceConnection);
    72. ServicesActivity.this.service = null;
    73. }
    74. }
    75. }
    76. }

    关键就是IBinder需要继承Binder还需要实现我们定义的空的接口。

    ·操作系统服务:服务的概念就是运行在后台之中,而且android之中为了方便的系统运行,也有多种服务提供给开发者使用。

    范例:剪贴板服务

    1. "http://schemas.android.com/apk/res/android"
    2. xmlns:tools="http://schemas.android.com/tools"
    3. android:layout_width="match_parent"
    4. android:layout_height="match_parent"
    5. android:orientation="vertical">
    6. android:layout_width="match_parent"
    7. android:layout_height="wrap_content" />

    如果需要取得系统服务,需要使用getSystemService(服务标记);

    1. package com.example.contextservice;
    2. import android.app.Activity;
    3. import android.content.Context;
    4. import android.os.Bundle;
    5. import android.text.ClipboardManager;
    6. public class ContextServiceActivity extends Activity {
    7. @Override
    8. protected void onCreate(Bundle savedInstanceState) {
    9. super.onCreate(savedInstanceState);
    10. super.setContentView(R.layout.activity_context_service);
    11. ClipboardManager clipboardManager = (ClipboardManager)super.getSystemService(Context.CLIPBOARD_SERVICE);//取得剪贴板服务
    12. clipboardManager.setText("毛栗子");
    13. }
    14. }

    这边就是直接使用了后台提供的服务。

    范例:取得正在运行的Activity程序信息

    1. xmlns:android="http://schemas.android.com/apk/res/android"
    2. xmlns:tools="http://schemas.android.com/tools"
    3. android:layout_width="match_parent"
    4. android:layout_height="match_parent"
    5. android:orientation="vertical" >
    6. android:id="@+id/aclist"
    7. android:layout_width="match_parent"
    8. android:layout_height="wrap_content"/>

    肯定是需要通过Activity程序取得所有信息并在ListView中显示。

    1. package com.example.activityrun;
    2. import java.util.ArrayList;
    3. import java.util.Iterator;
    4. import java.util.List;
    5. import android.app.Activity;
    6. import android.app.ActivityManager;
    7. import android.content.Context;
    8. import android.os.Bundle;
    9. import android.widget.ArrayAdapter;
    10. import android.widget.ListAdapter;
    11. import android.widget.ListView;
    12. public class MainActivity extends Activity {
    13. private ListView aclist = null;
    14. private ListAdapter adapter = null;
    15. private List all = new ArrayList();
    16. private List allTaskInfo = null;//所有任务信息
    17. private ActivityManager activityManager = null;//ActivityManager对象
    18. @Override
    19. protected void onCreate(Bundle savedInstanceState) {
    20. super.onCreate(savedInstanceState);
    21. super.setContentView(R.layout.activity_main);
    22. this.aclist = (ListView) super.findViewById(R.id.aclist);
    23. this.activityManager = (ActivityManager)super.getSystemService(Context.ACTIVITY_SERVICE);
    24. this.listActivity();
    25. }
    26. public void listActivity(){
    27. this.allTaskInfo = this.activityManager.getRunningTasks(30);//取回30笔任务数据
    28. Iterator it = this.allTaskInfo.iterator();
    29. while(it.hasNext()){
    30. ActivityManager.RunningTaskInfo task = it.next();
    31. this.all.add("【ID】"+task.id+"【NAME】"+task.baseActivity.getClassName());
    32. }
    33. this.adapter = new ArrayAdapter(this,android.R.layout.simple_list_item_1,this.all);
    34. this.aclist.setAdapter(this.adapter);
    35. }
    36. }

    需要配置权限:

    "android.permission.GET_TASKS"/>

    如果说要取得服务信息,则直接修改以上的程序就可以了。如果是要取得所有的进程信息,我们也只需要修改以上的程序。

    范例:取得网络信息

    如果要获取手机讯息,我们肯定也需要使用列表完成显示。

    1. package com.example.activityrun;
    2. import java.util.ArrayList;
    3. import java.util.List;
    4. import android.app.Activity;
    5. import android.content.Context;
    6. import android.os.Bundle;
    7. import android.telephony.TelephonyManager;
    8. import android.widget.ArrayAdapter;
    9. import android.widget.ListAdapter;
    10. import android.widget.ListView;
    11. public class MainActivity extends Activity {
    12. private ListView telinfo = null;
    13. private ListAdapter adapter = null;
    14. private List all = new ArrayList();
    15. private TelephonyManager telephonyManager = null;//ActivityManager对象
    16. @Override
    17. protected void onCreate(Bundle savedInstanceState) {
    18. super.onCreate(savedInstanceState);
    19. super.setContentView(R.layout.activity_main);
    20. this.telinfo = (ListView) super.findViewById(R.id.aclist);
    21. this.telephonyManager = (TelephonyManager)super.getSystemService(Context.TELEPHONY_SERVICE);
    22. this.listActivity();
    23. }
    24. public void listActivity(){
    25. this.all.add(this.telephonyManager.getLine1Number()==null?"没有手机号码":"手机号:"+this.telephonyManager.getLine1Number());
    26. this.all.add(this.telephonyManager.getNetworkOperatorName()== null?"没有移动服务商":"移动服务商:"+this.telephonyManager.getNetworkOperatorName());
    27. if(this.telephonyManager.getPhoneType() == TelephonyManager.NETWORK_TYPE_CDMA){
    28. this.all.add("移动网络:CDMA");
    29. }else if(this.telephonyManager.getPhoneType() == TelephonyManager.NETWORK_TYPE_GPRS){
    30. this.all.add("移动网络:GPRS");
    31. }else{
    32. this.all.add("移动网络:未知");
    33. }
    34. this.all.add("是否漫游:"+(this.telephonyManager.isNetworkRoaming()?"是漫游":"非漫游"));
    35. this.adapter = new ArrayAdapter(this,android.R.layout.simple_list_item_1,this.all);
    36. this.telinfo.setAdapter(this.adapter);
    37. }
    38. }

    权限:

    "android.permission.READ_PHONE_STATE"/>

    范例:操作WIFI

    1. xmlns:android="http://schemas.android.com/apk/res/android"
    2. xmlns:tools="http://schemas.android.com/tools"
    3. android:layout_width="match_parent"
    4. android:layout_height="match_parent"
    5. android:orientation="vertical" >
    6. android:id="@+id/mag"
    7. android:layout_width="match_parent"
    8. android:layout_height="wrap_content"/>
    9. android:id="@+id/openWIFI"
    10. android:layout_width="match_parent"
    11. android:layout_height="wrap_content"
    12. android:text="打开WIFI"/>
    13. android:id="@+id/closeWIFI"
    14. android:layout_width="match_parent"
    15. android:layout_height="wrap_content"
    16. android:text="关闭WIFI"/>
    17. android:id="@+id/selectState"
    18. android:layout_width="match_parent"
    19. android:layout_height="wrap_content"
    20. android:text="检查WIFI状态"/>
    1. package com.example.activityrun;
    2. import android.app.Activity;
    3. import android.content.Context;
    4. import android.net.wifi.WifiManager;
    5. import android.os.Bundle;
    6. import android.view.View;
    7. import android.view.View.OnClickListener;
    8. import android.widget.Button;
    9. import android.widget.TextView;
    10. public class MainActivity extends Activity {
    11. private TextView msg = null;
    12. private Button openWIFI = null;
    13. private Button closeWIFI = null;
    14. private Button selectState = null;
    15. private WifiManager wifiManager = null;
    16. @Override
    17. protected void onCreate(Bundle savedInstanceState) {
    18. super.onCreate(savedInstanceState);
    19. super.setContentView(R.layout.activity_main);
    20. this.msg = (TextView) super.findViewById(R.id.mag);
    21. this.openWIFI = (Button) super.findViewById(R.id.openWIFI);
    22. this.closeWIFI = (Button) super.findViewById(R.id.closeWIFI);
    23. this.selectState = (Button) super.findViewById(R.id.selectState);
    24. this.wifiManager = (WifiManager)super.getSystemService(Context.WIFI_SERVICE);
    25. this.openWIFI.setOnClickListener(new OnClickListener() {
    26. public void onClick(View v) {
    27. MainActivity.this.wifiManager.setWifiEnabled(true);//启动WIFI
    28. MainActivity.this.msg.setText("打开WIFI,状态:" + MainActivity.this.wifiManager.getWifiState());
    29. }
    30. });
    31. this.closeWIFI.setOnClickListener(new OnClickListener() {
    32. @Override
    33. public void onClick(View v) {
    34. MainActivity.this.wifiManager.setWifiEnabled(false);//关闭WIFI
    35. MainActivity.this.msg.setText("关闭WIFI,状态:" + MainActivity.this.wifiManager.getWifiState());
    36. }
    37. });
    38. this.selectState.setOnClickListener(new OnClickListener() {
    39. @Override
    40. public void onClick(View v) {
    41. MainActivity.this.msg.setText("检查WIFI,状态:" + MainActivity.this.wifiManager.getWifiState());
    42. }
    43. });
    44. }
    45. }

    配置权限:

    1. "android.permission.CHANGE_NETWORK_STATE"/>
    2. "android.permission.CHANGE_WIFI_STATE"/>
    3. "android.permission.ACCESS_WIFI_STATE"/>

    1.3 小结

    (1)Service是在后台运行的一种无界面的Activity程序;

    (2)在Android系统之中提供了多种Service供用户使用;

  • 相关阅读:
    WSL2上Docker打包的镜像迁移到Ubuntu服务器上无法使用GPU
    Django员工管理系统
    字符集 - java案例分析
    【安卓】Material Design
    Java EE——线程(2)
    学习ASP.NET Core Blazor编程系列一——综述
    Java加密与解密
    经常被人问起的API接口汇总,含免费次数
    物通博联持续参与京东方(BOE)工厂数字化项目
    ECMAScript6介绍及环境搭建
  • 原文地址:https://blog.csdn.net/weixin_41830242/article/details/133829271