I get an error when launching an activity from a fragment, using an intent.
Intent intent = new Intent(this.getActivity(),FormActivity.class);
intent.putExtra("Horas",hours);
intent.putExtra("Minutos",minutes);
intent.putExtra("Segundos",seconds);
intent.putExtra("Fecha",date);
intent.putExtra("Hora",time);
startActivity(intent);
LogCat:
android.content.ActivityNotFoundException: Unable to find explicit activity class
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1719)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1491)
at android.app.Activity.startActivityForResult(Activity.java:3436)
at android.app.Activity.startActivityForResult(Activity.java:3393)
at android.support.v4.app.FragmentActivity.startActivityFromFragment(FragmentActivity.java:848)
at android.support.v4.app.Fragment.startActivity(Fragment.java:878)
at es.timetrack.app.InActivityPageFragment.onClick(InActivityPageFragment.java:148)
Declare the Activity you are starting in the Manifest .xml file:
<activity
android:name="your.package.FormActivity"
android:label="FormActivity" />
Some additional information:
The App Manifest
There you can see the structure of the manifest.xml file and what it is used for.
In addition to you not declaring your Activity in the manifest file, your application might crash due to unhandled exceptions in the onCreate(...) method of your FormActivity.
Related
Running tests with createComposeRule and hitting a stack trace like (irrelevant parts omitted):
java.lang.RuntimeException: Could not launch activity
at androidx.test.runner.MonitoringInstrumentation.startActivitySync(MonitoringInstrumentation.java:495)
...
Caused by: java.lang.RuntimeException: Unable to resolve activity for: Intent { act=android.intent.action.MAIN flg=0x14000000 cmp=my.app.package.name.here/android.app.Activity }
...
The OP question is about the use of createComposeRule() which doesn't require a custom activity (it uses ComposeActivity under the hood).
In this case you need to include this below in your gradle file:
debugImplementation("androidx.compose.ui:ui-test-manifest:1.0.0-beta05")
If you take a look at the contents of that package, it's simply an AndroidManifest.xml with an <activity/> entry for androidx.activity.ComponentActivity.
You need declare an Activity with name android.app.Activity in your AndroidManifest.xml for the Compose UI tests to use to host the content. Add the following within your <application> tag:
<activity android:name="android.app.Activity" android:theme="#style/your_app_theme_here"/>
substituting your_app_theme_here with a theme that exists in your app.
You need to add
<activity android:name="androidx.activity.ComponentActivity" />
to your manifest.
I have an activity which I declare in my manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.my">
<uses-sdk android:minSdkVersion="14"/>
<application>
<activity
android:name="com.my.InternalDummyActivity"
android:exported="false">
</activity>
</application>
</manifest>
I have tried without the exported=false as well
The application contains an inner library with another activity.
I try to call an explicit intent from the other activity (other namespace)
But I always get an exception:
Intent intent1 = new Intent(activity.getApplicationContext(), InternalDummyActivity.class);
activity.startActivity(intent1);
ComponentName componentName2 =
new ComponentName(
"com.my","com.my.InternalDummyActivity");
Intent intent2 = new Intent().setComponent(componentName2); //dones work
activity.startActivity(intent2);
Process: com.comp.outter, PID: 9267
android.content.ActivityNotFoundException: Unable to find explicit activity class {com.my/com.my.InternalDummyActivity}; have you declared this activity in your AndroidManifest.xml?
How can I fix this?
Try using one of the ComponentName's contructors that uses a Context, such as
ComponentName cn = new ComponentName(context,
"com.my.InternalDummyActivity");
For some reason, you can use the contructor taking two Strings only if you know the class dynamically.
Also, update your manifest as follow:
<activity
android:name=".InternalDummyActivity">
</activity>
and application package name should be in lower case only, as mentioned in Java's Naming Conventions in Oracle Docs
Package names are written in all lower case to avoid conflict with the
names of classes or interfaces
This question is possible duplicate of the thread gives below
How to call activity from a library module in android studio
Check if this is what you are looking for.
The app crashes in Android Studio when a button is clicked to reach the another activity through intent
public void next(View view) {
Toast.makeText(getApplicationContext()," Next called " , Toast.LENGTH_SHORT).show();
startActivity(new Intent(getApplicationContext(),SecondActivity.class));
}
The error I am getting from logcat is
Caused by: android.content.ActivityNotFoundException: Unable to find
explicit activity class
{com.example.utkarsh.internalstorage/com.example.utkarsh.internalstorage.SecondActivity};
have you declared this activity in your AndroidManifest.xml?
specify activity in your android manifest file
<activity android:name="SecondActivity"> </activity>
The issue is, the SecondActivity Activity wasn't added to the AndroidManifest.xml. Once you add that as an application node, it will work properly.
<activity android:name="com.example.utkarsh.internalstorage.SecondActivity" />
Error message is clear, define your activity in your manifest
I have a ADT app, myadtapp (myapppkg), uses an Android Lib, myadtlib (mylibpackage). Inside myadtlib project, I created a custom Activity, myjavapkg.MyActivity, and declare the Activity in MyAdtLib::AndroidManifest.xml:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="mylibpackage" ... >
...
<application>
<activity
android:name="myjavapkg.MyActivity"
android:exported="true" />
...
I am surprised the following code doesn't work:
Intent intent = new Intent();
intent.setClassName("mylibpackage", MyActivity.class.getName());
startActivity(intent);
The error is:
ActivityNotFoundException: Unable to find explicit activity class {mylibpackage/myjavapkg.MyActivity}; have you declared this activity in your AndroidManifest.xml?
If I move MyActivity declartion to the myadtapp manifest file, it would work, but I don't want to. What is wrong with the above using an MyActivity in an my Android lib?
This should work:
Intent intent = new Intent(this, MyActivity.class);
startActivity(intent);
I have an Android library project that I would like to use from within another Android project.
The library has a Activity declared in its AndroidManifest. When I try the following within the second project:
Intent intent = new Intent(this, ReaderActivity.class);
startActivity(intent);
I get the following exception:
java.lang.RuntimeException: Unable to start activity ComponentInfo{br.com.digitalpages.reader.demo/br.com.digitalpages.reader.demo.ReaderDemoActivity}: android.content.ActivityNotFoundException: Unable to find explicit activity class {br.com.digitalpages.reader.demo/br.com.digitalpages.reader.ReaderActivity}; have you declared this activity in your AndroidManifest.xml?
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
...
Caused by: android.content.ActivityNotFoundException: Unable to find explicit activity class {br.com.digitalpages.reader.demo/br.com.digitalpages.reader.ReaderActivity}; have you declared this activity in your AndroidManifest.xml?
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1404)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1378)
...
How can I open the Activity from the another project?
EDIT:
By users answers I added the following line into my second project
<uses-library android:name="br.com.digitalpages.reader" android:required="true" />
But it's still doesn't works
I believe you must include the <activity> in your own AndroidManifest.xml -- I don't think it gets picked up from a library. I don't have my reference for that handy.
Update: It's official solution. From the doc:
Declaring library components in the manifest file
In the manifest file of the application project, you must add
declarations of all components that the application will use that are
imported from a library project. For example, you must declare any
<activity>, <service>, <receiver>, <provider>, and so on, as well as
<permission>, <uses-library>, and similar elements.
Declarations should reference the library components by their
fully-qualified package names, where appropriate.
Intent intent = new Intent(android.content.Intent.ACTION_VIEW);
intent.setComponent(new ComponentName("packagename//ex-com.hello",
"classname//ex-com.hello.ExampleActivity"));
startActivity(intent);
And make sure in library you have declared the activities. You don't need to declare the library activities in your current project's manifest.
did you add to the manifest?
http://developer.android.com/guide/topics/manifest/uses-library-element.html
This works:
In your library, put your custom Activity:
public class MyLibraryActivity extends ListActivity { ... }
No need to put it into a manifest.
In your calling Android project, create an empty (dummy) wrapper:
public class MyActivity extends MyLibraryActivity { }
and add reference to this class to your manifest:
<activity android:name="my_package.MyActivity" ... />
I am aware that the question is quite old but I think this might help people like me that came up with the same problem.
Using Eclipse, the best way to share code and activities among libraries is probably the one that can be found in the android documentation here:
Managing Projects from Eclipse with ADT
When using an activity inside the library, the activity should be declared only inside the manifest of library.
The activity can be started from the main app like this:
Intent intent = new Intent();
intent.setClassName(this, "com.duna.remotelocklibrary.activities.MainRemoteActivity");
startActivity(intent);
I tried to start the library's activity like the following code, but i warn you: it doesn't work
Intent intent = new Intent();
intent.setClassName("com.duna.remotelocklibrary", "com.duna.remotelocklibrary.activities.MainRemoteActivity");
startActivity(intent);
you should import just the code of the activity ( not the manifest too ) , and then , declare your Activity ( of the library ) , in the manifest of your second project
You don't need to explicitly add activity in your main project's manifest if you have already added the activity in your library's manifest by using the following code when starting library's activity.
For Kotlin
val myIntent = Intent(activityContext, ActivityToLaunch::class.java)
// Needed to set component to remove explicit activity entry in application's manifest
myIntent.component = ComponentName(activityContext, PickerActivity::class.java)
activityContext.startActivity(myIntent, PICKER_REQUEST_CODE)
For Java
Intent myIntent = new Intent(activityContext, PickerActivity.class);
// Needed to set component to remove explicit activity entry in application's manifest
final ComponentName component = new ComponentName(activityContext, PickerActivity.class);
myIntent.setComponent(component);
activityContext.startActivity(myIntent, REQUEST_CODE);