简体   繁体   中英

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

"I want to open SecondActivity when a button is clicked in FirstActivity"

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)

Here's the code in the 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

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:

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

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