Categories
discuss

Android Studio: Error: SplashActivity is not an Activity subclass or alias

I have a library project which has all functionality and some activities, and I also have a wrapper activity which only has a JSON configuration string and some styling. I imported the library to the …

I have a library project which has all functionality and some activities, and I also have a wrapper activity which only has a JSON configuration string and some styling. I imported the library to the wrapper project, and in the wrapper project I’m setting one of the library’s activities as the launch activity, but then get an error that the selected activity from the library is not an activity subclass or alias.

What does that mean and can I correct this?

The Activity that is supposed to be launched:

package dk.borgertip.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;

import dk.borgertip.R;

public class SplashActivity extends Activity {

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

        Thread startTimer = new Thread() {
            @Override
            public void run() {
                try {
                    sleep(3000);
                    Intent i = new Intent(SplashActivity.this, MainActivity.class);
                    startActivity(i);
                    finish();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        };
        startTimer.start();
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_splash, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }
}

The project structure: (The Borgertip module is the library that contains the activity to launch which extends Activity)

The Borgertip module is the library that contains the activity to launch

The ‘Edit Configuration’ dialog with the error:

enter image description here

What do I do wrong?

Answer

You have to include the activity in your project AndroidManifest.xml

Source official doc:

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.
Source: stackoverflow
Text is available under the Creative Commons Attribution-ShareAlike License; additional terms may apply. By using this site, you agree to the Privacy Policy, and Copyright Policy. Content is available under CC BY-SA 3.0 unless otherwise noted. The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 © No Copyrights, All Questions are retrived from public domain..