Service Management class-----Activitymanager

Source: Internet
Author: User

Ndroid.app.ActivityManager

This class is primarily used to manage activities on all devices.

Permissions: Android.permission.GET_TASKS

Method: | Return type Method |

1.list<activitymanager.recenttaskinfo> getrecenttasks (int maxnum, int flags)

Returns a collection of application information that the user has recently used. The first parameter is the maximum number, and the second parameter is only activitymanager.recent_with_excluded before API11. This method may be discarded later, Google is recommended for debug use.

(1) Recenttaskinfo class, mainly some fields

1.1 Intent Baseintent Get the activity that can jump to this task, that is, through this Intent to start this Intent point to the program.

The 1.2 int ID gets the identity of this task, and if it is-1, the program is not started and the other numbers indicate that it is started.

1.3 The unique value of the Int persistentid task.

1.4 Intent baseintent Start Task Intent

The task bar (long press the Home key or the menu key or click on the task key) in the task is mainly obtained by this method.

[Java]View Plaincopy
    1. Final list<activitymanager.recenttaskinfo> recenttasks =
    2. Am.getrecenttasks (Max_tasks, activitymanager.recent_ignore_unavailable);

Click Start Task

[Java]View Plaincopy
  1. if (Ad.taskid >= 0) {
  2. //This is a active task; it should just go to the foreground.
  3. Am.movetasktofront (Ad.taskid, Activitymanager.move_task_with_home,
  4. opts);
  5. } Else {
  6. Intent Intent = ad.intent;
  7. Intent.addflags (intent.flag_activity_launched_from_history
  8. | Intent.flag_activity_task_on_home
  9. | Intent.flag_activity_new_task);
  10. if (DEBUG) log.v (TAG, "starting activity" + intent);
  11. Context.startactivityasuser (Intent, opts,
  12. new Userhandle (userhandle.user_current));
  13. }

Swipe Delete Task (hide method, requires system permissions Android.permission.REMOVE_TASKS)

[Java]View Plaincopy
    1. Am.removetask (Ad.persistenttaskid, activitymanager.remove_task_kill_process);

Force stop app in Settings (hide, requires non-public permissions)

[Java]View Plaincopy
    1. Activitymanager am = (activitymanager) getactivity (). Getsystemservice (
    2. Context.activity_service);
    3. Am.forcestoppackage (Pkgname);

2.list<activitymanager.runningappprocessinfo> getrunningappprocesses ()

Returns the collection of processes for a running program on the device.

(1) Runningappprocessinfo class, mainly some fields

1.1 int importance The value of this field, if Importance_foreground (100), represents the process running as the previous segment, and Importance_background (400) represents the background run. There are some other values.

1.2 int Importancereasoncode A field that interprets the process with 3 values Reason_unknown (0), Reason_provider_in_use (1), and Reason_service_in_use (2). There is no reason, the content provider in the program is used by other programs, the same as the previous reason.

1.3 int Importancereasonpid When the value of Importancereasoncode is not 0 o'clock this field represents the PID value of other programs in 1.2, otherwise the value is 0.

1.4 ComponentName Importancereasoncomponent When the value in Importancereasoncode is not 0 o'clock, this field represents the componentname of other programs in 1.2, otherwise null.

1.5 The PID value of the int PID process.

1.6 int UID User ID.

1.7 String ProcessName process name, which is actually equal to the package name (content provider immunity).

1.8 string[] PkgList all the main packages in the program, this test comes out, the general program has only one element, but the system comes with the program and has a content provider has several packages.

3 list<activitymanager.runningtaskinfo> getrunningtasks (int maxnum)

Returns the maximum number of returned programs in a running program, in the order in which the most recently opened program is returned, which is the first to return the newly used program. The return value may be empty.

(1) Runningtaskinfo class, mainly provides fields

1.1 ComponentName baseactivity represents the componentname of the logged activity, which can be used to start the program represented by this return value.

1.2 int ID A Unique identifier for this task.

1.3 int numactivities Number of activities in the this task.

1.4 int numrunning Number of activities that is currently running (not stopped and persisted) in this T Ask.

1.5 ComponentName topactivity There is the componentname represented by the activity on top of the stack . The user can use this method to get the componentname of the activity currently being displayed .

[Java]View Plaincopy
    1. Activitymanager am = (activitymanager) context.getsystemservice (Context.activity_service);
    2. ComponentName cn = Am.getrunningtasks (1). Get (0). topactivity;

4.void killbackgroundprocesses (String packagename)

Kill background Process, parameter is the (main) package name of the program to be killed. Permission Android.permission.KILL_BACKGROUND_PROCESSES is required.

5. list<activitymanager.runningserviceinfo> getrunningservices (int maxnum)

Get all the running service.

(1) Runningserviceinfo class, mainly provides fields.

1.1 Long Activesince The first time the service has been launched to the current period.

PID of 1.2 int PID process

1.3 int UID User ID.

1.4 String Process Name (package name?) )。

1.5 Long Lastactivitytime last active service to present time

1.6 Componenname Service Gets the component name of the service, which is the ability to start the service

1.7 Long restarting if the value of this field is not 0, then the service is not started and will be self-initiated after the time period of the return value.

6. Void Restartpackage (String packagename)

Now this method equals method 4, and calling this method equals calling method 4.

Service Management class-----Activitymanager

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.