How to properly call mainactivity from library module on app module












0















Every time I call an activity on library module from app module the app crashes



There's a button on the app module and when it's pressed it will call an activity from the library module but every time I do that the app just crashes



Below is the code on the app module in which the intent will call a main activity on library module



 //Audio Activity
audioButton = (ImageView) findViewById(R.id.IV_main_audio);
audioButton.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v){
Intent intentLoadNewActivity = new
Intent("com.danielkim.soundrecorder.MainActivity");
startActivity(intentLoadNewActivity);
}

});


Here is the android manifest on the app module



<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.kiminonawa.mydiary">

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

<uses-feature android:name="android.hardware.location.network" />
<uses-feature android:name="android.hardware.location.gps" />
<uses-feature
android:name="android.hardware.telephony"
android:required="false" />

<application
android:name=".shared.MyDiaryApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="false"
android:theme="@style/AppTheme"
tools:replace="android:icon">

<!-- Add this key for search the place name -->
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="AIzaSyDVL96wY3-Xqe8Rjt065Low6hMCOjW-Qd4" />



<activity
android:name=".init.InitActivity"
android:screenOrientation="portrait"
android:theme="@style/Theme_NoActionBar_FullScreen">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".main.MainActivity"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustPan" />
<activity
android:name=".contacts.ContactsActivity"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustPan" />
<activity
android:name=".entries.DiaryActivity"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustPan" />
<activity
android:name=".entries.photo.PhotoOverviewActivity"
android:screenOrientation="portrait"
android:theme="@style/Theme_NoActionBar_FullScreen" />
<activity
android:name=".entries.photo.PhotoDetailViewerActivity"
android:screenOrientation="portrait" />
<activity
android:name=".memo.MemoActivity"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustPan" />
<activity
android:name=".setting.SettingActivity"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustPan" />
<activity
android:name=".main.AboutActivity"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustPan" />
<activity
android:name=".security.PasswordActivity"
android:screenOrientation="portrait" />
<activity
android:name=".backup.BackupActivity"
android:screenOrientation="portrait" />

<!-- Ucrop -->
<activity
android:name="com.yalantis.ucrop.UCropActivity"
android:screenOrientation="portrait"
android:theme="@style/Theme.AppCompat.Light.NoActionBar" />

<!-- Start For NoNonsense-FilePicker -->
<activity
android:name=".backup.DirectoryPickerActivity"
android:theme="@style/FilePickerTheme">
<intent-filter>
<action android:name="android.intent.action.GET_CONTENT" />

<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>

<!-- This is for Android N -->
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="${applicationId}.provider"
android:exported="false"
android:grantUriPermissions="true"
tools:replace="android:authorities">
<meta-data
tools:replace="android:resource"
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/nnf_provider_paths" />
</provider>
<!-- End For NoNonsense-FilePicker -->


<activity android:name=".main.CollageFragment"></activity>

</application>











share|improve this question




















  • 1





    Instead of writing solved in the title and explaining what you did in the question body, make your own answer, and mark your answer as best answer.

    – DrZoo
    Jan 4 at 4:44


















0















Every time I call an activity on library module from app module the app crashes



There's a button on the app module and when it's pressed it will call an activity from the library module but every time I do that the app just crashes



Below is the code on the app module in which the intent will call a main activity on library module



 //Audio Activity
audioButton = (ImageView) findViewById(R.id.IV_main_audio);
audioButton.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v){
Intent intentLoadNewActivity = new
Intent("com.danielkim.soundrecorder.MainActivity");
startActivity(intentLoadNewActivity);
}

});


Here is the android manifest on the app module



<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.kiminonawa.mydiary">

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

<uses-feature android:name="android.hardware.location.network" />
<uses-feature android:name="android.hardware.location.gps" />
<uses-feature
android:name="android.hardware.telephony"
android:required="false" />

