Every Activity in Android is a Process,or One Application is one process

前端 未结 4 692
野的像风
野的像风 2020-12-02 19:22

In this page, http://androidapps.org.ua/androidintro_ipc.html , intent switching between activities is described as Inter Process Communication. Now I am confused whether e

4条回答
  •  南笙
    南笙 (楼主)
    2020-12-02 19:49

    You are able to use [multi-processing][1] application approach using Manifest component element with android:process attribute. It is applied for all components

    
        
        
        
        
     
    

    Additionally element also supports an android:process attribute, to set a default value that applies to all components.

    By default a component process name is a package name. It can be overrode by or (the biggest priority) element

    Please note that each app process has is own Application instance. As a result if you define your own custom application class () be ready that at least Application.onCreate() will be called every time during creating a new process.

    JFYI, please note that ContentProvider.onCreate() is called before any other inits like Application.onCreate() etc. It can be helpful to get a Context for your library without extra code from dev side

    To get process name you can use the next method

    @Nullable
    public static String getProcessName(Context context) {
        ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
        for (ActivityManager.RunningAppProcessInfo processInfo : activityManager.getRunningAppProcesses()) {
            if (processInfo.pid == android.os.Process.myPid()) {
                return processInfo.processName;
            }
        }
        return null;
    }
    

    or via Terminal enter adb shell ps | grep [1]: https://developer.android.com/guide/components/processes-and-threads#Processes

提交回复
热议问题