Search code examples
javaandroid

Android Studio Start Activity from Module


I have created an *.aar File from a Android Studio project. This file I have successfully imported to another Android Studio project file. Now I want start the activity from the included libraries. But I am hanging and I try hour to hour...

In which file I have to include the statement like this?

 public void button_to_start_the_activity(View view)
{
    Intent intent = new Intent(StartActivity.this, MainActivity.class);
    startActivity(intent);
}

Should I implement this in the module java file or in the application java file? (Please check this out, I have not found a activity java file in my module) Steps before, I have created a new activity in my main-project and I was able to start the activity without trouble.

Okay... Next question:

In the Main Manifest,...what to hell I shout declare in android:name"....?...." like this:

<activity
        android:name="....??????...."
        android:label="DLC"
        android:screenOrientation="portrait"
        android:theme="@style/Theme.AppCompat.NoActionBar">
    </activity>

Maybe, or for sure, simple question... But I try to learn a little bit AS since a week... For your understanding, I will try to explain my project with simple words:

Try to merge two app projects in one app!

I have created a app, then I have created an another app. Now I want to merge. Simple startpage (already exist) with the function to call the both activities.


Solution

  • My final solution to start a module activity in the main app (For people with less experience like me)

    1. Create in Android Studio a module from the existing app

    2. Open Main-Project an insert the new module (File-->New-->Import Modul)

    3. Right click on project folder. Search App (left side), then dependencies (right side) --> Add new from module --> Add your module

    4. Check your build.cradle (Main-App) for compile project(':yourmodul')

    5. Add this in your activity (from the Main-App)

        public class StartActivity extends AppCompatActivity {
      
      
        public void gotocalc(View view)
        {
        Intent intent = new Intent(StartActivity.this, YourModulClass.class);
        startActivity(intent);
        }
      
    6. gotocalc is for start with a button android:onClick="gotocalc" set in your layout.xml in the Main App.

    7. Clean, Rebuild