<application
android:name=".shared.MyDiaryApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="false"
android:theme="@style/AppTheme"
tools:replace="android:icon">

<!-- Add this key for search the place name -->
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="AIzaSyDVL96wY3-Xqe8Rjt065Low6hMCOjW-Qd4" />



<activity
android:name=".init.InitActivity"
android:screenOrientation="portrait"
android:theme="@style/Theme_NoActionBar_FullScreen">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".main.MainActivity"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustPan" />
<activity
android:name=".contacts.ContactsActivity"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustPan" />
<activity
android:name=".entries.DiaryActivity"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustPan" />
<activity
android:name=".entries.photo.PhotoOverviewActivity"
android:screenOrientation="portrait"
android:theme="@style/Theme_NoActionBar_FullScreen" />
<activity
android:name=".entries.photo.PhotoDetailViewerActivity"
android:screenOrientation="portrait" />
<activity
android:name=".memo.MemoActivity"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustPan" />
<activity
android:name=".setting.SettingActivity"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustPan" />
<activity
android:name=".main.AboutActivity"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustPan" />
<activity
android:name=".security.PasswordActivity"
android:screenOrientation="portrait" />
<activity
android:name=".backup.BackupActivity"
android:screenOrientation="portrait" />

<!-- Ucrop -->
<activity
android:name="com.yalantis.ucrop.UCropActivity"
android:screenOrientation="portrait"
android:theme="@style/Theme.AppCompat.Light.NoActionBar" />

<!-- Start For NoNonsense-FilePicker -->
<activity
android:name=".backup.DirectoryPickerActivity"
android:theme="@style/FilePickerTheme">
<intent-filter>
<action android:name="android.intent.action.GET_CONTENT" />

<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>

<!-- This is for Android N -->
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="${applicationId}.provider"
android:exported="false"
android:grantUriPermissions="true"
tools:replace="android:authorities">
<meta-data
tools:replace="android:resource"
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/nnf_provider_paths" />
</provider>
<!-- End For NoNonsense-FilePicker -->


<activity android:name=".main.CollageFragment"></activity>

</application>











share|improve this question




















  • 1





    Instead of writing solved in the title and explaining what you did in the question body, make your own answer, and mark your answer as best answer.

    – DrZoo
    Jan 4 at 4:44
















0












0








0








Every time I call an activity on library module from app module the app crashes



There's a button on the app module and when it's pressed it will call an activity from the library module but every time I do that the app just crashes



Below is the code on the app module in which the intent will call a main activity on library module



 //Audio Activity
audioButton = (ImageView) findViewById(R.id.IV_main_audio);
audioButton.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v){
Intent intentLoadNewActivity = new
Intent("com.danielkim.soundrecorder.MainActivity");
startActivity(intentLoadNewActivity);
}

});


Here is the android manifest on the app module



<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.kiminonawa.mydiary">

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

<uses-feature android:name="android.hardware.location.network" />
<uses-feature android:name="android.hardware.location.gps" />
<uses-feature
android:name="android.hardware.telephony"
android:required="false" />

<application
android:name=".shared.MyDiaryApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="false"
android:theme="@style/AppTheme"
tools:replace="android:icon">

<!-- Add this key for search the place name -->
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="AIzaSyDVL96wY3-Xqe8Rjt065Low6hMCOjW-Qd4" />



<activity
android:name=".init.InitActivity"
android:screenOrientation="portrait"
android:theme="@style/Theme_NoActionBar_FullScreen">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".main.MainActivity"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustPan" />
<activity
android:name=".contacts.ContactsActivity"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustPan" />
<activity
android:name=".entries.DiaryActivity"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustPan" />
<activity
android:name=".entries.photo.PhotoOverviewActivity"
android:screenOrientation="portrait"
android:theme="@style/Theme_NoActionBar_FullScreen" />
<activity
android:name=".entries.photo.PhotoDetailViewerActivity"
android:screenOrientation="portrait" />
<activity
android:name=".memo.MemoActivity"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustPan" />
<activity
android:name=".setting.SettingActivity"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustPan" />
<activity
android:name=".main.AboutActivity"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustPan" />
<activity
android:name=".security.PasswordActivity"
android:screenOrientation="portrait" />
<activity
android:name=".backup.BackupActivity"
android:screenOrientation="portrait" />

