[Android Pro] OnCreate multiple call issues for global application in Android

Source: Internet
Author: User

Generally application's OnCreate method is executed only once,

If the application is in a multi-process manner, the OnCreate method executes multiple times and initializes differently depending on the process name.

is to add a few more if else in the application

String processName = Osutils.getprocessname ( This, Android.os.Process.myPid ()); if(ProcessName! =NULL) {            BooleanDefaultprocess =processname.equals (constants.real_package_name); if(defaultprocess) {initappformainprocess (); } Else if(Processname.contains (": WebBrowser")) ) {initappforwebbrowseprocess (); } Else if(Processname.contains (": Wallet"))) {            }        }
/**     * @returnNULL may be returned if the specified process is not found*/     Public StaticString Getprocessname (Context cxt,intpid) {Activitymanager am=(Activitymanager) Cxt.getsystemservice (Context.activity_service); List<RunningAppProcessInfo> Runningapps =am.getrunningappprocesses (); if(Runningapps = =NULL) {            return NULL; }         for(Runningappprocessinfo procinfo:runningapps) {if(Procinfo.pid = =pid) {                returnProcinfo.processname; }        }        return NULL; }

[Android Pro] OnCreate multiple call issues for global application in Android

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.