Is there a way to get current process name in Android

后端 未结 11 1801
-上瘾入骨i
-上瘾入骨i 2020-12-03 00:59

I set an Android:process=\":XX\" for my particular activity to make it run in a separate process. However when the new activity/process init, it will call my Application:onC

11条回答
  •  天命终不由人
    2020-12-03 01:16

    There is a method in ActivityThread class, You may use reflection to get the current processName. You don't need any loop or tricks. The performance is best compares to other solution. The limitation is you can only get your own process name. It's not a big deal since it covers most usage cases.

        val activityThreadClass = XposedHelpers.findClass("android.app.ActivityThread", param.classLoader)
        val activityThread = XposedHelpers.callStaticMethod(activityThreadClass, "currentActivityThread")
        val processName = XposedHelpers.callStaticMethod(activityThreadClass, "currentProcessName")
    

提交回复
热议问题