Vinoth
Vinoth

Reputation: 1349

Android activity not found error?

I'm getting an activity not found exception. I'm starting a SplashScreen Activity and then passing the control to the MainActivity.

Here is my manifest file

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="se.copernicus.activity"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="5" />

    <uses-permission android:name="android.permission.INTERNET" />

    <application
        android:icon="@drawable/icon"
        android:label="@string/app_name" >

        <activity
            android:label="@string/app_name"
            android:name=".SplashScreenActivity" >
            <intent-filter >
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name="se.copernicus.activity.MainActivity" >
     </activity>

        <activity
            android:label="@string/second_activity"
            android:name="se.copernicus.activity.Secondactivity"
            android:theme="@android:style/Theme.NoTitleBar" >
        </activity>
    </application>
</manifest>

This is the splash screen activity that I am starting at first.

public class SplashScreenActivity extends Activity {
protected boolean _active = true;
protected int _splashTime = 5000;
Intent intent = new Intent("se.copernicus.activity.MainActivity");
Thread splashTread = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    splashTread = new Thread() {
        @Override
        public void run() {
            try {
                int waited = 0;
                Log.i("Coming here 1","Coming here 1");
                while(_active && (waited < _splashTime)) {
                    sleep(50);
                    Log.i("Coming here 2","Coming here 2");
                    if(_active) {
                        waited += 50;
                        Log.i("Coming here 3","Coming here 3");
                    }
                }
            } catch(InterruptedException e) {
                // do nothing
            }  finally {
                finish();
                Log.i("Coming here 4","Coming here 4");
                startActivity(intent);

                Log.i("Coming here 5","Coming here 5");

                if(splashTread!= null){
                    splashTread.stop();
                    splashTread=null;
                }
            }
        }
    };
    splashTread.start();
}
@Override
public boolean onTouchEvent(MotionEvent event) {
    if (event.getAction() == MotionEvent.ACTION_DOWN) {
        _active = false;
    }
    return true;
}

}

I've declared the activity in the manifest double checked for errors, the package name too. And yet this error shows up. Where am I making a mistake ?

The error logs:

E/AndroidRuntime(340): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=se.copernicus.activity.MainActivity }
E/AndroidRuntime(340):  at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1408)
E/AndroidRuntime(340):  at android.app.Instrumentation.execStartActivity(Instrumentation.java:1378)
E/AndroidRuntime(340):  at android.app.Activity.startActivityForResult(Activity.java:2827)
E/AndroidRuntime(340):  at android.app.Activity.startActivity(Activity.java:2933)
E/AndroidRuntime(340):  at se.copernicus.activity.SplashScreenActivity$1.run(SplashScreenActivity.java:41)

Upvotes: 0

Views: 2038

Answers (4)

inazaruk
inazaruk

Reputation: 74780

Take a look at Intent(String) documentation:

public Intent (String action)

action The Intent action, such as ACTION_VIEW.


Now take a look at this piece of your code:

Intent intent = new Intent("se.copernicus.activity.MainActivity");

It says that you want to start activity with action "se.copernicus.activity.MainActivity". But you don't want that. You want to start activity of class se.copernicus.activity.MainActivity. These are two different things!


And now look at error message:

No Activity found to handle Intent { act=se.copernicus.activity.MainActivity }

Notice the act part in error message, it stands for Action. This means that Android can not resolve any activity for action "se.copernicus.activity.MainActivity". This only proves my previous point.


Instead of treating your class name as action, you need to create correct Intent with empty action value, but with correct Activity class name (more precisely with correct Component Id). So you actually need to create Intent using another Intent constructor:

Intent intent = new Intent(SplashScreenActivity.this, MainActivity.class);

Upvotes: 2

Ratan
Ratan

Reputation: 1757

Just finish() your activity after launching ur activity ...

finally {

            Log.i("Coming here 4","Coming here 4");
            startActivity(intent);
            finish();
          ......

}

Upvotes: 1

Sver
Sver

Reputation: 3409

Uh. Try to do it like this.

 Intent intent = new Intent(SplashScreenActivity.this, MainActivity.class);
 startActivity(intent);

Upvotes: 0

Shailendra Singh Rajawat
Shailendra Singh Rajawat

Reputation: 8242

either set packagename in menifest application tag or give fully qualified activity name in SplashScreen activity

Upvotes: 0

Related Questions