简体   繁体   English

是否可以调用另一个项目的mainActivity类?

[英]Is it possible to call the mainActivity class of another project ?

I have 3 android projects, which they have different functions. 我有3个android项目,它们具有不同的功能。 Each project has its own mainActivity class. 每个项目都有其自己的mainActivity类。 Now I want to merge the 3 projects into one. 现在,我想将3个项目合并为一个。 I can think of 2 ways to do it. 我可以想到两种方法。

First way: open one of the 3 projects, then create new java class and xml files and copy all java class and xml content from other 2 projects. 第一种方式:打开3个项目中的一个,然后创建新的Java类和xml文件,并从其他2个项目中复制所有Java类和xml内容。 However, each project has its own mainActivity class. 但是,每个项目都有其自己的mainActivity类。 I don't know whether I should preserve one mainActivity class only and rename other 2 mainActivity class of other 2 projects. 我不知道是否只应保留一个mainActivity类,并重命名其他2个项目的其他2个mainActivity类。 It seems that it is easy to encounter lots of bugs and messy. 似乎很容易遇到许多错误和混乱。

Second way: use 3 buttons. 第二种方式:使用3个按钮。 onclick first button then the mainActivity class of project 1 will run. 单击第一个按钮,然后将运行项目1的mainActivity类。 onclick second button then the mainActivity class of project 2 will run. 单击第二个按钮,然后将运行项目2的mainActivity类。 onclick third button then the mainActivity class of project 3 will run. 单击第三个按钮,然后将运行项目3的mainActivity类。 However, I don't know whether it is possible to do so. 但是,我不知道是否可以这样做。 If yes, How can I do so ? 如果是,我该怎么办? I know how to onclick on a button to go to a new activity but is that the same to apply to onclick going to other project's mainActivity ? 我知道如何在按钮上单击onclick来进行新的活动,但是将onclick应用于其他项目的mainActivity是否也一样?

I prefer the second method, if it is possible to do so. 如果可能的话,我更喜欢第二种方法。 Could anyone help ? 有人可以帮忙吗? Please advise , thanks. 请指教,谢谢。

This think it's impossible, you need to import all functions in 1 project... You can't open other project with one button, you need to import classes and activities in your global project that you needs or create a new classes, but you can't call other projects. 这认为这是不可能的,您需要在一个项目中导入所有功能...您不能用一个按钮打开其他项目,需要在全局项目中导入所需的类和活动或创建新的类,但是不能调用其他项目。 Good luck! 祝好运!

If you add a custom action to your activity: 如果您向活动添加自定义操作:

<activity
   android:name=".MainActivity"
   android:label="@string/app_name" >
   <intent-filter>
       <action android:name="android.intent.action.MAIN" />
       <category android:name="android.intent.category.LAUNCHER" />
   </intent-filter>
   <intent-filter>
       <action android:name="com.example.action.MYACTION" />
       <category android:name="android.intent.category.DEFAULT"/>
   </intent-filter>
</activity>

You can invoke it via implicit intent as long as the app already installed on the device: 只要设备上已经安装了应用程序,就可以通过隐式意图调用它:

Intent i = new Intent("com.example.action.MYACTION");
startActivity(i);

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

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