Kishore
Kishore

Reputation: 51

Invoking an activity from Android Library(.jar)?

I have created an Android Library Project which contains several Activities. I want to reuse these activities in other projects. How can I do this? I have added the project vi:

project->Android->Add(Android Library Project.)

Then added the required details to Android Manifest file.

Android Manifest file:

<?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="org.testlib.com"
        android:versionCode="1"
        android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="9" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    <uses-libraryandroid:name="org.mainlib.com" android:required="true"/>
    <application android:icon="@drawable/ic_launcher" 
        android:label="@string/app_name" >
        <activity android:name=".TestLibActivity"
            android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />    
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name="org.mainlib.com.MainActivity"/>                 
    </application>    
</manifest>

Code to start activity:

Intent myintent=new Intent(v.getContext(),MainActivity.class);
startActivityForResult(myintent, 0);

How can I invoke an activity from my jar file?

Upvotes: 1

Views: 1478

Answers (2)

Warpzit
Warpzit

Reputation: 28152

If you've created an android library and added it correctly (seems like it). Then the only thing you do is the same thing you'd do with a regular activity. The only difference being you import a path from your library project instead of your own project.

On a side note you don't need to add the library in your manifest. You only need add the library project through the project properties.

Upvotes: 2

Jeje Doudou
Jeje Doudou

Reputation: 1706

I don't understand your question. Do you mean

How to start 'TestLibActivity' from outside the Library

?

If that's the case, you can call it by calling Intent myintent=new Intent(v.getContext(),org.testlib.com.TestLibActivity.class); startActivityForResult(myintent, 0);

Of course you have to add the right import in your activity and add the library to your project.

Upvotes: 2

Related Questions