Multiple instantiation of Android Application object

Source: Internet
Author: User

Android application This object may be instantiated multiple times, which occurs when the android:process element is used.

The fundamental reason is that the newly opened process requires a Application Object service 4 large components.

Here is a code to get the name of the current process, through which you can determine whether the master process is running.

/** returns the name of the process and, if it is the main process, the package name*/public static String Getcurprocessname (context context) {int pid = Process.mypid (); Activitymanager Mactivitymanager = (activitymanager) context.getsystemservice ("activity"); Iterator iter = Mactivitymanager.getrunningappprocesses (). iterator (); Runningappprocessinfo Appprocess;do {if (!iter.hasnext ()) {return null;} Appprocess = (runningappprocessinfo) iter.next ();} while (appprocess.pid! = pid); return appprocess.processname;}

  

Multiple instantiation of Android Application object

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.