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 ???!!!
Related
startActivity(new Intent("com.google.android.accessibility.talkback.tutorial.AccessibilityTutorialActivity"));
getting crash
Exception: No Activity found to handle Intent { act=com.google.android.accessibility.talkback.tutorial.AccessibilityTutorialActivity }
android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:2064)
android.app.Instrumentation.execStartActivity(Instrumentation.java:1718)
android.app.Activity.startActivityForResult(Activity.java:5211)
androidx.activity.ComponentActivity.startActivityForResult(ComponentActivity.java:574)
android.app.Activity.startActivityForResult(Activity.java:5169)
androidx.activity.ComponentActivity.startActivityForResult(ComponentActivity.java:560)
android.app.Activity.startActivity(Activity.java:5540)
androidx.core.content.ContextCompat.startActivity(ContextCompat.java:251)
androidx.fragment.app.FragmentHostCallback.onStartActivityFromFragment(FragmentHostCallback.java:166)
androidx.fragment.app.Fragment.startActivity(Fragment.java:1377)
androidx.fragment.app.Fragment.startActivity(Fragment.java:1365)
i need to launch the talkback tutorial activity
The exception you're seeing suggests that the system cannot find the activity you're trying to launch. There are a few reasons why this might be happening.
First, make sure that the package name and activity name you're using is correct. It's possible that the name of the activity has changed in a recent update or you've made a typo.
Next, check that the activity is declared in the AndroidManifest.xml file for the application. Every activity that can be launched from outside the application needs to be declared in the manifest.
Finally, it's possible that the activity requires specific permission that your app does not have. Check the documentation for the activity to see if any permissions are required.
TLDR:
I have to extend the application class but don't know where to start.
Ok... I know this is a dumb one but I have to ask it.
I need to install LeakCanary and I see in their documentation that it requires me to put code in the Application Class.
I understand how to make a java class that extends the application class, but I have some questions before I do this.
SITUATION:
I have 9 classes in my app already.
The entry point to my app is MainActivity.class (figures, right?)
I have not had to extend the Application Class yet.
App name is "CST-ALERT"
QUESTIONS:
Do I just create a new Java class in my java source folder and name it the same as my overall
package name? What do I name this new class?
Do I need to adjust the manifest now to have this as the entry point
instead of MainActivity? Which I imagine will change things quite a
bit for me.
Do I have to change anything else in the manifest? I assume I will
at least have to declare it in there.
Hopefully my situation and questions will give you an idea of what I am asking.
Do I just create a new Java class in my java source folder
Yes.
and name it the same as my overall package name?
If by "it", you mean the Java package, you already have a directory for your existing Java code. Put your subclass of Application in there, unless you have a clear reason not to.
In this trivial sample app, I put my Application subclass in the same directory as my launcher Activity, which is the directory for my Java package (com.commonsware.android.button).
What do I name this new class?
That is up to you. I called it CanaryApplication. If you think you leak a lot, call it CoalMine. So long as it is a legal Java class name, it doesn't matter.
Do I need to adjust the manifest now to have this as the entry point instead of MainActivity?
Um, well, I wouldn't describe MainActivity as the entry point. Regardless, MainActivity is left alone. You need to add an android:name attribute to the <application> element, identifying your Application subclass.
Do I have to change anything else in the manifest?
No, that should suffice.
I have sub-folders(packages) defined in an application, which has to be defined in Manifest file accordingly.
But after defining as per the conventions and as suggested by patrons in their posts, the application crashes. The error again in the logcat is
"03-17 19:38:54.118: E/AndroidRuntime(558): android.content.ActivityNotFoundException: Unable to find explicit activity class {in.co.avksons/prox_analysis.prox_main_scr}; have you declared this activity in your AndroidManifest.xml?"
I tried to look in each file on the specifics of the package, but could not find the error.
What are the possible causes for not acknowledging the package definition in the manifest file.
Thanks
Can you post your Manifest file? I have a feeling you are referencing your Activity incorrectly.
If for example you have an activity called TestActivity, and it was under the folder Activities, and your package name was com.test.app then you would reference your activity as follows:
com.test.app.Activities.TestActivity
You cant use '/' in the manifest file, use '.' instead.
Most likely, you have wrong declaration of activiy in Manifest. If you have package "com.application.view", for example, declaration will be like this:
android:name=".view.Activity"
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.
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