Gaurav Arora
Gaurav Arora

Reputation: 8362

Calling the other Library Project from the Android Project

I want to open a library project from my android project. For that purpose I have made a demo using Project A and Project B ( library project)

I have added project B as library in Project A.

Here is how I am calling it :

public class ProjectA extends Activity {

    Button btn;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_project);

        btn = (Button)findViewById(R.id.btn_project2);
        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View arg0) {
                Intent LaunchIntent = new Intent(arg0.getContext(),ProjectB.class).setAction(Intent.CATEGORY_LAUNCHER);
                startActivity(LaunchIntent);
            }
        });
    }

Manifest of Project A

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

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="17" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.example.projecta.ProjectA"
            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="com.example.projectb.ProjectB" />
    </application>
</manifest>

Here I am getting a problem - Activity is getting called but UI still remains the same as that of the Activity A.

public class ProjectB extends Activity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_project_b);
        Toast.makeText(this, "Project B", 0).show();
    }
}

Manifest of Project B

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


    <application android:allowBackup="true" >
        <activity android:name="com.example.projectb.ProjectB" />
    </application>

</manifest>

Please tell me why my UI is not updating up

Upvotes: 1

Views: 667

Answers (1)

d.k.
d.k.

Reputation: 415

You can not call direct library project from your code.

You have two options:

  1. add library project in your project(android->library->add library project)
  2. create jar for that library project and add build path in your project after you can call.

Upvotes: 1

Related Questions