Как правильно вызвать mainacctivity из библиотечного модуля в модуле приложения - PullRequest
0 голосов
/ 02 января 2019

Каждый раз, когда я вызываю действие на модуле библиотеки из модуля приложения, происходит сбой приложения

В модуле приложения есть кнопка, и при ее нажатии она вызывает действие из модуля библиотеки, но каждый раз, когда я это делаюприложение просто падает

Ниже приведен код модуля приложения, в котором намерение будет вызывать основное действие для библиотечного модуля

 //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);
        }

    });

Вот манифест Android на модуле приложения

<?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>

Ответы [ 4 ]

0 голосов
/ 06 января 2019

(Размещено решение от имени автора вопроса) .

Я решил это уже после некоторого поиска. У меня только что было двойное имя файла в модуле приложения и модуле библиотеки.

0 голосов
/ 02 января 2019
Intent i=new Intent(PresentActivity.this, NextActivity.class);
startActivity(i);
0 голосов
/ 02 января 2019
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.
        }
    }
});
0 голосов
/ 02 января 2019

Мое плохое, отражение может быть использовано для запуска вашей Деятельности из модуля libary:

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

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

    } catch (ClassNotFoundException e) {
     e.printStackTrace();
  }
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...