Will Oliveira
Will Oliveira

Reputation: 5

how to call an activity from a library android

I'm trying to call an activity that is in the main project from a library

Library code

Intent in = new Intent(this, com.process.agenda.activity.MainActivity.class);
startActivity(in);

Error:Circular reference between projects: :app -> :autenticadorCadastro -> :app

Main project

apply plugin: 'com.android.application'

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.1.1'
    compile 'com.android.support:design:23.1.1'

    compile project(':autenticadorCadastro')
}

Library

apply plugin: 'com.android.library'

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.1.1'
    compile 'com.android.support:design:23.1.1'

    compile project(path: ':app') // here throws the error
}

Thanks

Upvotes: 0

Views: 563

Answers (2)

Gabe Sechan
Gabe Sechan

Reputation: 93542

You have to use one of the other methods of creating an intent. Usually I do it by apk name and activity name (passed down from the calling app, or put into strings resources that are overridden by the app if its an internal only library).

Upvotes: 1

CaseyB
CaseyB

Reputation: 25060

You shouldn't be able to. If you needed to call into your main project from your library then the project is a dependency of the library which flips things the wrong way. If you're making a library it should only depend on itself and other libraries.

Upvotes: 1

Related Questions