16
16
* author: Blankj
17
17
* blog : http://blankj.com
18
18
* time : 2016/08/02
19
- * desc : 服务相关工具类
19
+ * desc : utils about service
20
20
* </pre>
21
21
*/
22
22
public final class ServiceUtils {
@@ -26,11 +26,11 @@ private ServiceUtils() {
26
26
}
27
27
28
28
/**
29
- * 获取所有运行的服务
29
+ * Return all of the services are running.
30
30
*
31
- * @return 服务名集合
31
+ * @return all of the services are running
32
32
*/
33
- public static Set getAllRunningService () {
33
+ public static Set getAllRunningServices () {
34
34
ActivityManager am =
35
35
(ActivityManager ) Utils .getApp ().getSystemService (Context .ACTIVITY_SERVICE );
36
36
if (am == null ) return Collections .emptySet ();
@@ -44,9 +44,9 @@ public static Set getAllRunningService() {
44
44
}
45
45
46
46
/**
47
- * 启动服务
47
+ * Start the service.
48
48
*
49
- * @param className 完整包名的服务类名
49
+ * @param className The name of class.
50
50
*/
51
51
public static void startService (final String className ) {
52
52
try {
@@ -57,20 +57,20 @@ public static void startService(final String className) {
57
57
}
58
58
59
59
/**
60
- * 启动服务
60
+ * Start the service.
61
61
*
62
- * @param cls 服务类
62
+ * @param cls The service class.
63
63
*/
64
64
public static void startService (final Class <?> cls ) {
65
65
Intent intent = new Intent (Utils .getApp (), cls );
66
66
Utils .getApp ().startService (intent );
67
67
}
68
68
69
69
/**
70
- * 停止服务
70
+ * Stop the service.
71
71
*
72
- * @param className 完整包名的服务类名
73
- * @return {@code true}: 停止成功 <br>{@code false}: 停止失败
72
+ * @param className The name of class.
73
+ * @return {@code true}: success <br>{@code false}: fail
74
74
*/
75
75
public static boolean stopService (final String className ) {
76
76
try {
@@ -82,23 +82,24 @@ public static boolean stopService(final String className) {
82
82
}
83
83
84
84
/**
85
- * 停止服务
85
+ * Stop the service.
86
86
*
87
- * @param cls 服务类
88
- * @return {@code true}: 停止成功 <br>{@code false}: 停止失败
87
+ * @param cls The name of class.
88
+ * @return {@code true}: success <br>{@code false}: fail
89
89
*/
90
90
public static boolean stopService (final Class <?> cls ) {
91
91
Intent intent = new Intent (Utils .getApp (), cls );
92
92
return Utils .getApp ().stopService (intent );
93
93
}
94
94
95
95
/**
96
- * 绑定服务
96
+ * Bind the service.
97
97
*
98
- * @param className 完整包名的服务类名
99
- * @param conn 服务连接对象
100
- * @param flags 绑定选项
98
+ * @param className The name of class.
99
+ * @param conn The ServiceConnection object.
100
+ * @param flags Operation options for the binding.
101
101
* <ul>
102
+ * <li>0</li>
102
103
* <li>{@link Context#BIND_AUTO_CREATE}</li>
103
104
* <li>{@link Context#BIND_DEBUG_UNBIND}</li>
104
105
* <li>{@link Context#BIND_NOT_FOREGROUND}</li>
@@ -118,12 +119,13 @@ public static void bindService(final String className,
118
119
}
119
120
120
121
/**
121
- * 绑定服务
122
+ * Bind the service.
122
123
*
123
- * @param cls 服务类
124
- * @param conn 服务连接对象
125
- * @param flags 绑定选项
124
+ * @param cls The service class.
125
+ * @param conn The ServiceConnection object.
126
+ * @param flags Operation options for the binding.
126
127
* <ul>
128
+ * <li>0</li>
127
129
* <li>{@link Context#BIND_AUTO_CREATE}</li>
128
130
* <li>{@link Context#BIND_DEBUG_UNBIND}</li>
129
131
* <li>{@link Context#BIND_NOT_FOREGROUND}</li>
@@ -140,19 +142,19 @@ public static void bindService(final Class<?> cls,
140
142
}
141
143
142
144
/**
143
- * 解绑服务
145
+ * Unbind the service.
144
146
*
145
- * @param conn 服务连接对象
147
+ * @param conn The ServiceConnection object.
146
148
*/
147
149
public static void unbindService (final ServiceConnection conn ) {
148
150
Utils .getApp ().unbindService (conn );
149
151
}
150
152
151
153
/**
152
- * 判断服务是否运行
154
+ * Return whether service is running.
153
155
*
154
- * @param className 完整包名的服务类名
155
- * @return {@code true}: 是 <br>{@code false}: 否
156
+ * @param className The name of class.
157
+ * @return {@code true}: yes <br>{@code false}: no
156
158
*/
157
159
public static boolean isServiceRunning (final String className ) {
158
160
ActivityManager am =
0 commit comments