10

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 :) :)

3 Answers 3

2

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 )

Sign up to request clarification or add additional context in comments.

2 Comments

i'm trying to make a call inside the library.. starting an activity with in library. not from outside library.
updated .please try with removing activities from library manifest and mention only on app manifest.
1

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.

Comments

0

Right click on App module, then Open Module Settings, choose App from the left, and on the last tab add the Module dependecy to your lib (you don't need to edit gradle file this way, even if what you have in your gradle seems correct). Then, declare the activity you want to open only in the android manifest of the library module.

<activity android:name=".myLibActivity"/> 

6 Comments

i have added dependency the same way as u explained. I have tried declaring activity in library module only, but no luck .
not getting any error, but the view is not getting drawn. only a blank screen is visible.. no views.
try put a log into onCreate method of your activity to see if the code is reached. Maybe the layout is not linked.
tried putting a toast message. but toast is not getting displayed.
Try to log since you don't need a context this way. BTW, is the xml linked to the library in the module's layout?
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.