下面列出了android.app.Service#getClass ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public void startService(final Context context, final Service... services) {
Thread serviceThread = new Thread(new Runnable() {
@Override
public void run() {
for (Service s : services) {
if (!ServiceUtils.isServiceRunning(context, s.getClass()
.getName())) {
Intent i = new Intent(context, s.getClass());
context.startService(i);
ZogUtils.printLog(ServiceManager.class,
"start service " + s.getClass().getName());
}
}
}
});
serviceThread.start();
}
/**
* 在插件服务中停止服务。近似于Service.stopSelf
* 注意:此方法应在插件服务中被调用
*
* @param s 要停止的插件服务
* @see android.app.Service#stopSelf()
*/
public static void stopSelf(Service s) {
Intent intent = new Intent(s, s.getClass());
try {
PluginMgrFacade.stopService(intent);
} catch (Throwable e) {
if (LOGR) {
LogRelease.e(PLUGIN_TAG, "pss.ss: pf f", e);
}
}
}
public void stopService(final Context context, final Service... services) {
for (Service s : services) {
Intent service = new Intent(context, s.getClass());
context.stopService(service);
}
}
public void restartService(final Context context, final Service... services) {
System.out.println("ServiceManager restartService");
stopService(context, services);
for (Service s : services) {
Intent service = new Intent(context, s.getClass());
context.startService(service);
}
}
public Builder(Service service) {
this(new ComponentName(service, service.getClass()));
}