Launch an Activity from a JAR/Lib

I found out the answer in following way,

I dont know but Jar files are not working this way, so what i did was i made the normal android project (MyApplication) which i wanted to export as a lib. Once i comepleted making changes to my Activity say My Activity. GO to build.gradle of application make following changes :

1) change code **"apply plugin: 'com.android.application'" to "apply plugin: 'com.android.library'"**

2) remove attribute "applicationId "com.myapplication"" from defaultConfig.

Now go to menu bar and click on Build->clean and than build-> rebuild. It will create a ".aar" file in "app\build\outputs\aar".

This is your lib. Import it in you application say NotMyApplication in libs folder and perform following steps : 1) Add following code to build.gradle of app : repositories{ flatDir { dirs 'libs' }

2) Also add following to build.gradle of app : 
    **dependencies {
    ...
    compile (name: 'name_of_aar_file_without_ext', ext:'aar' )
    }**

3) Declare the Activity you want to launch in your apps manifest file : 

    **<activity android:name="com.testmylib.MyActivity" >
    </activity>**

4) Launch your activity as :
        **Intent in = new Intent(NotMyActivity.this,com.testmylib.MyActivity.class)
        startActivity(in);**

It will launch your activity from lib. One point to note is if Resources of same name are there, than Activity will pick from NotMyApplication. So keep in mind ke give unique name to resources of such activities which you want to export in libs.

I still dont know though why from Jar it is not working. Any help on that will be appreciated...:)

For more detials visit the link : http://revisitingandroid.blogspot.in/2017/01/how-to-launch-activity-from-aar-files.html