Android system process phone memory tool class

Source: Internet
Author: User

Tag:android    memory     process    

public class Taskutils {/** * Gets the number of running processes * * @param context * @return */public static int Getrunningprocesscount (Contex T context) {//Get the system's task manager. Activitymanager am = (activitymanager) context.getsystemservice (context.activity_service); return Am.getrunningappprocesses (). Size ();} /** * Get the available memory of the phone * * @param context * @return The total available memory of long type data */public static long Getavailram (context context) {Activitym Anager am = (activitymanager) context.getsystemservice (Context.activity_service); Activitymanager.memoryinfo outinfo = new Memoryinfo (); Am.getmemoryinfo (outinfo); return outinfo.availmem;} /** * Get the total memory of the phone * * @return */public static long Gettotalram () {try {File file = new file ("/proc/meminfo"); FileInputStream fis = new FileInputStream (file); BufferedReader br = new BufferedReader (new InputStreamReader (FIS));//memtotal:253604 kbstring result = Br.readline (); StringBuffer sb = new StringBuffer () char[] chars = Result.tochararray (); for (char c:chars) {if (c >= ' 0 ' && C <= ' 9 ') {sB.append (c);}} Return Long.parselong (sb.tostring ()) * 1024;} catch (Exception e) {//TODO auto-generated catch Blocke.printstacktrace (); return 0;}}}

Android system process phone memory tool class

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.