Intent resolved to different process in Espresso test for APK (without source code)

ぐ巨炮叔叔 提交于 2019-12-13 05:08:24

问题


I'm trying to launch an activity(of another APK) via instrumentation object. I'm able to pull the class of that APK in classToInvestigate object but cannot start the activity through

instrumentation.startActivitySync(startIntent2);

Below is the complete code of launching activity via instrumentation object.

private Object xyz(String packageName, String className){
        Object plugin = null;
        try {
            PackageManager packageManager = context.getPackageManager();
            ApplicationInfo appInfo = packageManager.getApplicationInfo(packageName, 0);
            DexFile df = new DexFile(appInfo.sourceDir);
            ClassLoader cl = context.getClassLoader();
            Class classToInvestigate = df.loadClass(className, cl);

            Intent startIntent2 = new Intent(Intent.ACTION_MAIN);
            startIntent2.setClassName(packageName, classToInvestigate.getName());
            startIntent2.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

            instrumentation.startActivitySync(startIntent2);
            instrumentation.waitForIdleSync();


            plugin = classToInvestigate.newInstance();


        } catch (Exception e) {
            System.out.println("EXCEPTION");
        }
        finally{
            return plugin;
        }
    }

Specifically at line instrumentation.startActivitySync(startIntent2); the Android studio throws an error

java.lang.RuntimeException: Intent in process com.main.apk resolved to different process com.abc.xyz Intent

来源:https://stackoverflow.com/questions/55721618/intent-resolved-to-different-process-in-espresso-test-for-apk-without-source-co

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!