I am getting an ActivityNotFoundException in the following code:
Main.java
Intent intent = new Intent();
intent.setAction("com.test.app.TEST");
startActivity(intent); // ActivityNotFoundException
Manifest.xml
<activity android:name=".MainActivity" android:theme="#android:style/Theme.Dialog">
<intent-filter>
<action android:name="com.test.app.TEST" />
</intent-filter>
</activity>
I've had this issue too, as perfectly concisely described by jpahn.
the period at the front did not give any help to me.
even with exactly this (a copy of the original question including edits), I would still get ActivityNotFoundException.
Main.java
Intent intent = new Intent();
intent.setAction("com.test.app.TEST");
startActivity(intent); // ActivityNotFoundException
Manifest.xml
<activity android:name=".MainActivity" android:theme="#android:style/Theme.Dialog">
<intent-filter>
<action android:name="com.test.app.TEST" />
</intent-filter>
</activity>
This was resolved, after much trial-and-error, by simply adding this to the intent-filter in the manifest:
<category android:name="android.intent.category.DEFAULT" />
So the final manifest file contained:
<activity android:name=".MainActivity" android:theme="#android:style/Theme.Dialog">
<intent-filter>
<action android:name="com.test.app.TEST" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
I got this error after moving an activity class from one package to another.
Clean build solved it (Project -> Clean).
Be sure to declare your activity in the manifest.xml within the aplication:
<application>
<activity android:name=".YourNewActivity"/>
</application>
To start the new Activity:
Intent intent = new Intent(main.this, YourNewActivity.class);
startActivity(intent);
Where main stands for the current activity,
Add a . (dot) before your activity name in Android Manifest. So it should be android:name=".WordsToSpeakMainActivity"
I have some addition to the #Tom Pace answer. The answer is completely right, but to make it more clear:
ActivityNotFoundException occurs because of absence of
<category android:name="android.intent.category.DEFAULT" />
Because when Android OS see this in the manifest file, understands that this activity can receive intent.
The point ActivityNotFoundException thrown is that, when activity(intent-creator-activity) tries to create intent for other activity(intent-receiver-activity), Android OS sees there is intent for receiver activity but receiver activity does not receive anyone. Then Android OS returns null or empty intent to intent-creator-activity. And startActivity throws that exception.
I have found a code from android developers to avoid this exception:
// Verify the original intent will resolve to at least one activity
if (sendIntent.resolveActivity(getPackageManager()) != null) {
startActivity(chooser);
}
Android Developers: Intent Filters
To be safe you can also call your new activity like this:
Intent intent = new Intent();
intent.setClass(this, THECLASSNAME);
startActivity(intent); //
However, you must add the activity to the androidmanifest - and write a . in front of it, e.g.
<activity android:name=".YOURACTIVITYNAME"></activity>
There two types of intents in android framework,
1-Implicit intents that you are using,
<activity android:name=".MainActivity" android:theme="#android:style/Theme.Dialog">
<intent-filter>
<action android:name="com.test.app.TEST" />
</intent-filter>
</activity>
just add one line in intent filter
<intent-filter>
<action android:name="com.test.app.TEST" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
2- Explicit Intents
Intent i=new Intent(CurrentActivity.this,WhereWeWantToGoActivity.class);
startActivity(i);
To launch an activity by a string definition, use:
Intent intent = new Intent();
intent.setComponent(
new ComponentName("com.app", "com.app.activity.TheActivity"));
startActivity(intent);
At the very top of your AndroidManifest.xml, you'll see the package attribute
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.android.example"
and then, in the activity tag, you'll see the name attribute:
<activity
android:name=".Something"
Make sure that the package name and activity name, when joined together, make the full package specification of your Activity i.e.
com.android.example + .Something = com.android.example.Something
Otherwise, you'll get a ActivityNotFoundException.
I found a solution to this problem... I´m using 2 modules in a android studio project, the thing here is that I needed to add the activity to the main manifest file
<activity android:name="com.HeadApp.ARTry.UnityPlayerActivity"
android:clearTaskOnLaunch="false" android:label="#string/app_name"
android:screenOrientation="portrait"
android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen"
/>
I had that in the unity activity manifest, I just copied the activity and paste it in the main manifest and that was it, hope it helps, eve been struggling a lot with this for the past 3 weeks
Related
There are 2-3 ways to use Intent to start New Activity.
Mostly, I am using
Intent openStartingPoint = new Intent("com.Example.Jeeten.Connection");
startActivity(openStartingPoint);
But sometimes, It does not work, It shows error Activity not found and in that case If I use
Intent openStartingPoint = new Intent(Connection.this, Hello.class);
startActivity(openStartingPoint);
then It works fine. What can be the issue with this ?
When u make an activity, u have to register it in your AndroidManifest.xml file.
<activity
android:name=".Connection"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.Example.Jeeten.CONNECTION" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
In the above code <activity android:name represents your activity class(Case sensitive),in your case its Connection and Hello.Next is <action android:name in this you specify by what name are you going to refer to the activity(its a good practice to put the last word all in uppercase CONNECTION).
So make sure you have two such activities in your xml file.In case one of the activity is your starting point of your app,modify the <intent-filter> like this
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
I would like to launch, from my app, two specific activities A_Activity and B_Activity from apps Aapp and Bapp
I inserted two buttons and in the two OnClickListener I wrote
Intent intent = new Intent();
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setAction("com.Acompany.Aapp.A_Activity");
ctx.startActivity(intent);
Intent intent = new Intent();
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setAction("com.Bcompany.Bapp.B_Activity");
ctx.startActivity(intent);
Moreover I added to AndroidManifest.xml the following lines
<activity
android:name="com.Acompany.Aapp.A_Activity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.Acompany.Aapp.A_Activity" />
</intent-filter>
</activity>
<activity
android:name="com.Bcompany.Bapp.B_Activity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.Bcompany.Bapp.B_Activity" />
</intent-filter>
</activity>
But my app crashes and in the logcat I read "No Activity found to handle Intent"
Where is my mistake?
EDIT: More precisely the two activities are not in my own app
More precisely the two activities are not in my own app
You should investigate target app's manifest file first, to check if these activities are available to others by being exported or offering publicly accessible intent filters. It looks you may simply be not allowed to do what you attempt to.
Try like this. For your home activity(first launch activity) do like this in your manifest file.xml
<activity
android:name="com.Acompany.LaunchHomeActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.Acompany.LaunchHomeActivity" />
</intent-filter>
</activity>
<activity android:name="com.Acompany.Aapp.A_Activity">
</activity>
<activity android:name="com.Bcompany.Bapp.B_Activity">
</activity>
don't include <intent-filter> to all activities
Intent intent = new Intent(myFirstClass.this, MySecondClassA.class);
startActivity(intent);
Class B
Intent intent = new Intent(myFirstClass.this, MySecondClassB.class);
startActivity(intent);
I have an android project with several packages. The structure of the packages in this case is com.WAPP.SetLocation is the package that contains the activity I want to run.
In my manifest, com.WAPP is considered the base package:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.WAPP"
android:versionCode="1"
android:versionName="1.0">
My activities are declared in my manifest as:
<activity android:name=".mainScreenActivity"></activity>
<activity android:name=".SetLocation.setLocationActivity"></activity>
The mainScreen activity displays fine, since it is inside the com.WAPP package. But when I try to run the setLocationActivity, I get the unable to find explicit class error. Here is how I have the intent parameters:
Intent i = new Intent();
i.setClassName("com.WAPP.SetLocation",
"com.WAPP.SetLocation.setLocationActivity");
startActivity(i);
The first parameter is application package not the package where the activity is.
You can invoke the Activity like this.
Intent i = new Intent();
i.setClassName("com.WAPP",
"com.WAPP.SetLocation.setLocationActivity");
startActivity(i);
It is preferred as SYLARRR suggested to have Android automatically figure that out for you. Hence the call as..
startActivity(new Intent(this, setLocationActivity.class));
It's recommended per java standards to have the package name all lower-cased and the class name as CamelCased.
If the new activity not in the same packet with MainActivity(you call from here?), try declare on manifest
<activity android:name="com.WAPP.SetLocation.setLocationActivity"></activity>
and in the caller
Intent intent = new Intent(this, setLocationActivity.class);
startActivity(intent);
Hope this helps!
In additional to the above answers make sure that your activities are declared inside application in manifest
<application
android:allowBackup="true"
android:label="#string/app_name"
android:supportsRtl="true">
<activity android:name=".mainScreenActivity"></activity>
<activity android:name=".SetLocation.setLocationActivity"></activity>
</application>
If i'm not mistaken, the i.setClassName("com.WAPP.SetLocation","com.WAPP.SetLocation.setLocationActivity"); should be i.setClassName(getBaseContext(),"setLocationActivity"); Reference
Also try this syntax:
startActivity(new Intent(MyActivity.this, setLocationActivity.class));
and try removing the starting dot from:
<activity android:name=".SetLocation.setLocationActivity"></activity>
Do it by this way:
Intent intent = new Intent();
intent.setComponent(
new ComponentName("com.WAPP", "com.WAPP.SetLocation.setLocationActivity"));
startActivity(i);
you should class ad to manifest.xml
for example of manifest.xml
in this example, i added SecondActivity.class
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myapplication">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/Theme.MyApplication">
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".SecondActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
In Xamarin Android, make sure that your Activity class has an Activity attribute
[Activity(Theme = "#style/MyTheme")]
public class MyActivity : ActivityBase
{
...
}
With that you are making sure that your activity is registered in AndroidManifest.xml
I had the same kind of issue in the project . It wasted me almost a full day . i tried all the solutions that are mentioned above , but none of the solutions worked for me .
After all the hard work i just "Rebuild" the project and "clean" The project and it worked perfectly .
Note:
Before going through all the process u just needed to have a try to these options.
First of all, make sure that you have created activity and not the class. And, if it is activity then go to the manifest.xml file and look at the path of that particular file.
This worked for me absolutely well!!
https://forums.xamarin.com/discussion/104102/android-content-activitynotfoundexception-unable-to-find-explicit-activity-class
this is for reference
in your manifest you declared it as
.SetLoction.setLocationActivity
but
the package name is com.WAPP.SetLocation
so you need to prefix that again.
Intent i = new Intent();
i.setClassName("com.WAPP.SetLocation",
"com.WAPP.SetLocation.SetLocation.setLocationActivity");
startActivity(i);
This might be due to not registering your next activity XML file in the manifest. Register your next activity XML file in the AndroidManifest.xml file
<activity android:name=".NextActivity" />
Hope it helps.
Thia might be problem if ImageView is used :(
Intent intent = new Intent(context,ImageView.class);
intent.putExtra("imageurl",clients_document_return.getUrl());
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
v.getContext().startActivity(intent);
and your class name might me Imageview.class
so first check all small capital in class name
Thanks :)
we know that there are flags which we can add to our intent using the addFlags() method in our java code. Is there any way we can add these flags in the manifest file itself instead of writing this in java code.
I need to add REORDER_TO_FRONT flag for one of my activities in the manifest.
How to achieve this ?
In manifest file you can not add Intent flags.You need to set the flag in Intent which u pass to startActivity. Here is a sample:
Intent intent = new Intent(this, ActivityNameToLaunch.class);
intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
startActivity(intent);
To answer the original question, since this appears as the first answer in the google search, it can be done, since API level 3 (introduced in 2009) with adding android:noHistory="true" to the activity definition in the manifest file as described here: http://developer.android.com/guide/topics/manifest/activity-element.html#nohist.
example:
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:noHistory="true">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.cataegory.LAUNCHER"/>
</intent-filter>
</activity>
I had a similar problem and wanted to set the flags
Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK
in order to bring the activity always to top.
In this scenario, the solution is to set the attribute
android:launchMode="singleInstance"
in the manifest.
Generally, there are many attributes in the Android manifest for an activity, and you may play around with these to get similar effects as with flags.
You can easily achieve this with using android:launchMode="singleTop" in the <activity> node of manifest, like this:
<activity
android:name=".ui.activities.MainActivity"
android:launchMode="singleTop">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Note, that android:launchMode="singleInstance" as it is given by #jörg-eisfeld is not recommended option for general use, as it is stated in official documentation: https://developer.android.com/guide/topics/manifest/activity-element.html (see the android:launchMode section)
I want to call other apps activity from my app. So I am using the following code
Intent i = new Intent();
i.setComponent(new ComponentName("com.android.DailyDeals",
"com.android.DailyDeals.TodaysDeals_AM" ));
startActivity(i);
But I am getting following exception:
Caused by: java.lang.SecurityException: Permission Denied:
starting Intent { cmp=com.android.DailyDeals/.TodaysDeals_AM } from
ProcessRecord{44f9b8b0 399:com.prabhu.android/10041} (pid=399, uid=10041)
requires null.
How to resolve this?
i think this will help you
make code in your java file like this.
startActivity(new Intent("com.name of your class"));you have to write your package name .classname inside it.
& also declare this activity into your **mainfest** file
<activity android:name=".name of your class"
android:label="#string/app_name">
<intent-filter>
<action android:name="com.diffrentview.MYFILE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>