简体   繁体   English

如何从Android中的主应用访问模块?

[英]How to access module from main app in Android?

I have a main Android App, called A and a module called B. I have imported the module and added the correct dependencies. 我有一个名为A的主Android应用程序,一个名为B的模块。我已导入该模块并添加了正确的依赖项。 My question is: how do I actually use the information from the module inside my Android App? 我的问题是:我实际上如何使用Android应用程序内部模块中的信息? Do I just do B b = new B(); 我只是做B b = new B(); inside A? 在A里面? I think that this method is more related to accessing other classes within the same module. 我认为该方法与访问同一模块中的其他类更相关。 Is there a specific way to access modules that is different from accessing other classes within the same module? 是否有一种不同于访问同一模块内其他类的特定方法来访问模块?

Am assuming your modules are Java Classes, just instantiate them the way you are proposing 假设您的模块是Java类,只需按照您提出的方式实例化它们
b = new B();

If those modules are Android UI elements like Activities/Fragments etc then you have pass an Intent to start them. 如果这些模块是Android UI元素(例如“活动/片段”等),那么您已经传递了一个Intent以启动它们。 Refer to Android documentation here 在此处参考Android文档

 Intent intent = new Intent(this, YourActivityB.class);
 EditText editText = (EditText) findViewById(R.id.editText);
 String message = editText.getText().toString();
 intent.putExtra(EXTRA_MESSAGE, message);
 startActivity(intent);

Similarly for an Android service (documentation here ):- 同样对于Android服务( 此处的文档):-

Intent intent = new Intent(this, HelloService.class);
startService(intent);

HTH HTH

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM