简体   繁体   中英

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. My question is: how do I actually use the information from the module inside my Android App? Do I just do B b = new B(); inside 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
b = new B();

If those modules are Android UI elements like Activities/Fragments etc then you have pass an Intent to start them. Refer to Android documentation here

 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 ):-

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

HTH

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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