提示你该服务已经绑定过了,你可以设置个是否绑定的标志来标识,已经绑定了就不执行bindService
另外,服务不会起多个的,可以去百度下service的
另外,服务不会起多个的,可以去百度下service的
解决方案 »
- 如何用c或者c++代码获取默认DNS服务器的ip?
- 开发android 更新了一下sdk 再打开eclipse时就无法创建 Android Appication project 项目了 怎么办
- 使用堆栈管理activity,第二次启动时进入程序黑屏?
- 请问谁知道如何开启nexus one的闪光灯?
- android怎么实现禁止某个程序或软件运行?
- 切换语系成中文后 字体效果消失了!
- 代码死循环求助
- 求android studio 下载地址,最好有中文的
- Android recyclerview嵌套ViewPager,再嵌套recycylerView性能优化问题
- 大佬留步,请问Android8.1怎么获取外置sd卡读写权限
- 大神求救Android、setOnClickListener侦听总提示错误
- 请问一下AsyncTask的用法
代码
// 判断服务是否开启
public static boolean isServiceRunning(Context mContext, String className) { boolean isRunning = false;
ActivityManager activityManager = (ActivityManager) mContext
.getSystemService(Context.ACTIVITY_SERVICE);
List<ActivityManager.RunningServiceInfo> serviceList = activityManager
.getRunningServices(30); if (!(serviceList.size() > 0)) {
return false;
} for (int i = 0; i < serviceList.size(); i++) {
if (serviceList.get(i).service.getClassName().equals(className) == true) {
isRunning = true;
break;
}
}
return isRunning;
}调用
isServiceRunning(MainActivity.this, myServise.class.getName())
我调试了一下,我发现你这个方法 不成功的 是不是不是getName 是GetClass啊
protected void onDestroy(){
super.onDestroy();
unbindService(serviceconnection);
}
解决了