简体   繁体   English

从其他包(主包)中的活动 A 中打开不同包/文件夹中的活动 B

[英]open activity B in different package/folder from activity A in other package (main package)

I'm currently working on a mobile app for our final project this sem.我目前正在为我们这个学期的最终项目开发一个移动应用程序。 I just wanna know how to open an activity in a package from another activity from a different package.我只想知道如何从另一个包中的另一个活动打开包中的活动。

Example:例子:

FirstActivity in com.example.package1 SecondActivity in Package2 Package2 is inside in the com.example.package1 com.example.package1 中的 FirstActivity Package2 中的 SecondActivity Package2 在 com.example.package1 中

"I want to open SecondActivity when a button is clicked in FirstActivity" “我想在 FirstActivity 中单击按钮时打开 SecondActivity”

The underlined class is the 2nd Activity and the highlighted one is the 1st activity.带下划线的类是第二个活动,突出显示的类是第一个活动。

Here's the code from the MM_Play.class (first activity)这是 MM_Play.class 中的代码(第一个活动)

Here's the code in the AndroidManifest.xml这是 AndroidManifest.xml 中的代码

I hope you can help to my problem.我希望你能帮助我的问题。 Stay safe always my fellow programmers.永远保持安全,我的程序员伙伴们。

Please try this way by import second activity class in first activity请通过在第一个活动中导入第二个活动类来尝试这种方式

Inside onClickListener in First activity在第一个活动中的 onClickListener 内部

Intent intent = new Intent(FirstActivity.this, SecondActivity.class);
startActivity(intent)

Add activity in your manifest file like this:在您的清单文件中添加活动,如下所示:

<activity
        android:name=". Your folder name where Second Activity is present then . 
        (Second Activity Name)"/>

In java file like this:在这样的java文件中:

Intent intent = new Intent(FirstActivit.this,Second activity.class);
start activity(intent)

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

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