<!-- Ucrop -->
<activity
android:name="com.yalantis.ucrop.UCropActivity"
android:screenOrientation="portrait"
android:theme="@style/Theme.AppCompat.Light.NoActionBar" />

<!-- Start For NoNonsense-FilePicker -->
<activity
android:name=".backup.DirectoryPickerActivity"
android:theme="@style/FilePickerTheme">
<intent-filter>
<action android:name="android.intent.action.GET_CONTENT" />

<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>

<!-- This is for Android N -->
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="${applicationId}.provider"
android:exported="false"
android:grantUriPermissions="true"
tools:replace="android:authorities">
<meta-data
tools:replace="android:resource"
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/nnf_provider_paths" />
</provider>
<!-- End For NoNonsense-FilePicker -->


<activity android:name=".main.CollageFragment"></activity>

</application>











share|improve this question
















Every time I call an activity on library module from app module the app crashes



There's a button on the app module and when it's pressed it will call an activity from the library module but every time I do that the app just crashes



Below is the code on the app module in which the intent will call a main activity on library module



 //Audio Activity
audioButton = (ImageView) findViewById(R.id.IV_main_audio);
audioButton.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v){
Intent intentLoadNewActivity = new
Intent("com.danielkim.soundrecorder.MainActivity");
startActivity(intentLoadNewActivity);
}

});


Here is the android manifest on the app module



<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.kiminonawa.mydiary">

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

<uses-feature android:name="android.hardware.location.network" />
<uses-feature android:name="android.hardware.location.gps" />
<uses-feature
android:name="android.hardware.telephony"
android:required="false" />

<application
android:name=".shared.MyDiaryApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="false"
android:theme="@style/AppTheme"
tools:replace="android:icon">

<!-- Add this key for search the place name -->
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="AIzaSyDVL96wY3-Xqe8Rjt065Low6hMCOjW-Qd4" />



<activity
android:name=".init.InitActivity"
android:screenOrientation="portrait"
android:theme="@style/Theme_NoActionBar_FullScreen">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".main.MainActivity"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustPan" />
<activity
android:name=".contacts.ContactsActivity"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustPan" />
<activity
android:name=".entries.DiaryActivity"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustPan" />
<activity
android:name=".entries.photo.PhotoOverviewActivity"
android:screenOrientation="portrait"
android:theme="@style/Theme_NoActionBar_FullScreen" />
<activity
android:name=".entries.photo.PhotoDetailViewerActivity"
android:screenOrientation="portrait" />
<activity
android:name=".memo.MemoActivity"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustPan" />
<activity
android:name=".setting.SettingActivity"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustPan" />
<activity
android:name=".main.AboutActivity"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustPan" />
<activity
android:name=".security.PasswordActivity"
android:screenOrientation="portrait" />
<activity
android:name=".backup.BackupActivity"
android:screenOrientation="portrait" />

<!-- Ucrop -->
<activity
android:name="com.yalantis.ucrop.UCropActivity"
android:screenOrientation="portrait"
android:theme="@style/Theme.AppCompat.Light.NoActionBar" />

<!-- Start For NoNonsense-FilePicker -->
<activity
android:name=".backup.DirectoryPickerActivity"
android:theme="@style/FilePickerTheme">
<intent-filter>
<action android:name="android.intent.action.GET_CONTENT" />

<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>

