I'm programming a new app which contains a splash screen.
I've finished it and it was all good. After I've opened android studio again to work on the navigation bar I've tried to run the app to see the result but the application stopped and crashed after the display of the splash screen.
this is Main class
package com.example.computer.bsinfoshop;
public class Main extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
and this is the class od splash screen
package com.example.computer.bsinfoshop;
import android.graphics.Typeface;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.content.Intent;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
public class Screen extends AppCompatActivity {
TextView tv;
ImageView img;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_screen);
tv = (TextView)findViewById(R.id.textView);
img = (ImageView)findViewById(R.id.imageView);
Typeface font = Typeface.createFromAsset(getAssets(),"fonts/Satisfy-Regular.ttf");
tv.setTypeface(font);
img.setImageResource(R.drawable.rsz_2rsz_img);
Thread timerThread = new Thread(){
public void run(){
try
{
sleep(3700);
}
catch(InterruptedException e)
{
e.printStackTrace();
}
finally {
Intent intent = new Intent(Screen.this , Main.class);
startActivity(intent);
}
}
};
timerThread.start();
}
#Override
protected void onPause() {
super.onPause();
finish();
}
}
and here where i think is the problem
the manifest file
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.computer.bsinfoshop">
<application
android:allowBackup="true"
android:icon="#drawable/logo"
android:label="#string/app_name">
<activity
android:name=".Screen"
android:theme="#style/App">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Information"
android:label="Information"
android:theme="#style/AppTheme">
</activity>
<activity
android:name="com.example.computer.bsinfoshop.Main"
android:theme="#style/AppTheme">
</activity>
</application>
</manifest>
I just want to know what is the problem in my code and how can I fix it. thank you ^^
Change Thread to something like this:
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
finish();
startActivity(new Intent(Screen.this, Main.class));
}
}, 1500);
To be honest, I think this is not the correct way of creating a Splash Screen. That way you force the user to wait for 3 seconds which causes a bad user-experience.
Have a look at that tutorial and your users will thank you! https://www.bignerdranch.com/blog/splash-screens-the-right-way/
Related
Firstly, I am pretty new to Android programming and I am trying to develop a simple app that shows a message, and when you press the button that's under the message, it sends you to a 2nd activity, which is a form. The app isn't linked to any database, I was just trying to develop a validation algorithm within the app, so the data that's written in the EditText's it's correct. Like the Name only with letters, etc. I created both activities, it worked to jump from the 1st one to the 2nd one after pressing the button, but that was before I added the validation algorithm. Now, with that implemented, whenever I press on the "Start!" button(1st activity-submit one), the apps just crashes.
The manifest:
<?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.example.myapplication">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme"
tools:ignore="GoogleAppIndexingWarning">
<activity
android:name=".Inregistrare"
android:exported="true"
android:theme="#style/AppTheme1" />
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
The 1st app MainActivity.java:
package com.example.myapplication;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button submitButton = findViewById(R.id.submitButton);
submitButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Inregistrare();
}
});
}
public void Inregistrare(){
Intent intent = new Intent(this,Inregistrare.class);
startActivity(intent);
}
}
The 2nd activity Inregistrare.java:
package com.example.myapplication;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
public class Inregistrare extends AppCompatActivity {
EditText nume, prenume, email, telefon;
TextView rezultat;
Button submit;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_inregistrare);
submit.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view)
{ final String Nume = nume.getText().toString();
final String Prenume=prenume.getText().toString();
final String Email=email.getText().toString();
final String Telefon=telefon.getText().toString();
if(Nume.length()==0)
{
nume.requestFocus();
nume.setError("Campul nu poate fi lasat liber");
}
else if(!Nume.matches("[a-zA-Z ]+"))
{
nume.requestFocus();
nume.setError("Campul poate fi completat doar cu litere");
}
else if(Prenume.length()==0)
{
prenume.requestFocus();
prenume.setError("Campul nu poate fi lasat liber");
}
else if(!Prenume.matches("[a-zA-Z ]+")) {
prenume.requestFocus();
prenume.setError("Campul poate fi completat doar cu litere");
}
else if(Email.length()==0)
{
email.requestFocus();
email.setError("Campul nu poate fi lasat liber");
}
else if(!Email.matches("^[A-Z0-9._%+-]+#[A-Z0-9.-]+\\.[A-Z]{2,6}$"))
{
email.requestFocus();
email.setError("Campul poate fi completat doar cu litere");
}
else if(Telefon.length()==0 || Telefon.length()<10)
{
telefon.requestFocus();
telefon.setError("Campul nu poate fi lasat liber si trebuie sa aiba minim 10 cifre");
}
else if(!Telefon.matches("[0-9]+"))
{
telefon.requestFocus();
telefon.setError("Campul poate fi completat doar cu cifre");
}
else{
rezultat = findViewById(R.id.rezultat);
String date="Date corecte!";
rezultat.setText(date);
}
}
})
;}
}
I tried using another activity to check the switch and it works. The problem is somewhere in inregistrare.java (2nd activity) but i cant seem to find it. I didnt add the .xml's because i dont this that there's any problem. As i said i am pretty new to this, so please be kind and dont yell at me if i did a big mistake.
Thanks in advance!
Aim
To login to my Admin.xml via AdminLogin.xml
Flow of Classes
AdminLoginActivity ---> AdminActivity
AdminLoginActivityClass
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class AdminLoginActivity extends AppCompatActivity {
private Toolbar jAdminToolbar;
private EditText jAdminID;
private EditText jAdminPassword;
private Button jAdminLoginBtn;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_admin_login);
jAdminToolbar = (Toolbar) findViewById(R.id.adminLoginToolbar);
setSupportActionBar(jAdminToolbar);
getSupportActionBar().setTitle("Admin Login");
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
jAdminID = (EditText) findViewById(R.id.adminLoginName);
jAdminPassword = (EditText) findViewById(R.id.adminLoginPassword);
jAdminLoginBtn = (Button) findViewById(R.id.adminLoginBtn);
jAdminLoginBtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
String adminLoginID = jAdminID.getText().toString();
String adminLoginPassword = jAdminPassword.getText().toString();
if(adminLoginID.equals("admin")&& adminLoginPassword.equals("admin")){
Intent intentAdmin = new Intent(AdminLoginActivity.this, AdminActivity.class);
intentAdmin.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(intentAdmin);
finish();
}else{
Toast.makeText(AdminLoginActivity.this, "Failed Login", Toast.LENGTH_SHORT).show();
return;
}
}
});
}
}
AdminActivityClass
import android.content.Intent;
import android.support.design.widget.TabLayout;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
public class AdminActivity extends AppCompatActivity {
private FirebaseAuth mAdminAuth;
private Toolbar jAdminToolbar;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_admin);
mAdminAuth = FirebaseAuth.getInstance();
jAdminToolbar = (Toolbar) findViewById(R.id.adminToolbar);
setSupportActionBar(jAdminToolbar);
getSupportActionBar().setTitle("Administrator");
}
#Override
public void onStart() {
super.onStart();
FirebaseUser currentUser = mAdminAuth.getCurrentUser();
if(currentUser == null){
sendUserToStartPage();
}
}
private void sendUserToStartPage(){
Intent intentStart = new Intent(AdminActivity.this, StartActivity.class);
startActivity(intentStart);
finish();
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
getMenuInflater().inflate(R.menu.activity_admin_menu, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
super.onOptionsItemSelected(item);
if(item.getItemId() == R.id.mainSignOutBtn){
FirebaseAuth.getInstance().signOut();
sendUserToStartPage();
}
if(item.getItemId() == R.id.mainViewContactsBtn){
Intent intentViewContacts = new Intent(AdminActivity.this, AllUsersActivity.class);
startActivity(intentViewContacts);
}
return true;
}
}
Manifest File
<?xml version="1.0" encoding="utf-8"?>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<application
android:name=".SecurityApp"
android:allowBackup="true"
android:icon="#mipmap/appiconone"
android:label="#string/app_name"
android:roundIcon="#mipmap/appiconone"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".StartActivity" />
<activity
android:name=".ResidentRegistrationActivity"
android:parentActivityName=".StartActivity" />
<activity
android:name=".AdminLoginActivity"
android:parentActivityName=".LoginActivity">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.example.lenovo.securityapp.LoginActivity" />
</activity>
<activity
android:name=".LoginActivity"
android:parentActivityName=".StartActivity" />
<activity
android:name=".SettingsActivity"
android:parentActivityName=".MainActivity" />
<activity
android:name=".DetailsActivity"
android:parentActivityName=".SettingsActivity" />
<activity
android:name=".AllUsersActivity"
android:parentActivityName=".MainActivity" />
<activity android:name=".UserProfileActivity" />
<activity
android:name=".HelpInformationActivity"
android:parentActivityName=".StartActivity" />
<activity android:name=".AdminActivity" />
</application>
Problem
ToolBar on AdminLogin does not allow me to return to LoginActivity when I select the back Button
Admin Login does not work despite entering the hardcoded input for the Admin Name and Password. After clicking on the Login button, the app prompts out a White layout for a few seconds I am brought back to the StartActivity and the Toast message does not show "Failed Login".
SOLUTION
The problem was because the "AdminActivityClass" had
#Override
public void onStart() {
super.onStart();
FirebaseUser currentUser = mAdminAuth.getCurrentUser();
if(currentUser == null){
sendUserToStartPage();
}
}
private void sendUserToStartPage(){
Intent intentStart = new Intent(AdminActivity.this, StartActivity.class);
startActivity(intentStart);
finish();
}
Since the Admin login was hardcoded, the currentUser within the FirebaseUser currentUser = mAdminAuth.getCurrentUser(); was set to null. This caused the activity to be sent back to the start page (sendUserToStartPage();)
After posting your full set of code, you should be doing the following.
comment out the sendUserToStartPage(); inside of the currentuser == null and then try.
why? Because the user IS null. why? because you hard coded it into the code. The user admin with password admin does not exist in your Firebase (and if it does, you never checked it prior) so when you sign in, you do not create a session for admin, therefore the current user is null.
try doing this
if ("admin".equals(adminLoginID)) {
if ("admin".equals(adminLoginPassword)) {
//goto activity
}
} else {
//not admin
}
this might be better actually
if (("admin".equals(adminLoginID)) && ("admin".equals(adminLoginPassword))) {
//goto activity
} else {
//not admin
}
or even this....
if (("admin".equals(jAdminID.getText().toString().trim())) && ("admin".equals(jAdminPassword.getText().toString().trim()))) {
//goto activity
} else {
//not admin
}
Try this example in the manifest.
Youre manifest for the activities are missing a theme.
Also, its missed the meta-data.
<activity
android:name=".Leagues.CreateLeague"
android:label="Create League"
android:parentActivityName=".MainActivity"
android:screenOrientation="portrait"
android:theme="#style/AppTheme2">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.aaa.bbb.MainActivity" />
</activity>
Try like this smartly
take a String variable globally and declare and intialise them
in next step you need to add validations
String str_admin="admin";
if ((str_admin.equals(adminLoginID)) && (str_admin.equals(adminLoginPassword))) {
//pass reference of activity which you want to open it
} else {
//not admin
}
Happy to help yoh
I have a problem with my application I am making on Android Studio. I don't know why, but after the splash screen, the application crashes. I want the activity "Accueil" to open after the splash screen. It worked fine last week and now it doesn't anymore. I didn't touch anything. I show you the manifest, and the .java files.
Splashscreen.java:
import android.app.Activity;
import android.content.Intent;
import android.graphics.PixelFormat;
import android.os.Bundle;
import android.view.Window;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import android.widget.LinearLayout;
public class Splashscreen extends Activity {
public void onAttachedToWindow() {
super.onAttachedToWindow();
Window window = getWindow();
window.setFormat(PixelFormat.RGBA_8888);
}
Thread splashTread;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splashscreen);
StartAnimations();
Thread loading = new Thread() {
public void run() {
try {
sleep(5000);
Intent main = new Intent(Splashscreen.this,Menu.class);
startActivity(main);
finish();
} catch (Exception e) {
e.printStackTrace();
} finally {
finish();
}
}
};
loading.start();
}
private void StartAnimations() {
Animation anim = AnimationUtils.loadAnimation(this, R.anim.alpha);
anim.reset();
LinearLayout l = (LinearLayout) findViewById(R.id.lin_lay);
l.clearAnimation();
l.startAnimation(anim);
anim = AnimationUtils.loadAnimation(this, R.anim.rotate);
anim.reset();
ImageView iv = (ImageView) findViewById(R.id.splash);
iv.clearAnimation();
iv.startAnimation(anim);
splashTread = new Thread() {
#Override
public void run() {
try {
int waited = 0;
while (waited < 3500) {
sleep(100);
waited += 100;
}
Intent intent = new Intent(Splashscreen.this,Menu.class);
startActivity(intent);
finish();
} catch (InterruptedException e) {
}
}
};
}
}
Android Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.thibaudmangeot.erdfapplicationsecurite">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme">
<activity android:name=".Splashscreen"
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=".Accueil"
android:label="#string/title_activity_accueil"/>
</application>
</manifest>
Accueil.java:
package com.example.thibaudmangeot.erdfapplicationsecurite;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.widget.Button;
import android.view.View;
public class Accueil extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_accueil);
Button buttonfis = (Button) findViewById(R.id.buttonfis);
buttonfis.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
goTosignin();
}
});
}
private void goTosignin() {
Intent intent = new Intent(this, Menu.class);
startActivity(intent);
}
}
Do this
Intent main = new Intent(Splashscreen.this, Accueil.class);
startActivity(main);
finish();
Instead of
Intent main = new Intent(Splashscreen.this, Menu.class);
startActivity(main);
finish();
You have not even mentioned Menu activity in your manifest.
This is your error:
Intent main = new Intent(Splashscreen.this,Menu.class);
it should be:
Intent main = new Intent(Splashscreen.this, Accueil.class);
I think your application is crashing maybe because of two reasons
There is no Activity named "Menu"
Menu Activity is not mentioned in manifest file
If you want to open "Accueil" activity then write your intent in following fashion.
Intent openAccueil = new Intent(Splashscreen.this,Menu.class);
startActivity(openAccueil);
I am new to programming and I am trying to figure out how Activities in android programming work by making a small app,which should let me know in which state of the activity I am.
I am getting an error in the setContentView because Android Studio says "cannot resolve symbol "R""
Here is my code:
package com.example.daniele.activity;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
public class MainActivity extends Activity {
String tag = "Lifecycle";
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Log.d(tag, "in the onCreate() event");
}
public void onStart() {
super.onStart();
Log.d(tag, "in the onStart() event");
}
public void onRestart() {
super.onRestart();
Log.d(tag, "in the onRestart() event");
}
public void onResume() {
super.onResume();
Log.d(tag, "in the onResume() event");
}
public void onPause() {
super.onPause();
Log.d(tag, "in the onPause() event");
}
public void onStop() {
super.onStop();
Log.d(tag, "in the onStop() event");
}
public void onDestroy() {
super.onDestroy();
Log.d(tag, "in the onDestroy() event");
}
}
here is my AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.daniele.activity" >
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Everyone is suggesting you the fix. Good. But since you are learning, you should also understand what is happening here:
All layout files are in xml
Every xml file is compiled and made available to java classes
The compiled class is called R.java
To make
R.java available to your class you need to import it
Under
import android.util.Log;
add this
import com.example.daniele.R;
Alternatively when you see a red underline under something, you can hover above it and Android Studio usually tells you what you need to do. In this case, "Optimize Imports" or something similar.
"R" errors usually happen when one or more of your XML files is corrupt. Start by seeing if your apps manifest looks correct!
You will need to import R because your activity is in a different package.
import com.example.daniele.R;
I'm pretty new to Java and xml i'm looking to have a splash screen run when i start up my app for about 5 seconds. I've taken code for the splash screen from stack overflow to set it up but i cant get it to run for some reason could anybody help me out!
Cheers
MY splash class
package com.darraghoflaherty.competer.game;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.Menu;
public class Splash extends Activity {
/** Duration of wait **/
private final int SPLASH_DISPLAY_LENGTH = 5000;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.splashscreen);
/* New Handler to start the Menu-Activity
* and close this Splash-Screen after some seconds.*/
new Handler().postDelayed(new Runnable(){
#Override
public void run() {
/* Create an Intent that will start the Menu-Activity. */
Intent mainIntent = new Intent(Splash.this,Menu.class);
Splash.this.startActivity(mainIntent);
Splash.this.finish();
}
}, SPLASH_DISPLAY_LENGTH);
}
My xml code
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#0099FF">
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="#string/ss1"
android:id="#+id/ss1"
android:textColor="#ffffff"
android:textSize="260sp"/>
</RelativeLayout>
first change this peace of code :
public void run() {
/* Create an Intent that will start the Menu-Activity. */
Intent mainIntent = new Intent(Splash.this,Menu.class);
Splash.this.startActivity(mainIntent);
Splash.this.finish();
}
To
public void run() {
/* Create an Intent that will start the Menu-Activity. */
Intent mainIntent = new Intent(getApplicationContext(),Menu.class);
startActivity(mainIntent);
finish();
}
Now your code is clear, the error must come from the manifest file.
Go to the manifest file and change the position of the intent-filter from the Mainactivity to the slashscreen activity.
here the code :
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
My guess is that you have not changed the launcher activity in the manifest. Android looks in the AndroidManifest.xml to select the activity to start first. Your manifest probably contains these lines:
<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>
This should be changed to:
<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"/>
It is also a good convention to name activities XyzActivity, so in your case MenuActivity and SplashActivity.
/* New Handler to start the Menu-Activity
* and close this Splash-Screen after some seconds.*/
Thread timer = new Thread(){
public void run(){
try{
Thread.sleep(2000);
}
catch(InterruptedException e){
e.printStackTrace();
}
finally{
Intent mainIntent = new Intent(Splash.this,Menu.class);
startActivity(mainIntent );
finish();
}
}
};// end thread
timer.start();
use this code for the splash screen ...
public class SPLASH extends Activity {
protected boolean _active = true;
protected int _splashTime = 3000; // time to display the splash screen in MICROSECONDS
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
Thread splashTread = new Thread() {
#Override
public void run() {
try {
int waited = 0;
while (_active && (waited < _splashTime)) {
sleep(100);
if (_active) {
waited += 100;
}
}
} catch (Exception e) {
} finally {
startActivity(new Intent(Splash.this,Menu.class));
finish();
}
};
};
splashTread.start();
}
}
and make the Splash activity a launcher activity by using
<activity
android:name=".SPLASH"
android:label="#string/app_name"
android:theme="#style/NoActionBar"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Hope this will help u
Hey checkOut it i have improve little bit. thanks
public class Splash extends Activity {
private final int SPLASH_DISPLAY_LENGTH = 5000;
#Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.splashscreen);
nav();
}
public void nav() {
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
Intent mainIntent = new Intent(Splash.this,Menu.class);
startActivity(mainIntent);
finish();
}
}, SPLASH_DISPLAY_LENGTH);
}
#Override
protected void onPause() {
super.onPause();
finish();
}
}