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

时间:2022-01-11 20:53:28

I have 3 android projects, which they have different functions. Each project has its own mainActivity class. Now I want to merge the 3 projects into one. I can think of 2 ways to do it.

我有3个android项目,它们有不同的功能。每个项目都有自己的mainActivity类。现在我想将3个项目合并为一个。我可以想到两种方法。

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. However, each project has its own mainActivity class. I don't know whether I should preserve one mainActivity class only and rename other 2 mainActivity class of other 2 projects. It seems that it is easy to encounter lots of bugs and messy.

第一种方式:打开3个项目中的一个,然后创建新的java类和xml文件,并从其他2个项目中复制所有java类和xml内容。但是,每个项目都有自己的mainActivity类。我不知道是否应该只保留一个mainActivity类,并重命名其他2个项目的其他2个mainActivity类。似乎很容易遇到很多错误和杂乱。

Second way: use 3 buttons. onclick first button then the mainActivity class of project 1 will run. onclick second button then the mainActivity class of project 2 will run. onclick third button then the mainActivity class of project 3 will run. 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 ?

第二种方式:使用3个按钮。 onclick第一个按钮然后将运行项目1的mainActivity类。 onclick第二个按钮然后将运行项目2的mainActivity类。 onclick第三个按钮然后将运行项目3的mainActivity类。但是,我不知道是否可以这样做。如果是,我该怎么办?我知道如何点击一个按钮去进行一项新活动,但同样适用于onclick转到其他项目的mainActivity?

I prefer the second method, if it is possible to do so. Could anyone help ? Please advise , thanks.

如果有可能的话,我更喜欢第二种方法。有人可以帮忙吗?请指教,谢谢。

2 个解决方案

#1


0  

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!

这认为这是不可能的,你需要导入1个项目中的所有函数......你不能用一个按钮打开其他项目,你需要在你需要的全局项目中导入类和活动,或者创建一个新类,但是你不能打电话给其他项目。祝好运!

#2


-1  

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

#1


0  

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!

这认为这是不可能的,你需要导入1个项目中的所有函数......你不能用一个按钮打开其他项目,你需要在你需要的全局项目中导入类和活动,或者创建一个新类,但是你不能打电话给其他项目。祝好运!

#2


-1  

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