Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Activity not declared in AndroidManifest.xml even if it is

Suddenly I get the following error:

android.content.ActivityNotFoundException: Unable to find explicit activity class.

Although I have declared in the file AndroidManifest.xml all the activities of my application. Does anyone know how to fix this error? Thank you all

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.uniparthenope.jacoe.homework_tmm">
<uses-feature android:name="android.hardware.camera"
              android:required="true"/>

<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/AppTheme">
    <activity android:name=".MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity android:name=".SignUpActivity"
        android:parentActivityName=".MainActivity">
    <!-- The meta-data tag is required if you support API level 15 and lower -->
    <meta-data
        android:name="android.support.PARENT_ACTIVITY"
        android:value=".MainActivity"/>
</activity>
</application>

</manifest>

This is my MainActivity.java, in which I call the activity SignUpActivity.java through an Intent.

import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

private TabLayout tabLayout;
private ViewPager viewPager;

ChatFragment chatFragment;
CallsFragment callsFragment;
StatusFragment statusFragment;
PhotoFragment  photoFragment;

String[] tabTitle = {"FOTO", "CHIAMATE", "CHAT", "STATO"};
int[] unreadCount = {0, 0, 5, 0};

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_tab);

    Toolbar toolbarapp = (Toolbar) findViewById(R.id.Whatsapp_tmm_toolbar);
    setSupportActionBar(toolbarapp);


    viewPager = (ViewPager) findViewById(R.id.viewpager);
    viewPager.setOffscreenPageLimit(4);
    setupViewPager(viewPager);

    tabLayout = (TabLayout) findViewById(R.id.tablayout);
    tabLayout.setupWithViewPager(viewPager);

    viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

        }

        @Override
        public void onPageSelected(int position) {
            viewPager.setCurrentItem(position, false);

        }

        @Override
        public void onPageScrollStateChanged(int state) {

        }
    });
}


@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.menu_button, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle item selection
    switch (item.getItemId()) {
        case R.id.login:
             Intent login = new Intent(this, SignUpActivity.class);
             startActivity(login);
             finish();
             return true;
like image 787
Jacopo Avatar asked Mar 11 '26 16:03

Jacopo


2 Answers

try to sync with " sync Project with Gradle files" inside Android Studio->Files->Sync Project with Gradle Files.

Sometime we miss to do this after having changes to Manifest.

like image 153
Manish S Avatar answered Mar 13 '26 08:03

Manish S


I had this issue on Android Studio 4.0.1, android gradle 4.0.1 build gradle 6.1.1 and could not resolve it with the answers here.

What eventually fixed it for me was going to my app folder and deleting the entire .gradle folder, then invalidating cache and restarting. Normal cache invaldiation didn't work. Rebuilding, cleaning, syncing with gradle: None of it worked without me going in and deleting the entire .gradle folder.

like image 21
Matthew Bahr Avatar answered Mar 13 '26 08:03

Matthew Bahr



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!