android activity in jar library - android

I have copied an activity class from the internet : get user input
When I had the activity class inside the project, as a class file - it worked fine.
When I inserted the class +layout file into a different project (my dialogs.jar file) I could not start the activity.
The activity (TextEntryActivity) is under "com.xyz.dialogs"
My project is under "com.xyz.thisproject"
First I got the "activity class not found" error:
"AndroidRuntime(487): android.content.ActivityNotFoundException: Unable to find explicit activity class ..."
Then I read in an article that I should insert the startActivityForResult into a try/catch and I did.
The result is :
Activity is not shown
onActivityResult is fired without any action from the user
Notes:
I put the activity in both manifests (first only in jar,then in my project, then both)
I have another class (not activity!) in that JAR file and its working fine (a OK only dialog I build with dialog builder)
My questions are:
Is it at all possible to put an activity in an external library ?
Is it ok that that the layout file is in the jar (its only a textbox with two commands ok/cancel)
Where should I declare the activity (which manifest or both?)
How should I declare the activity (I saw samples with "ActivityName" and some other samples with ".ActivityName" where should I use what method...)
Thanks in advance
Guy

I have at least a workaround:
Make an Eclipse library project with your activity (there is an is-library property in the Android properties of an Android project) and make your second project use the library project. Here is more information on that topic: http://developer.android.com/guide/developing/projects/projects-eclipse.html
Then subclass your activity and declare the subclass in the manifest. This works around the package issue.

Related

Create new android project with out Fragment activity in eclipse

After the ADT update in eclipse whenever I create a new project for android a default fragment activity is created. How to get to create simple activity always?
I don't want to downgrade the ADT.
Is this possible? any work around?
The latest ADT plugins are made in such a way that if you create any simple project you will always get the FragmentActivity not a simple Activity. And you can not change it.
In new ADT itself there is Blank Activity that is defined with an actionbar and optional navigational elements such as tabs or horizontal swipe.
If you want to create simple activity in your project then you can simply create class and extends Activity into it, this is the only way now. Or you can change the Fragment with Activity simply by changing code only.
As an Activity is simply a Java class, just accept the defaults the ADT gives you during the initial creation of your project. Create your project, then manually:
1. Delete all the class and layout files in your project.
2. Create your Java class files extending Activity (in your desired packages).
3. Create XML layout files (in the res/layout folder).
4. 'Wire-up' your Java class files and XML layout files using setContentView(R.layout.YOUR_LAYOUT_ID) in the onCreate() methods.
5. Done!
EDIT
Remember to Register your Activities in the Manifest manually as well.

How can I Integrate my Widget Application into my another Application

Hi guy's Please See the question asked on this link[ Integration of my widget with my application ][1]
[1]:
My problem is exactly same as the question asked on this link.
Very first I have tried this Ans=>
1]
i) Turn the Widget project into a Library project : properties -> Android -> and tick Is Library
ii) Go to the original project and import the Widget project : properties -> Android -> Add
iii)In the original project's Manifest, add the text between the (...) , including and , into the (...)
But this didn't work for me.. Then I tried second ans i.e.---
2] Copy all code from one package to 2nd one and merge AndroidManifest.xml ...
But in this case My both application i.e. widget App and Another app has MainActivity.. So there is ambiguity between them.. ! Please help..!
Finally I've solved my problem, what I did is--
I have copied all Activities, Classes and Services form my widget app to my another app.
After that I have merged the both Manifest files (One from widget app. and one from my another app) into my another app, so that it is a single Manifest file. And the main problem was my widget app and another app both had the activity with same name i.e. MainActivity, so to resolve this problem I've just renamed MainActivity from my widget app to StartActivity, and problem got solved, now application is running fine.!

ActivtyNotFoundException but YES, it is declared in my AndroidManifest.xml

in my application I call
startActivityForResult( new Intent(this, ShowPreferencesActivity.class), <some code>);
the activity is declared as :
package ca.qc.webalterpraxis.cinedroid.activity.preference;
public class ShowPreferencesActivity extends PreferenceActivity { ...}
and in my manifest I got :
<activty android:name=".activity.preference.ShowPreferencesActivity" android:label="#string/set_preferences">
But I receive an exception when I try to start the activity (in the first line of code of this question) :
E/AndroidRuntime(1830): android.content.ActivityNotFoundException: Unable to find explicit activity class {ca.qc.webalterpraxis.cinedroid/ca.qc.webalterpraxis.cinedroid.activity.preference.ShowPreferencesActivity}; have you declared this activity in your AndroidManifest.xml?
I tried everything I could :
replacing, in the manifest, the name of the class with the fully qualified name of the class
setting the intent class name using setClassName
providing a default filter for the activity
I relaunched eclipse around 10 times, rebooted my computer, erased the application from the device, resintalled, etc...
I don't have any idea of what's happening. And the worse is that it was working before, but not anymore after I renamed the class. Something strange : even if I rename the class now, the AndroidManifest won't update in eclipse, I have to update it by hand..but it still works for other classes...
Also, please note that I have a test application, apart of the under test app, and the test app can't find the activity to instrument it, neither.
Oh, and last but not least, I am 100 % sure that the ShowPreferencesActivity is in the resulting dex file, I dexdumped it to check.
Thanks in advance for your time.
(I use the maven-android-plugin)
Thanks all, I found my problem : the tag in the manifest was
<activty
and not
<activity
But why does eclipse allow that ???!!!

Open an activity without declaring it in the manifest file in ANDROID?

I want to open an activity without declaring it in an manifest file.
I don't know if it is possible or not.
What I actually want is to dynamically open an activity from my program using intents.
Can anyone help me if it is possible.
Not possible. Although I am unsure what you mean "dynamically open an activity".
See: http://developer.android.com/reference/android/app/Activity.html
Under Class Overview it states "To be of use with Context.startActivity(), all activity classes must have a corresponding declaration in their package's AndroidManifest.xml"
You can have an Activity in your package and not define it in the manifest, however you would not be able to start it successfully.
Your 'Dynamic' activity start is actually the normal way of starting an activity (as you have said in a comment to the answer of Matt M). Though you HAVE to add the Activities in manifest as Matt M said. In list view, clicking an activity will call a function that will start respective activity with startActivity() function.
I tried this very long, but since the Instrumentation class uses the IActivityTaskManager, which is a class of the internal API located at com.android.server.wm, that is not in the Activity classloader, I solved this by another method:
Using a subclass
I just made an Gist, with sample code.
GIST

Android: Extending a custom abstract Activity

I created an abstract Activity which extends the android.app.Activity. Then I created an activity extending my abstract one. [1]
Everything is fine with ant, but eclipse showed an error in the manifest saying that my activiy did not exists, so I regenerate the class files and the error in the manifest is gone. But now eclipse shows an error at the root of my project and don't want to compile.
I precise that the activity is working fine in a device builded with ant. I tried to "Fix Project Properties" as well. I can't declare the abstract activity because of it's abstract.
Anybody already saw this bug ?
Thanks
[1] Here is a little schematic
android.app.Activity -> abstract ActivityNet -> MyActivity
This is a common bug/behaviour of Eclipse.
To eliminate it click on the "Problems" icon (right bottom corner but it depends on your prospective)
Right click on the error line and then delete it.
The error should be gone away now

Categories

Resources