本文整理匯總了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;
}