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

2023-09-05 00:22:19 作者:仅仅只是囬忆つ

我要访问,看看有多少,哪些服务在后台运行。

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

这是我们的Andr​​oid基础的移动电话或制表符。谁能告诉我什么功能或类已经被用于Android源$ C ​​$ C提供此功能。

on our android base mobile phones or tabs. Can anybody tell me what function or classes have been used in android source code to provide this functionality.

如果有任何方式,我可以访问后台运行,我在上面已经提到的服务,那么请你告诉我在建造列表中,因为它更好地为我使用,建立酮替代创建整个新的。

推荐答案

下面是一个完整的答案。

Here is a complete answer.

步骤1.首先,你需要声明和初始化几个变量: -

Step 1. First you need to declare and initialize few variables :-

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.

步骤2.实例化一个意向

Step 2. Instantiate an Intent

Intent intent = new Intent();

第三步:将动作设置为ACTION_VIEW

Step 3. Set Action to ACTION_VIEW

intent.setAction(Intent.ACTION_VIEW);

因为我们知道,包可以有多个活动的意图内第3步:设置类名。因此,意图需要的东西相匹配的包名内的活动。

Step 3. Set class name inside the intent as we know that package can have more than one activity. So Intent needs something to match the Activity inside the package name.

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.

步骤4.启动活动

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

在上面的例子中,如果你想访问一些不同的屏幕,然后改变APP_DETAILS_PACKAGE_NAME和SCREEN_CLASS_NAME根据您的需要。

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.

我真的不知道,这种方法是记录或没有,但它的作品般的魅力对我来说。

I really don't know that this method is documented or not but it works like charm for me.