Reputation: 1424
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);
Upvotes: 43
Views: 105069
Reputation: 284
For anyone who encounters this issue specifically for react native:
If you're using firebase dynamic links on Android 13, you need to explicitly define the host and scheme in your AndroidManifext.xml
Let's say your dynamic link looks like this:
https://example.page.link/?link=https://www.example.com/someresource&apn=com.example.android&amv=3&ibi=com.example.ios&isi=1234567&ius=exampleapp
You need to set the host to example.com
and scheme to https
The reason is in Android 13, non-matching intents are blocked https://developer.android.com/about/versions/13/behavior-changes-all#intents
Example:
<application
android:name=".MainApplication"
android:label="@string/app_name"
android:icon="@mipmap/ic_launcher"
android:roundIcon="@mipmap/ic_launcher_round"
android:allowBackup="false"
android:theme="@style/AppTheme"
android:requestLegacyExternalStorage="true"
>
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|screenSize|smallestScreenSize|uiMode"
android:launchMode="singleTask"
android:windowSoftInputMode="adjustResize"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data
android:host="example.com"
android:scheme="https"/>
<data
android:host="sample.com" //You need to add other domains if you have more than one link.
android:scheme="https"/>
</intent-filter>
</activity>
</application>
This issue helped a lot https://github.com/firebase/firebase-android-sdk/issues/4198
Upvotes: 0
Reputation: 4201
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>
Upvotes: 2
Reputation: 524
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 :)
Upvotes: 0
Reputation: 527
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!!
this is for reference
Upvotes: 1
Reputation: 11
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.
Upvotes: 0
Reputation: 119
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.
Upvotes: 1
Reputation: 2565
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
Upvotes: 1
Reputation: 918
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);
Upvotes: 0
Reputation: 933
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>
Upvotes: 15
Reputation: 617
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!
Upvotes: 21
Reputation: 13639
Do it by this way:
Intent intent = new Intent();
intent.setComponent(
new ComponentName("com.WAPP", "com.WAPP.SetLocation.setLocationActivity"));
startActivity(i);
Upvotes: 3
Reputation: 14740
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.
Upvotes: 32
Reputation: 6449
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>
Upvotes: 4