问题
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