Creating java packages for Android projects - android

I created multiple packages to better structure our Android-based project. After creating these packages, the application no longer runs. It's a widget application. I noticed that the application manifest needed to be modified and did so. This didn't seem to fix the problem. I don't get any error messages, I'm simply not able to open the main activity page from the application widget. Could anyone tell me how to resolve this issue?
For more detail, I initially had a flat project structure (com.domain.A). Now I have the following:
com.domain.Activities
Activity1.java
Activity2.java
com.domain.Features
Feature1.java
Feature2.java
com.domain.Services
Service_1.java
Service_2.java
etc...
Here's an excerpt from the manifest file:
<activity android:name="com.domain.Activities.Activity1"
android:theme="#style/Theme.D1"
android:label="#string/act1"
/>
<activity android:name="com.domain.Activities.Activity2"
android:theme="#style/Theme.D1"
android:label="#string/act2"
/>
<activity android:name="com.domain.Features.Feature1"
android:theme="#style/Theme.D1"
android:label="#string/fea1"
/>
<activity android:name="com.domain.Features.Feature2"
android:theme="#style/Theme.D1"
android:label="#string/fea2"
/>
<service android:name="com.cmu.Services.Service_1"/>
<service android:name="com.cmu.Services.Service_2"/>
Thanks.

After moving the classes in packages, how have you defined the activities in the manifest.
(as a thumb rule ctrl+click on activity declaration in manifest should take you to class file, else link is broken), its generally better to keep all classes extending Activity in main android package of your app
EDIT:
if your MyActivity lies under package a.b;
then .a.b.MyActivity is to be used for android:name in manifest the dot(.) initially specifies to use package-prefix from manifest package name..

You specify a package in your manifest, then you can just use the . prefix to reference the package for the Activities you define in you manifest. So for example:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.domain"
android:versionCode="1"
android:versionName="1.0" >
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:label="#string/app_name"
android:name=".activities.MainActivity" >
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".activities.Activity1" />
<activity android:name=".activities.Activity2" />
You main launcher activity is thus: com.domain.activities.MainActivity and the other two are: com.domain.activities.Activity1 and com.domain.activities.Activity2

Related

implementing Ubers usebutton sdk and AndroidManifest.xml

