I have an android library module and I'm trying to start an activity like
Intent intent = new Intent(mContext, DetailsScreen.class);
mContext.startActivity(intent);
I'm making above request inside the module and I have referenced the module in app gradle file like compile project(':myModule')
Also i have defined activity in Manifest file of both app module and in myModule like
<activity
android:name="com.test.mymodule.DetailsScreen" >
<intent-filter>
<action android:name="com.test.mymodule.DetailsScreen" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
But the activity which opens is an blank activity.
Can some one kindly explain me what's wrong I'm doing ?.
Thanks in advance :) :)
public void displayName() { String name = fetchName(); // Here's the call. System.
Go to "Edit Configurations..." in the "Run" menu. In the left pane, select your application. In the right pane, in the "General" tab, in the "Launch Options" section, there is a "Launch:" dropdown. Select "Specified Activity", and enter the name of your activity as it appears in your Manifest.
An Android library is structurally the same as an Android app module. It can include everything needed to build an app, including source code, resource files, and an Android manifest.
Start the Second Activity To start an activity, call startActivity() and pass it your Intent . The system receives this call and starts an instance of the Activity specified by the Intent .
you should mention only your library activity in app manifest. like how we include for facebook or other sdk activities. and start the activity with intent from your app. just try with removing activities from manifest. include only on app module.(package must be from library's )
This ans is copied from siddhesh
We can use reflection to get class object.
Class.forName("com.mypackage.myMainActivity")
Add this code in Library project to call,
try {
Intent myIntent = new Intent(this,Class.forName("com.mypackage.myMainActivity"));
startActivity(myIntent );
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
"com.mypackage.myMainActivity" is the Activity present in Main project, that we need to call from its Library project.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With