英文:
Open Activity From Another Module Giving Circular Dependency
问题
我正在开发一个 Android 应用程序,需要调用位于主模块中的 Activity。我面临的问题是,包含一个 Fragment 的子模块无法访问主模块中的 Activity。
我刚刚查看了以下链接以寻求帮助,但无法解决访问主模块活动的问题。
以下是我从中调用父模块的 Fragment 类:
Intent intent = new Intent(getActivity(), QRScannedResultActivity.class);
intent.putExtra("sendedscannedcontent", resultString);
startActivity(intent);
从调用主模块的函数的图像如下所示:
(图像链接已省略)
模块层次结构如下图所示:
(图像链接已省略)
在 Gradle 中添加 implementation project(path:':app')
后,出现循环依赖错误:
(图像链接已省略)
英文:
I am working on Android app that has to call to Activity which lies in the Main Module. The Issue I am facing is, the Sub Module which contains a Fragment is unable to Access to Activity in the Main Module.
I have Just seen these links for the Help but the Problem of Accessing to main module activity could not resolved..
Here is the Fragment Class in the Module from where I am calling to Parent Module..
Intent intent = new Intent(getActivity(), QRScannedResultActivity.class);
intent.putExtra("sendedscannedcontent", resultString);
startActivity(intent);
the Function Image from where I am Calling to main
The Module Hirarchy looks like
After Adding implementation project(path:':app')
in Gradle it Gives the Circular Dependency Error
答案1
得分: 1
你可以使用 Class.forName()
获取 QRScannedResultActivity
类的引用。
假设 QRScannedResultActivity
位于 com.maximus.technologies.view
包中,如果不是这种情况,请替换包路径。
try {
Intent intent = new Intent(getActivity(),
Class.forName("com.maximus.technologies.views.QRScannedResultActivity"));
intent.putExtra("sendedscannedcontent", resultString);
startActivity(intent);
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
英文:
You can use Class.forName()
to get QRScannedResultActivity
class reference
Assuming that QRScannedResultActivity
is in com.maximus.technologies.view
package, replace the package path if that's not the case
try {
Intent intent = new Intent(getActivity(),
Class.forName("com.maximus.technologies.views.QRScannedResultActivity"));
intent.putExtra("sendedscannedcontent", resultString);
startActivity(intent);
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论