My splash screen ( splash.java ) works fine , it appear for 5 sec when I call it Launcher
in Android Manifest , but when i fix it as Default
in Android Manifest and run it through List Activity
( Menu.java ) , it run for 5sec and then instead of going back to Menu.java it crashes with run time error . I want it to appear for 5 sec and then go back to the menu.java.
The manifest in which it not work for 5 sec but application crash run time after 5 sec (Unfortunately your application has stopped)
<activity
android:name=".Menu"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".splash"
android:label="@string/app_name" >
<intent-filter>
<action android:name="com.example.hello.SPLASH" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
This splash.java
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity2);
tone = MediaPlayer.create(splash.this, R.raw.songg);
tone.start();
Thread haai = new Thread()
{
public void run()
{
try
{
sleep(5000);
}
catch (InterruptedException e)
{
e.printStackTrace();
}
finally
{
Intent first = new Intent("com.example.hello.Menu");
startActivity(first);
}
}
};
haai.start();
}
Error log:
E/AndroidRuntime(25707): FATAL EXCEPTION: Thread-30562
E/AndroidRuntime(25707): Process: com.example.hello, PID: 25707
E/AndroidRuntime(25707): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=com.example.hello.Menu }
E/AndroidRuntime(25707): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1672)
E/AndroidRuntime(25707): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1442)
E/AndroidRuntime(25707): at android.app.Activity.startActivityForResult(Activity.java:3511)
E/AndroidRuntime(25707): at android.app.Activity.startActivityForResult(Activity.java:3472)
E/AndroidRuntime(25707): at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:817)
E/AndroidRuntime(25707): at android.app.Activity.startActivity(Activity.java:3714)
E/AndroidRuntime(25707): at android.app.Activity.startActivity(Activity.java:3682)
E/AndroidRuntime(25707): at com.example.hello.splash$1.run(splash.java:36)
I am not satisfied with my own answer because i am in learning stage so waiting for better answer with explanation of its working and problem.
ActivityNotFoundException: No
Because not Activity found with com.example.hello.MENU
action in manifest.
To fix issue,use com.example.hello.MENU
action string for Menu
Activity. like:
<activity
android:name=".Menu"
android:label="@string/app_name" >
<intent-filter>
<action android:name="com.example.hello.MENU" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Or you can start Activity using target Activity class name :
Intent intent=new Intent (splash.this,Menu.class);
splash.this.startActivity(intent);
The problem is in the manifest you have set the activity name .Menu whereas in the java code you have set it as MENU(uppercase).
<activity
android:name=".Menu" <---- activity name as .Menu
android:label="@string/app_name" >
In java code as:
Intent first = new Intent("com.example.hello.MENU")<---.MENU- its all uppercase
Change it in java code as below to fix your problem:
Intent first = new Intent("com.example.hello.Menu");
startActivity(first);
I find the answer , its simple but I use the other way but still I don't find why the program works fine when .splash
make as Main
and LAUNCHER
, but when make .Menu
as Main
and LAUNCHER
program run but when I select splash from Menu List it run for 5 seconds then instead of going back to Menu again it crashes with runtime error . I changed the .splash
code to the below code and it works but as I am new to android I don't know why the last way was not working.
public void run()
{
try
{
sleep(5000);
}
catch (InterruptedException e)
{
e.printStackTrace();
}
finally
{
try
{
Class ourclass = Class.forName("com.example.hello.Menu");
Intent myclass = new Intent(splash.this , ourclass);
startActivity(myclass);
}
catch(ClassNotFoundException e)
{
e.printStackTrace();
}
}
}
I didn't change anything from Android Manifest
The problem is you declared intent action is .SPLASH but you create action is .MENU
change
Intent first = new Intent("com.example.hello.MENU");
startActivity(first);
to
Intent first = new Intent("com.example.hello.SPALSH");
startActivity(first);
or change your manifest like this
<activity
android:name=".splash"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".Menu"
android:label="@string/app_name" >
<intent-filter>
<action android:name="com.example.hello.MENU" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.