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)
Take a look at
Intent(String)documentation:Now take a look at this piece of your code:
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 classse.copernicus.activity.MainActivity. These are two different things!And now look at error message:
Notice the
actpart in error message, it stands forAction. 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
Intentwith empty action value, but with correctActivityclass name (more precisely with correct Component Id). So you actually need to createIntentusing anotherIntentconstructor: