简体   繁体   English

如何检查android中所有正在运行的服务?

[英]How to check all the running services in android?

I want to access and see how many and which services are running in background.我想访问并查看后台运行了多少服务和哪些服务。

I want the exactly same functionality as we can access by我想要与我们可以访问的完全相同的功能

Menu->Setting->Applications->Running Services菜单->设置->应用程序->运行服务

on our android base mobile phones or tabs.在我们的 android 基础手机或标签上。 Can anybody tell me what function or classes have been used in android source code to provide this functionality.谁能告诉我在 android 源代码中使用了哪些函数或类来提供此功能。

And if there is any way by which i can access this in-build list of background running services which i have mentioned above then please do tell me because its better for me to use in-build one instead of creating the whole new one.如果有什么方法可以访问我上面提到的后台运行服务的内置列表,那么请告诉我,因为使用内置服务对我来说更好,而不是创建全新的服务。

Check This Link:检查此链接:

How to Access Android's List of Running Apps in 6.0 Marshmallow and Above如何在 6.0 Marshmallow 及更高版本中访问 Android 的运行应用程序列表


Where to Find Running Services in Android 6.0 Like I noted earlier, on在哪里可以找到在 Android 6.0 中运行的服务 就像我之前提到的,在

Android 5.x and below, you could see what was going on by jumping in Settings > Apps > Running. Android 5.x 及更低版本,您可以通过跳转到设置 > 应用程序 > 运行来查看发生了什么。 This shows both running processes and services, along with how much memory (RAM) is being used by System and Apps, as well as how much is still available.这显示了正在运行的进程和服务,以及系统和应用程序使用了多少内存 (RAM),以及还有多少可用。


To find the same menu in Marshmallow, you'll first need to enable Developer Options.要在 Marshmallow 中找到相同的菜单,您首先需要启用开发人员选项。 Do this by heading into Settings, then About Phone.通过进入“设置”,然后“关于手机”来执行此操作。


Once there, find the Software info section—that will be a separate entry on some phones (Samsung, LG), but not on others, like Nexus devices.在那里,找到“软件信息”部分——这在某些手机(三星、LG)上是一个单独的条目,但在其他手机(如 Nexus 设备)上则不是。 You're looking for the Build Number, so you may have to poke around a bit before you find it.您正在寻找内部版本号,因此在找到它之前您可能需要四处看看。 The下面的前两张图 were taken from the Samsung Galaxy S7 Edge, and the last one from the Nexus 6P.取自三星 Galaxy S7 Edge,最后一个取自 Nexus 6P。 As you can see, the build is in two different places.如您所见,构建位于两个不同的位置。



When you've found it, tap it seven times.找到后,点击它七次。 You'll see a toast notification letting you know how many are left until “you become a developer.”您会看到一个 Toast 通知,让您知道在“您成为开发人员”之前还剩下多少。 Once it's been tapped seven times, a new menu will be unlocked just above About Phone in the main Settings menu.点击七次后,将在主设置菜单中的关于手机上方解锁一个新菜单。


Back in Settings, head into Developer Options.返回设置,进入开发者选项。 You should see “Running services” a little way down this menu—that's what you're looking for.您应该会在此菜单的下方看到“运行服务”——这就是您要查找的内容。 Once you tap “Running services,” you should be presented with a familiar screen—it's exactly the same one from Lollipop.一旦您点击“正在运行的服务”,您应该会看到一个熟悉的屏幕——它与 Lollipop 的屏幕完全相同。 Just in a different spot.只是在不同的地方。


Here is a complete answer.这是一个完整的答案。

Step 1. First you need to declare and initialize few variables :-第 1 步。首先你需要声明和初始化几个变量:-

private static final String APP_DETAILS_PACKAGE_NAME = “com.android.settings”; // Here you need to define the  package name

private static final String SCREEN_CLASS_NAME = “com.android.settings.RunningServices”; // Here you need to define the class name but NOTICE!! you need to define its full name including  package name.

Step 2. Instantiate an Intent步骤 2. 实例化一个意图

Intent intent = new Intent();

Step 3. Set Action to ACTION_VIEW步骤 3. 将操作设置为 ACTION_VIEW

intent.setAction(Intent.ACTION_VIEW);

Step 3. Set class name inside the intent as we know that package can have more than one activity.步骤 3. 在意图中设置类名,因为我们知道包可以有多个活动。 So Intent needs something to match the Activity inside the package name.所以 Intent 需要一些东西来匹配包名中的 Activity。

intent.setClassName(APP_DETAILS_PACKAGE_NAME,  SCREEN_CLASS_NAME); //Here you need to set package name as well as class name so it could refer to the Package and IntentFilter of the given Activity.

Step 4. Start the Activity步骤 4. 启动活动

context.startActivity(intent); // As soon as this line will be executed Running Service screen will be displayed as a foreground activity.

In above example if you want to access some different screen then change the APP_DETAILS_PACKAGE_NAME and SCREEN_CLASS_NAME as per your need.在上面的示例中,如果您想访问一些不同的屏幕,请根据需要更改 APP_DETAILS_PACKAGE_NAME 和 SCREEN_CLASS_NAME。

I really don't know that this method is documented or not but it works like charm for me.我真的不知道这种方法是否被记录在案,但它对我来说很有魅力。

simple steps简单的步骤

  1. turn on develop mode on your device在您的设备上打开开发模式
  2. go to develop settings and try to find "running services"去开发设置并尝试找到“正在运行的服务”
  3. as a result you will get list of run services结果,您将获得运行服务列表

You check in your device您签入您的设备

1- Go to mobile setting 2- Click on Application manager 3- Slide left to see running applications 1- 转到移动设置 2- 单击应用程序管理器 3- 向左滑动以查看正在运行的应用程序

This is the place where you'll find running application along running services as shown in attached image:这是您可以在运行的服务中找到正在运行的应用程序的地方,如附图所示:

在此处输入图片说明

Presumably, it is calling getRunningServices() on ActivityManager .据推测,它正在ActivityManager上调用getRunningServices() There is no documented Intent to go straight to that screen.没有直接进入该屏幕的记录Intent

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM