Activity Access via Manisfest File - Android

Asked

Viewed 62 times

0

Hello, everybody.

I’m trying to build an app inspired by pokedex for a challenge, and trying to use the MVC architecture.

I’m having problems accessing the activities (that are inside the packages I created) through the manifest file.

Below is manifest code and activities.

Could someone tell me what is wrong on the way to Activity?

Manifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    package="com.pokemon">



    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_splash_screen_pokemon_round"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme"
        >

        <activity android:name="com.pokemon.View.SplashScreenActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name="com.pokemon.View.MainActivity"/>
    </application>

</manifest>

Mainactivity.java

package com.pokemon.View;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;

import com.pokemon.R;

public class MainActivity extends AppCompatActivity 
{

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

Splashscreenactivity.java

package com.pokemon.View;

import android.content.Intent;
import android.os.Handler;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;

import com.pokemon.R;

public class SplashScreenActivity extends AppCompatActivity
{

    /* Timer Splash Screen */
    private static int SPLASH_TIME_OUT = 5000;

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


        new Handler().postDelayed(new Runnable()
        {
            /* THis method will run right after the execution of the splash finish */
            @Override
            public void run()
            {   /* The Main Activity will be started */
                Intent intent = new Intent(SplashScreenActivity.this, MainActivity.class);
                startActivity(intent);

                finish();
            }
        }, SPLASH_TIME_OUT);
    }
}

Files Structure in the project

enter image description here

1 answer

2


Like the package (package="com.pokemon") is already specified in the tag <manifest>, you need to indicate only what is "missing". Note that the name should start with a point .:

<activity android:name=".View.MainActivity"/>

This information can be found on documentation:

This name is used to resolve all relative class names declared in the manifest archive.

Example: with the manifesto <manifest package="com.example.myapp">, an activity declared as <activity android:name=".MainActivity"> is resolved to be com.example.myapp.MainActivity.

  • Thanks for your help. The problem was actually some packages that had renamed (I think wrong) and Android Studio was not identifying well what it should run. I redid the project with the packages from scratch and it worked.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.