Tobias Moe Thorstensen
Tobias Moe Thorstensen

Reputation: 8981

How to define activities in different packages

I have splitted my application into several packages. Some of my classes which extends Activity is located under com.tmt.app and another Activity is in the package Dialogs. Both packages is located under the src folder, I noticed that in my Manifest file I specify the package name like this:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.tmt.app"
android:versionCode="1"
android:versionName="1.0" >

which indicates that this manifest is relevant for the package com.tmt.app The relevant class is defined like this:

<activity
        android:name=".PasswordDialog"
        android:theme="@style/AboutTheme"
        android:screenOrientation="portrait" >
    </activity>

Which indicates that the class PasswordDialog is in the package com.tmt.app

How can I specify that this class is located under the package Dialogs ?

Thanks in advance!

Upvotes: 1

Views: 136

Answers (5)

Athul Harikumar
Athul Harikumar

Reputation: 2491

go to the manifest select application tab in application node select add activity then you will get the list of available activities select from them thats the best method and hazzle free

Upvotes: 0

Raghav Sood
Raghav Sood

Reputation: 82563

Say you have two packages, like com.one and com.two. Your manifest looks like:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.two"
android:versionCode="1"
android:versionName="1.0" >

.......

<activity
        android:name="com.one.a"
        android:theme="@style/AboutTheme"
        android:screenOrientation="portrait" >
    </activity>

<activity
        android:name=".b"
        android:theme="@style/AboutTheme"
        android:screenOrientation="portrait" >
    </activity>

You will need to use the fully qualified name to reference an Activity from outside the package.

OR

If the second package is a subpackage like com.one and com.one.two, you'll use:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.one"
android:versionCode="1"
android:versionName="1.0" >

.......

<activity
        android:name=".two.a"
        android:theme="@style/AboutTheme"
        android:screenOrientation="portrait" >
    </activity>

<activity
        android:name=".b"
        android:theme="@style/AboutTheme"
        android:screenOrientation="portrait" >
    </activity>

Upvotes: 1

hardartcore
hardartcore

Reputation: 17037

You have to write the whole path of the package. Example :

<activity
        android:name="com.tmt.Dialogs.PAsswordDialog"
        android:theme="@style/AboutTheme"
        android:screenOrientation="portrait" >
    </activity>

Upvotes: 1

user468311
user468311

Reputation:

<activity
        android:name=".Dialogs.PasswordDialog"
        android:theme="@style/AboutTheme"
        android:screenOrientation="portrait" >
</activity>

Upvotes: 1

Chirag
Chirag

Reputation: 56935

When you declare your activity android:name=".PasswordDialog" like this then it consider as the current package activity where package is declare in root of manifest .

When you have to declare your activity in another package then you have to declared your activity in menifest as below.

<activity
        android:name="YourAnotherPackageName.PasswordDialog"
        android:theme="@style/AboutTheme"
        android:screenOrientation="portrait" >
    </activity>

Upvotes: 1

Related Questions