skip to Main Content

I’m currently working on a mobile app for our final project this semester. I want to 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

2

Answers


  1. 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)
    
    Login or Signup to reply.
  2. 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)
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search