<!-- This is for Android N -->
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="${applicationId}.provider"
android:exported="false"
android:grantUriPermissions="true"
tools:replace="android:authorities">
<meta-data
tools:replace="android:resource"
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/nnf_provider_paths" />
</provider>
<!-- End For NoNonsense-FilePicker -->


<activity android:name=".main.CollageFragment"></activity>

</application>








android android-studio






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 5 at 21:04









halfer

14.7k759116




14.7k759116










asked Jan 2 at 14:02









DatsiK77DatsiK77

13




13








  • 1





    Instead of writing solved in the title and explaining what you did in the question body, make your own answer, and mark your answer as best answer.

    – DrZoo
    Jan 4 at 4:44
















  • 1





    Instead of writing solved in the title and explaining what you did in the question body, make your own answer, and mark your answer as best answer.

    – DrZoo
    Jan 4 at 4:44










1




1





Instead of writing solved in the title and explaining what you did in the question body, make your own answer, and mark your answer as best answer.

– DrZoo
Jan 4 at 4:44







Instead of writing solved in the title and explaining what you did in the question body, make your own answer, and mark your answer as best answer.

– DrZoo
Jan 4 at 4:44














4 Answers
4






active

oldest

votes


















0














Intent i=new Intent(PresentActivity.this, NextActivity.class);
startActivity(i);





share|improve this answer
























  • how can I differentiate on which activity I'm trying to call. Because both app module and library module has MainActivity on them

    – DatsiK77
    Jan 2 at 14:15











  • I did this and it still crashes Intent i=new Intent(MainActivity.this, com.danielkim.soundrecorder.activities.MainActivity.class); startActivity(i);

    – DatsiK77
    Jan 2 at 14:18













  • show logcat crash report

    – Anisur Rahman Tonu
    Jan 2 at 16:25











  • which library are you using?

    – Anisur Rahman Tonu
    Jan 2 at 16:26











  • Here's the logcat crash report imgur.com/a/FECU0xL I converted the com.danielkim.soundrecorder from an app module into a library module and that's why I'm using as a library.

    – DatsiK77
    Jan 3 at 1:33





















0














audioButton = (ImageView) findViewById(R.id.IV_main_audio);
audioButton.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v){
try{
// try another constructor
Intent intentLoadNewActivity = new Intent(v.getContext(), "com.danielkim.soundrecorder.MainActivity");
// add optional flag FLAG_ACTIVITY_NEW_TASK if necessary.
// intentLoadNewActivity.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intentLoadNewActivity);
} catch (Exception e) {
Log.e("TAG",e);// if still not work, please show us the log.
}
}
});





share|improve this answer
























  • Where can I see the log?? sorry I'm new at using android studio

    – DatsiK77
    Jan 2 at 14:21











  • @DatsiK77 press alt + 6, or Logcat on the bottom tool bar. See developer.android.com/studio/debug/am-logcat

    – XieEDeHeiShou
    Jan 2 at 14:24













  • here is the screenshot of the log imgur.com/a/Ksp8dED

    – DatsiK77
    Jan 2 at 14:37











  • I cannot see what went wrong, please set the filter to only selected application on the right top of the logcat plane. And input the TAG you used when logging into the middle top input plane.

    – XieEDeHeiShou
    Jan 2 at 14:48



















0














My bad, reflection can be used to start your Activity from libary module :




Class.forName("com.mypackage.MainActivity")




try {
Intent myIntent = new
Intent(this,Class.forName("com.danielkim.soundrecorder.MainActivity"));
startActivity(myIntent);

} catch (ClassNotFoundException e) {
e.printStackTrace();
}





share|improve this answer


























  • i'll be adding this on the app module or library module??

    – DatsiK77
    Jan 2 at 14:13











  • updated answer. please check.

    – Sahil
    Jan 4 at 4:36



















0














(Posted solution on behalf of the question author).



I solved it already after some searching. I just had a duplicate filename on the app module and the library module.