I am trying to use the Uber usebutton but each time, it crashes giving the following error:
Unable to find explicit activity class {com.heyjude.heyjudeapp/com.usebutton.sdk.internal.GroupedInventoryCardActivity}; have you declared this activity in your AndroidManifest.xml?
I am unsure what to put in the AndroidManifest, currently as per the docs I have:
<meta-data
android:name="com.usebutton.applicationid"
android:value="app-myId" />
But it's clearly not working...
I have some more information, I checked the manifest-merger-debug-report.txt and found the following line
REJECTED from [com.usebutton:android-sdk:5.0.1] /Users/adamkatz/Projects/LavaLamp/Hey Jude/heyjudestudio/app/build/intermediates/exploded-aar/com.usebutton/android-sdk/5.0.1/AndroidManifest.xml:13:5-43:19
Why would the library manifest be rejected and how to make it accepted?
The maifest stuff maybe a red herring, your probably missing a library (The Uber library).
Here's a typical (working) AndroidMainfest.xml.
VERY important:
package="com.example.html2pdf"
replace with your package name (it's normally in your (local package) GroupedInventoryCardActivity.java file).
VERY important: Html2pdfActivity"
replace with one entry for activity for all your Activity files .GroupedInventoryCardActivity in your case (full path best package plus activity with dots (full stop's separating things, normally no slashes).
VERY VERY important:
com.heyjude.heyjudeapp/com.usebutton.sdk.internal.GroupedInventoryCardActivity is reffering to a library Activity (also with a package name the forward slash links the two packages). That's o.k.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.html2pdf"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="16"
android:targetSdkVersion="19" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.html2pdf.Html2pdfActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
So package (replace/change):
package="com.heyjude.heyjudeapp"
and (replace/change/insert) Activity (name):
<activity
android:name="com.heyjude.heyjudeapp/com.usebutton.sdk.internal.GroupedInventoryCardActivity"
Hope this helps and not make it more confusing ;O)
All that goes into the AndroidManifest.xml file is this:
<application
<activity
<!-- your activities -->
</activity>
<!--Button SDK-->
<meta-data android:name="com.usebutton.applicationid" android:value="YOUR_BUTTON_APP_ID"/>
</application>
Did you remember to replace "YOUR_BUTTON_APP_ID" with your Button app ID found in the dashboard?

The acitivity is not declared in Android Manifest

i had a problem, the Android Studio give me a warning which say:
"The acitivity is not declared in Android Manifest" this appear when i look on the Edit Configuration.
I see in another topic wich says that i have to put in androidManifest.xml
But i already did, and the Android Studio doesnt take it.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.drdower.myapplication" >
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".AplicacionSencillaInicio"
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=".AplicacionSencillaResultado"
android:label="#string/app_name"/>
</application>
</manifest>
Which problem could be?
Thank u!
copy the code
delete the activity class
recreate one with same name
paste the code
Place your whole package path
com.example.drdower.myapplication.AplicacionSencillaInicio
Then clean your Project.
Also make sure you passed the correct java file name.

In Android XML, what is the significance of a period (".") preceding a class or package reference?

While browsing the Android developer docs I spotted example code where references to classes/packages are preceded by periods.
In the snippet below from http://developer.android.com/guide/topics/search/search-dialog.html there is ".SearchableActivity"
<application ... >
<activity android:name=".SearchableActivity" >
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
<meta-data android:name="android.app.searchable"
android:resource="#xml/searchable"/>
</activity>
...
</application>
Another example - http://developer.android.com//training/sharing/receive.html - has ".ui.MyActivity"
<activity android:name=".ui.MyActivity" >
What do these preceding "." imply, and when/why should/would you use one? What happens if they are ommited?
android:name
Quoting docs
The name of the class that implements the activity, a subclass of
Activity. The attribute value should be a fully qualified class name
(such as, "com.example.project.ExtracurricularActivity"). However, as
a shorthand, if the first character of the name is a period (for
example, ".ExtracurricularActivity"), it is appended to the package
name specified in the element. Once you publish your
application, you should not change this name (unless you've set
android:exported="false").
If in manifest you have
package="com.example.layout"
And your Activity is under the same package you can have
<activity
android:name=".ActivityName"
Instead of ShortHand You can also have
<activity
android:name="com.example.layout.ActivityName"
If the activity is not declared right in manifest you end up in ActivityNotFoundException
If your activity is in a different package then you mention the fully qualified class name
<activity
android:name="packagename.ActivityName"
Note: There is no default. The name must be specified.
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="8" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity android:name=".DownloadActivity" >
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
See the above example manifest file
Here "." means a package name
means following line
<activity android:name=".DownloadActivity" >
you can write 2 ways
<activity android:name="com.example.DownloadActivity" > and
<activity android:name=".DownloadActivity" >
in your manifest file you already declare the base package name on top
package="com.example"
so android gives us a way to make it short
so if you use "." for class names it will take the package name that you have defined on top of the manifest file and system take it as com.example.DownloadActivity

ActivityNotFoundException but i've declared in manifest

my error is
E/AndroidRuntime(11101): android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.hellolinear/java.text.Normalizer$Form};
have you declared this activity in your `AndroidManifest.xml`?
but in my manifest code is:
<activity android:name=".Form"
android:label="#string/app_name">
<intent-filter/>
</activity>
can anyone help me?
If non of above works, then
uninstall app from your device
restart eclipse( if you are using it, otherwise other IDE)
clean your project
Check whether the activity is in the root package. Otherwise mention the package path while declaring in manifest file.
<activity
android:name="com.example.smstracking.MainActivity"
>
</activity>
Perhaps you the package name is incorrect? Try specifying the full package name like this:
<activity android:name="com.example.hellolinear.Form"
android:label="#string/app_name">
<intent-filter/>
</activity>
The correct way to this, however, would be to add the package name like this tou your manifest:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.hellolinear"
android:versionCode="1"
android:versionName="1.0.0" >
at least one activity must contain with intent filter that contain action as action.MAIN and category as Launcher as per my knowledge.Hope this helps as you haven't provided the intent filter in your manifest.
<activity android:name="your package name.Your Activity Name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Your Package name is not written correctly. Your Code:
<activity
android:name=".Form"
android:label="#string/app_name">
<intent-filter/>
</activity>
Instead of above, write this:
<activity
android:name="your package name.Form" // eg: android:name="com.example.myapp.Form"
android:label="#string/app_name">
<intent-filter/>
</activity>

Android Package structure

My default package name is com.xont.controller (R file contain that package.Eclipse generated one) . I want to make it more packages.Like 'com.xont.controller.salesand 'com.xont.controller.admin like this: And I added activity also in manifestfile
Edited
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.android.xont.controller"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="8" />
<application android:label="Xont" android:icon="#drawable/virtusel64">
<activity android:name=".AndroidAppXontActivity"
android:label="Xont">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".LoginActivity"
android:label="Login">
</activity>
<activity android:name=".syn.DatabaseCheckActivity"
android:label="Databse Setup">
</activity>
...........
Package structure is:
Error says : android.content.ActivityNotFoundException: Unable to find explicit activity class {com.xont.controller/com.xont.controller.syn.DatabaseSetupActivity}; have you declared this activity in your AndroidManifest.xml?
Please help me what i want to do here.
All components that are registered as .SomeName use manifest's package value as prefix. So basicaly you regsitered activity .AndroidAppXontActivity as com.android.xont.controller.AndroidAppXontActivity. But there is no such java class.
You should fix your component names to have full name to your Java class, like this:
<activity android:name="com.xont.controller.AndroidAppXontActivity" ... />
Same for all other components.
Please try this,
<activity android:name="com.xont.controller.syn.DatabaseSetupActivity"
android:label="Databse Setup">
</activity>

Categories

Resources