本文整理汇总了Java中android.app.ActivityManager.RunningServiceInfo方法的典型用法代码示例。如果您正苦于以下问题:Java ActivityManager.RunningServiceInfo方法的具体用法?Java ActivityManager.RunningServiceInfo怎么用?Java ActivityManager.RunningServiceInfo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.app.ActivityManager
的用法示例。
在下文中一共展示了ActivityManager.RunningServiceInfo方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: isMyServiceRunning
import android.app.ActivityManager; //导入方法依赖的package包/类
private boolean isMyServiceRunning(Class<?> serviceClass) {
ActivityManager manager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
if (manager != null) {
for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
if (serviceClass.getName().equals(service.service.getClassName())) return true;
}
}
return false;
}
示例2: onCreate
import android.app.ActivityManager; //导入方法依赖的package包/类
@Override
public void onCreate() {
mAm = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
// catch up in case we crashed but other processes are still running
List<ActivityManager.RunningServiceInfo> svcs = mAm.getRunningServices(256);
for (ActivityManager.RunningServiceInfo svc : svcs) {
if (svc.service.getPackageName().equals(getPackageName())) {
Log.v(TAG, "discovered running service: " + svc.process + " (" + svc.pid + ")");
startTrackingProcess(svc.pid, svc.process,
System.currentTimeMillis() - (SystemClock.elapsedRealtime() - svc.activeSince));
}
}
List<ActivityManager.RunningAppProcessInfo> procs = mAm.getRunningAppProcesses();
for (ActivityManager.RunningAppProcessInfo proc : procs) {
final String pname = proc.processName;
if (pname.startsWith(getPackageName())) {
Log.v(TAG, "discovered other running process: " + pname + " (" + proc.pid + ")");
startTrackingProcess(proc.pid, pname, System.currentTimeMillis());
}
}
}
示例3: isServiceRunning
import android.app.ActivityManager; //导入方法依赖的package包/类
/**
* 判断service是否正在运行
*
* @param mContext
* @param className
* @return
*/
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(200);
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;
}
// Log.d("Service:", "isServiceRunning: "+serviceList.get(i).service.getClassName());
}
return isRunning;
}
示例4: getServices
import android.app.ActivityManager; //导入方法依赖的package包/类
@Override
public VParceledListSlice<ActivityManager.RunningServiceInfo> getServices(int maxNum, int flags, int userId) {
synchronized (mHistory) {
List<ActivityManager.RunningServiceInfo> services = new ArrayList<>(mHistory.size());
for (ServiceRecord r : mHistory) {
if (r.process.userId != userId) {
continue;
}
ActivityManager.RunningServiceInfo info = new ActivityManager.RunningServiceInfo();
info.uid = r.process.vuid;
info.pid = r.process.pid;
ProcessRecord processRecord = findProcessLocked(r.process.pid);
if (processRecord != null) {
info.process = processRecord.processName;
info.clientPackage = processRecord.info.packageName;
}
info.activeSince = r.activeSince;
info.lastActivityTime = r.lastActivityTime;
info.clientCount = r.getClientCount();
info.service = ComponentUtils.toComponentName(r.serviceInfo);
info.started = r.startId > 0;
services.add(info);
}
return new VParceledListSlice<>(services);
}
}
示例5: isMyServiceRunning
import android.app.ActivityManager; //导入方法依赖的package包/类
public static boolean isMyServiceRunning(Context context, Class<?> serviceClass) {
ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
if (serviceClass.getName().equals(service.service.getClassName())) {
return true;
}
}
return false;
}
示例6: isRunning
import android.app.ActivityManager; //导入方法依赖的package包/类
/**
* 判断服务是否正在运行
* @param context
* @param serviceName 服务的全类名
* @return
*/
public static boolean isRunning(Context context, String serviceName) {
// ActivityManager 进程的管理者
ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
List<ActivityManager.RunningServiceInfo> runningServices = am.getRunningServices(1000); // 参数
for (ActivityManager.RunningServiceInfo info : runningServices) {
String className = info.service.getClassName();
if (serviceName.equals(className)) {
return true;
}
}
return false;
}
示例7: isMyServiceRunning
import android.app.ActivityManager; //导入方法依赖的package包/类
public static boolean isMyServiceRunning(Class<?> serviceClass, Context context) {
ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
if (serviceClass.getName().equals(service.service.getClassName())) {
return true;
}
}
return false;
}
示例8: isServiceRunning
import android.app.ActivityManager; //导入方法依赖的package包/类
public static boolean isServiceRunning(Class<?> serviceClass, Context context) {
ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
if (serviceClass.getName().equals(service.service.getClassName())) {
return true;
}
}
return false;
}
示例9: isMyServiceRunning
import android.app.ActivityManager; //导入方法依赖的package包/类
/**
* Function to check service running of not
*
* @param context Application context
* @param serviceClass Service class
* @return Service running or not
*/
public static boolean isMyServiceRunning(Context context, Class<?> serviceClass) {
ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
for (ActivityManager.RunningServiceInfo service : manager
.getRunningServices(Integer.MAX_VALUE)) {
if (serviceClass.getName().equals(service.service.getClassName())) {
return true;
}
}
return false;
}
示例10: isServiceRunning
import android.app.ActivityManager; //导入方法依赖的package包/类
private boolean isServiceRunning(Class<LocationData> locationDataClass) {
ActivityManager manager = (ActivityManager) getContext().getSystemService(Context.ACTIVITY_SERVICE);
for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
if (locationDataClass.getName().equals(service.service.getClassName())) {
return true;
}
}
return false;
}
示例11: isMyServiceRunning
import android.app.ActivityManager; //导入方法依赖的package包/类
private boolean isMyServiceRunning(Class<?> serviceClass) {
ActivityManager manager = (ActivityManager) getActivity().getSystemService(Context.ACTIVITY_SERVICE);
for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
if (serviceClass.getName().equals(service.service.getClassName())) {
return true;
}
}
return false;
}
示例12: isServiceRunning
import android.app.ActivityManager; //导入方法依赖的package包/类
/**
* Method to check if the service to get location is already running
*
* @param context - Used to access the System services
* @param serviceClass - Class that has to be checked if its instance is running
* @return - boolean on success
*/
public static boolean isServiceRunning(Context context, Class<?> serviceClass) {
ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
if (serviceClass.getName().equals(service.service.getClassName())) {
return true;
}
}
return false;
}
示例13: isWorking
import android.app.ActivityManager; //导入方法依赖的package包/类
public boolean isWorking() {
ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
String serviceName = DNSService.class.getName();
for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
if (serviceName.equals(service.service.getClassName())) {
return true;
}
}
return false;
}
示例14: onDestroy
import android.app.ActivityManager; //导入方法依赖的package包/类
@Override
protected void onDestroy() {
ActivityManager manager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
if (CacheService.class.getName().equals(service.service.getClassName())) {
stopService(new Intent(this, CacheService.class));
}
}
super.onDestroy();
}
示例15: isMyServiceRunning
import android.app.ActivityManager; //导入方法依赖的package包/类
private boolean isMyServiceRunning(Class<?> serviceClass) {
ActivityManager manager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
if (serviceClass.getName().equals(service.service.getClassName())) {
return true;
}
}
return false;
}