share|improve this answer

























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54007702%2fhow-to-properly-call-mainactivity-from-library-module-on-app-module%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    4 Answers
    4






    active

    oldest

    votes








    4 Answers
    4






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    Intent i=new Intent(PresentActivity.this, NextActivity.class);
    startActivity(i);





    share|improve this answer
























    • how can I differentiate on which activity I'm trying to call. Because both app module and library module has MainActivity on them

      – DatsiK77
      Jan 2 at 14:15











    • I did this and it still crashes Intent i=new Intent(MainActivity.this, com.danielkim.soundrecorder.activities.MainActivity.class); startActivity(i);

      – DatsiK77
      Jan 2 at 14:18













    • show logcat crash report

      – Anisur Rahman Tonu
      Jan 2 at 16:25











    • which library are you using?

      – Anisur Rahman Tonu
      Jan 2 at 16:26











    • Here's the logcat crash report imgur.com/a/FECU0xL I converted the com.danielkim.soundrecorder from an app module into a library module and that's why I'm using as a library.

      – DatsiK77
      Jan 3 at 1:33


















    0














    Intent i=new Intent(PresentActivity.this, NextActivity.class);
    startActivity(i);





    share|improve this answer
























    • how can I differentiate on which activity I'm trying to call. Because both app module and library module has MainActivity on them

      – DatsiK77
      Jan 2 at 14:15











    • I did this and it still crashes Intent i=new Intent(MainActivity.this, com.danielkim.soundrecorder.activities.MainActivity.class); startActivity(i);

      – DatsiK77
      Jan 2 at 14:18













    • show logcat crash report

      – Anisur Rahman Tonu
      Jan 2 at 16:25











    • which library are you using?

      – Anisur Rahman Tonu
      Jan 2 at 16:26











    • Here's the logcat crash report imgur.com/a/FECU0xL I converted the com.danielkim.soundrecorder from an app module into a library module and that's why I'm using as a library.

      – DatsiK77
      Jan 3 at 1:33
















    0












    0








    0







    Intent i=new Intent(PresentActivity.this, NextActivity.class);
    startActivity(i);





    share|improve this answer













    Intent i=new Intent(PresentActivity.this, NextActivity.class);
    startActivity(i);






    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Jan 2 at 14:10









    Anisur Rahman TonuAnisur Rahman Tonu

    166216




    166216













    • how can I differentiate on which activity I'm trying to call. Because both app module and library module has MainActivity on them

      – DatsiK77
      Jan 2 at 14:15











    • I did this and it still crashes Intent i=new Intent(MainActivity.this, com.danielkim.soundrecorder.activities.MainActivity.class); startActivity(i);

      – DatsiK77
      Jan 2 at 14:18













    • show logcat crash report

      – Anisur Rahman Tonu
      Jan 2 at 16:25











    • which library are you using?

      – Anisur Rahman Tonu
      Jan 2 at 16:26











    • Here's the logcat crash report imgur.com/a/FECU0xL I converted the com.danielkim.soundrecorder from an app module into a library module and that's why I'm using as a library.

      – DatsiK77
      Jan 3 at 1:33





















    • how can I differentiate on which activity I'm trying to call. Because both app module and library module has MainActivity on them

      – DatsiK77
      Jan 2 at 14:15











    • I did this and it still crashes Intent i=new Intent(MainActivity.this, com.danielkim.soundrecorder.activities.MainActivity.class); startActivity(i);

      – DatsiK77
      Jan 2 at 14:18













    • show logcat crash report

      – Anisur Rahman Tonu
      Jan 2 at 16:25











    • which library are you using?

      – Anisur Rahman Tonu
      Jan 2 at 16:26











    • Here's the logcat crash report imgur.com/a/FECU0xL I converted the com.danielkim.soundrecorder from an app module into a library module and that's why I'm using as a library.

      – DatsiK77
      Jan 3 at 1:33



















    how can I differentiate on which activity I'm trying to call. Because both app module and library module has MainActivity on them

    – DatsiK77
    Jan 2 at 14:15





    how can I differentiate on which activity I'm trying to call. Because both app module and library module has MainActivity on them

    – DatsiK77
    Jan 2 at 14:15













    I did this and it still crashes Intent i=new Intent(MainActivity.this, com.danielkim.soundrecorder.activities.MainActivity.class); startActivity(i);

    – DatsiK77
    Jan 2 at 14:18







    I did this and it still crashes Intent i=new Intent(MainActivity.this, com.danielkim.soundrecorder.activities.MainActivity.class); startActivity(i);

    – DatsiK77
    Jan 2 at 14:18















    show logcat crash report

    – Anisur Rahman Tonu
    Jan 2 at 16:25





    show logcat crash report

    – Anisur Rahman Tonu
    Jan 2 at 16:25













    which library are you using?

    – Anisur Rahman Tonu
    Jan 2 at 16:26





    which library are you using?

    – Anisur Rahman Tonu
    Jan 2 at 16:26













    Here's the logcat crash report imgur.com/a/FECU0xL I converted the com.danielkim.soundrecorder from an app module into a library module and that's why I'm using as a library.

    – DatsiK77
    Jan 3 at 1:33







    Here's the logcat crash report imgur.com/a/FECU0xL I converted the com.danielkim.soundrecorder from an app module into a library module and that's why I'm using as a library.

    – DatsiK77
    Jan 3 at 1:33















    0














    audioButton = (ImageView) findViewById(R.id.IV_main_audio);
    audioButton.setOnClickListener(new View.OnClickListener(){
    @Override
    public void onClick(View v){
    try{
    // try another constructor
    Intent intentLoadNewActivity = new Intent(v.getContext(), "com.danielkim.soundrecorder.MainActivity");
    // add optional flag FLAG_ACTIVITY_NEW_TASK if necessary.
    // intentLoadNewActivity.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    startActivity(intentLoadNewActivity);
    } catch (Exception e) {
    Log.e("TAG",e);// if still not work, please show us the log.
    }
    }
    });





    share|improve this answer
























    • Where can I see the log?? sorry I'm new at using android studio

      – DatsiK77
      Jan 2 at 14:21











    • @DatsiK77 press alt + 6, or Logcat on the bottom tool bar. See developer.android.com/studio/debug/am-logcat

      – XieEDeHeiShou
      Jan 2 at 14:24













    • here is the screenshot of the log imgur.com/a/Ksp8dED

      – DatsiK77
      Jan 2 at 14:37











    • I cannot see what went wrong, please set the filter to only selected application on the right top of the logcat plane. And input the TAG you used when logging into the middle top input plane.

      – XieEDeHeiShou
      Jan 2 at 14:48
















    0














    audioButton = (ImageView) findViewById(R.id.IV_main_audio);
    audioButton.setOnClickListener(new View.OnClickListener(){
    @Override
    public void onClick(View v){
    try{
    // try another constructor
    Intent intentLoadNewActivity = new Intent(v.getContext(), "com.danielkim.soundrecorder.MainActivity");
    // add optional flag FLAG_ACTIVITY_NEW_TASK if necessary.
    // intentLoadNewActivity.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    startActivity(intentLoadNewActivity);
    } catch (Exception e) {
    Log.e("TAG",e);// if still not work, please show us the log.
    }
    }
    });





    share|improve this answer
























    • Where can I see the log?? sorry I'm new at using android studio

      – DatsiK77
      Jan 2 at 14:21











    • @DatsiK77 press alt + 6, or Logcat on the bottom tool bar. See developer.android.com/studio/debug/am-logcat

      – XieEDeHeiShou
      Jan 2 at 14:24













    • here is the screenshot of the log imgur.com/a/Ksp8dED

      – DatsiK77
      Jan 2 at 14:37











    • I cannot see what went wrong, please set the filter to only selected application on the right top of the logcat plane. And input the TAG you used when logging into the middle top input plane.

      – XieEDeHeiShou
      Jan 2 at 14:48














    0












    0








    0







    audioButton = (ImageView) findViewById(R.id.IV_main_audio);
    audioButton.setOnClickListener(new View.OnClickListener(){
    @Override
    public void onClick(View v){
    try{
    // try another constructor
    Intent intentLoadNewActivity = new Intent(v.getContext(), "com.danielkim.soundrecorder.MainActivity");
    // add optional flag FLAG_ACTIVITY_NEW_TASK if necessary.
    // intentLoadNewActivity.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    startActivity(intentLoadNewActivity);
    } catch (Exception e) {
    Log.e("TAG",e);// if still not work, please show us the log.
    }
    }
    });





    share|improve this answer













    audioButton = (ImageView) findViewById(R.id.IV_main_audio);
    audioButton.setOnClickListener(new View.OnClickListener(){
    @Override
    public void onClick(View v){
    try{
    // try another constructor
    Intent intentLoadNewActivity = new Intent(v.getContext(), "com.danielkim.soundrecorder.MainActivity");
    // add optional flag FLAG_ACTIVITY_NEW_TASK if necessary.
    // intentLoadNewActivity.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    startActivity(intentLoadNewActivity);
    } catch (Exception e) {
    Log.e("TAG",e);// if still not work, please show us the log.
    }
    }
    });






    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Jan 2 at 14:17









    XieEDeHeiShouXieEDeHeiShou

    1008




    1008













    • Where can I see the log?? sorry I'm new at using android studio

      – DatsiK77
      Jan 2 at 14:21











    • @DatsiK77 press alt + 6, or Logcat on the bottom tool bar. See developer.android.com/studio/debug/am-logcat

      – XieEDeHeiShou
      Jan 2 at 14:24













    • here is the screenshot of the log imgur.com/a/Ksp8dED

      – DatsiK77
      Jan 2 at 14:37











    • I cannot see what went wrong, please set the filter to only selected application on the right top of the logcat plane. And input the TAG you used when logging into the middle top input plane.

      – XieEDeHeiShou
      Jan 2 at 14:48



















    • Where can I see the log?? sorry I'm new at using android studio

      – DatsiK77
      Jan 2 at 14:21











    • @DatsiK77 press alt + 6, or Logcat on the bottom tool bar. See developer.android.com/studio/debug/am-logcat

      – XieEDeHeiShou
      Jan 2 at 14:24













    • here is the screenshot of the log imgur.com/a/Ksp8dED

      – DatsiK77
      Jan 2 at 14:37











    • I cannot see what went wrong, please set the filter to only selected application on the right top of the logcat plane. And input the TAG you used when logging into the middle top input plane.

      – XieEDeHeiShou
      Jan 2 at 14:48

















    Where can I see the log?? sorry I'm new at using android studio

    – DatsiK77
    Jan 2 at 14:21





    Where can I see the log?? sorry I'm new at using android studio

    – DatsiK77
    Jan 2 at 14:21













    @DatsiK77 press alt + 6, or Logcat on the bottom tool bar. See developer.android.com/studio/debug/am-logcat

    – XieEDeHeiShou
    Jan 2 at 14:24







    @DatsiK77 press alt + 6, or Logcat on the bottom tool bar. See developer.android.com/studio/debug/am-logcat

    – XieEDeHeiShou
    Jan 2 at 14:24















    here is the screenshot of the log imgur.com/a/Ksp8dED

    – DatsiK77
    Jan 2 at 14:37





    here is the screenshot of the log imgur.com/a/Ksp8dED

    – DatsiK77
    Jan 2 at 14:37













    I cannot see what went wrong, please set the filter to only selected application on the right top of the logcat plane. And input the TAG you used when logging into the middle top input plane.

    – XieEDeHeiShou
    Jan 2 at 14:48





    I cannot see what went wrong, please set the filter to only selected application on the right top of the logcat plane. And input the TAG you used when logging into the middle top input plane.

    – XieEDeHeiShou
    Jan 2 at 14:48











    0














    My bad, reflection can be used to start your Activity from libary module :




    Class.forName("com.mypackage.MainActivity")




    try {
    Intent myIntent = new
    Intent(this,Class.forName("com.danielkim.soundrecorder.MainActivity"));
    startActivity(myIntent);

    } catch (ClassNotFoundException e) {
    e.printStackTrace();
    }





    share|improve this answer


























    • i'll be adding this on the app module or library module??

      – DatsiK77
      Jan 2 at 14:13











    • updated answer. please check.

      – Sahil
      Jan 4 at 4:36
















    0














    My bad, reflection can be used to start your Activity from libary module :




    Class.forName("com.mypackage.MainActivity")




    try {
    Intent myIntent = new
    Intent(this,Class.forName("com.danielkim.soundrecorder.MainActivity"));
    startActivity(myIntent);

    } catch (ClassNotFoundException e) {
    e.printStackTrace();
    }





    share|improve this answer


























    • i'll be adding this on the app module or library module??

      – DatsiK77
      Jan 2 at 14:13











    • updated answer. please check.

      – Sahil
      Jan 4 at 4:36














    0












    0








    0







    My bad, reflection can be used to start your Activity from libary module :




    Class.forName("com.mypackage.MainActivity")




    try {
    Intent myIntent = new
    Intent(this,Class.forName("com.danielkim.soundrecorder.MainActivity"));
    startActivity(myIntent);

    } catch (ClassNotFoundException e) {
    e.printStackTrace();
    }





    share|improve this answer















    My bad, reflection can be used to start your Activity from libary module :




    Class.forName("com.mypackage.MainActivity")




    try {
    Intent myIntent = new
    Intent(this,Class.forName("com.danielkim.soundrecorder.MainActivity"));
    startActivity(myIntent);

    } catch (ClassNotFoundException e) {
    e.printStackTrace();
    }






    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Jan 4 at 4:34

























    answered Jan 2 at 14:09









    SahilSahil

    751510




    751510













    • i'll be adding this on the app module or library module??

      – DatsiK77
      Jan 2 at 14:13











    • updated answer. please check.

      – Sahil
      Jan 4 at 4:36



















    • i'll be adding this on the app module or library module??

      – DatsiK77
      Jan 2 at 14:13











    • updated answer. please check.

      – Sahil
      Jan 4 at 4:36

















    i'll be adding this on the app module or library module??

    – DatsiK77
    Jan 2 at 14:13





    i'll be adding this on the app module or library module??

    – DatsiK77
    Jan 2 at 14:13













    updated answer. please check.

    – Sahil
    Jan 4 at 4:36





    updated answer. please check.

    – Sahil
    Jan 4 at 4:36











    0














    (Posted solution on behalf of the question author).



    I solved it already after some searching. I just had a duplicate filename on the app module and the library module.






    share|improve this answer






























      0














      (Posted solution on behalf of the question author).



      I solved it already after some searching. I just had a duplicate filename on the app module and the library module.






      share|improve this answer




























        0












        0








        0







        (Posted solution on behalf of the question author).



        I solved it already after some searching. I just had a duplicate filename on the app module and the library module.






        share|improve this answer















        (Posted solution on behalf of the question author).



        I solved it already after some searching. I just had a duplicate filename on the app module and the library module.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        answered Jan 5 at 21:05


























        community wiki





        halfer































            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54007702%2fhow-to-properly-call-mainactivity-from-library-module-on-app-module%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Can a sorcerer learn a 5th-level spell early by creating spell slots using the Font of Magic feature?

            Does disintegrating a polymorphed enemy still kill it after the 2018 errata?

            A Topological Invariant for $pi_3(U(n))$