I have implemented a Splash Screen on an android app I am building using Android Studio and I would like to add a spinner to the splash screen. Can anyone give me a hand on this:
Here is the code on my splashScreen.java Class:
package com.packagename.appname;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Window;
/**
* Created by VAIO1 on 05/09/2014.
*/
public class splashScreen extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.splash);
Thread logoTimer = new Thread() {
public void run() {
try {
sleep(3000);
Intent splashIntent = new Intent("com.packagename.appname.SPLASH");
startActivity(splashIntent);
} catch (InterruptedException e) {
e.printStackTrace();
} finally {
finish();
}
}
};
logoTimer.start();
}
#Override
protected void onPause() {
super.onPause();
}
}
Here is the code for my splash.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:id="#+id/splashId">
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center"
android:src="#drawable/screen"
android:cropToPadding="false"
android:scaleType="fitXY"/>
</LinearLayout>
Thank you for any feedback on how to achieve this.
use this code :-
public class splashScreen extends Activity {
ProgressDialog progressDialog;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.splash);
Thread logoTimer = new Thread() {
public void run() {
try {
sleep(3000);
progressDialog = new ProgressDialog(Sync_Screen_activity.this);
progressDialog.setMessage("Wait..");
progressDialog.setCancelable(false);
progressDialog.show();
} catch (InterruptedException e) {
e.printStackTrace();
} finally {
Intent splashIntent = new Intent("com.packagename.appname.SPLASH");
startActivity(splashIntent);
finish();
}
}
};
logoTimer.start();
}
#Override
protected void onPause() {
super.onPause();
}
}
Related
I'm in need of help, I'd like to display an interstitial add after the splash screen screen loads, but my code has an error.
Here is my code:
public class SplashScreenActivity extends AppCompatActivity {
InterstitialAd mInterstitialAd;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash_screen);
// FIREBASE INTERSTICIAL
mInterstitialAd = new InterstitialAd(this);
mInterstitialAd.setAdUnitId("ca-app-pub-2565065222479596/3931476543");
mInterstitialAd.setAdListener(new AdListener() {
#Override
public void onAdClosed() {
requestNewInterstitial();
}
});
requestNewInterstitial();
Toast.makeText(this,"* Necessário Acesso a Internet *",Toast.LENGTH_LONG).show();
Thread timerThread = new Thread() {
public void run() {
try {
sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
} finally {
if (mInterstitialAd.isLoaded()) {
mInterstitialAd.show();
Intent intent = new Intent(SplashScreenActivity.this, MainActivity.class);
startActivity(intent);
}
else
{
Intent intent = new Intent(SplashScreenActivity.this, MainActivity.class);
}
}
}
};
timerThread.start();
}
// FIREBASE INTERSTICIAL
private void requestNewInterstitial() {
AdRequest adRequest = new AdRequest.Builder()
.addTestDevice("SEE_YOUR_LOGCAT_TO_GET_YOUR_DEVICE_ID")
.build();
mInterstitialAd.loadAd(adRequest);
}
}
after debugging the following is informed:
01-22 16:27:03.048 13840-13970/? E/AndroidRuntime: FATAL EXCEPTION: Thread-6
Process: idea.tisco.pepavideos, PID: 13840
java.lang.IllegalStateException: isLoaded must be called on the main UI thread.
at oc.b(:com.google.android.gms.DynamiteModulesA#11951448:20)
at com.google.android.gms.ads.internal.a.d(:com.google.android.gms.DynamiteModulesA#11951448:98)
at com.google.android.gms.ads.internal.client.ak.onTransact(:com.google.android.gms.DynamiteModulesA#11951448:14)
at android.os.Binder.transact(Binder.java:499)
at com.google.android.gms.internal.zzep$zza$zza.isReady(Unknown Source)
at com.google.android.gms.internal.zzfa.isLoaded(Unknown Source)
at com.google.android.gms.ads.InterstitialAd.isLoaded(Unknown Source)
at company.ts.SplashScreenActivity$2.run(SplashScreenActivity.java:50)
Even after the debug I could not understand the reason for the error.
I would like to just display an interstitial just after the splash screen or when I open the mainactivity.
Thank you so much!
the problem is herejava.lang.IllegalStateException: isLoaded must be called on the main UI thread.
so may have to do this
runOnUiThread(new Runnable() {
#Override public void run() {
if (mInterstitialAd.isLoaded()) {
mInterstitialAd.show();
}
}
});
Possibly You have to call it with an activity reference, it depends from where Do You call
mYourActivity.runOnUiThread(new Runnable() {
#Override public void run() {
if (mInterstitialAd.isLoaded()) {
mInterstitialAd.show();
}
}
});
Source:AdMob Interstitial and error isLoaded must be called on the main UI thread
Facebook Interstitial Ads on Splash Screen.
Build.Gradle :
implementation 'com.facebook.android:audience-network-sdk:5.+'
implementation 'com.victor:lib:1.0.4'
MyAplication.java:
AudienceNetworkAds.initialize(this);
Manifest.xml:
<activity
android:name="com.facebook.ads.AudienceNetworkActivity"
android:configChanges="keyboardHidden|orientation|screenSize" />
Permission:
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
activity_splash.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/holo_blue_light"
tools:context=".SplashActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:textColor="#android:color/background_light"
android:text="Splash Screen"
android:textSize="25sp"
android:layout_marginTop="20dp"
android:textStyle="bold"/>
<TextView
android:id="#+id/loadingTxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:text="Loading Ad..."
android:layout_centerHorizontal="true"
android:layout_marginBottom="15dp"
android:textColor="#android:color/holo_red_dark"/>
<com.victor.loading.rotate.RotateLoading
android:id="#+id/rotateloading"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_above="#+id/loadingTxt"
app:loading_color="#android:color/holo_red_dark"
android:layout_centerHorizontal="true"
app:loading_speed="11"
app:loading_width="5dp" />
</RelativeLayout>
SplashActivity.java
import androidx.appcompat.app.AppCompatActivity;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.view.WindowManager;
import android.widget.TextView;
import com.facebook.ads.Ad;
import com.facebook.ads.AdError;
import com.facebook.ads.InterstitialAd;
import com.facebook.ads.InterstitialAdListener;
import com.victor.loading.rotate.RotateLoading;
import java.lang.ref.WeakReference;
public class SplashActivity extends AppCompatActivity {
private Handler handler;
private SplashThread splashThread;
private InterstitialAd facebookInterstitialAd;
private boolean isAdsLoad=false;
private TextView loadingTxt;
private RotateLoading rotateloading;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//full screen
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_splash);
loadingTxt=(TextView)findViewById(R.id.loadingTxt);
rotateloading=(RotateLoading)findViewById(R.id.rotateloading);
if (isNetworkAvailable(this)){
//if on then load ads
rotateloading.start();
handler=new Handler();
splashThread=new SplashThread(this);
handler.postDelayed(splashThread,5000); //5 second delay otherwise ads not show it take some time to load
loadFaceBookAds();
}
else{
//if network off then show simple splash screen
rotateloading.setVisibility(View.GONE);
loadingTxt.setVisibility(View.GONE);
handler=new Handler();
splashThread=new SplashThread(this);
handler.postDelayed(splashThread,2000); //2 second delay for simple splash
}
}
public static boolean isNetworkAvailable(Context context) {
ConnectivityManager connectivity = (ConnectivityManager) context
.getSystemService(Context.CONNECTIVITY_SERVICE);
if (null != connectivity) {
NetworkInfo info = connectivity.getActiveNetworkInfo();
if (null != info && info.isConnected()) {
if (info.getState() == NetworkInfo.State.CONNECTED) {
return true;
}
}
}
return false;
}
private void loadFaceBookAds(){
facebookInterstitialAd=new InterstitialAd(this,"Facebook_Interstitial_Ads_ID");
facebookInterstitialAd.setAdListener(new InterstitialAdListener() {
#Override
public void onInterstitialDisplayed(Ad ad) {
}
#Override
public void onInterstitialDismissed(Ad ad) {
//on dismiss ads call next activity
finish();
startActivity(new Intent(SplashActivity.this,MainActivity.class));
}
#Override
public void onError(Ad ad, AdError adError) {
}
#Override
public void onAdLoaded(Ad ad) {
//if ads load then show it.
isAdsLoad=true;
rotateloading.stop();
rotateloading.setVisibility(View.GONE);
loadingTxt.setVisibility(View.GONE);
facebookInterstitialAd.show();
}
#Override
public void onAdClicked(Ad ad) {
}
#Override
public void onLoggingImpression(Ad ad) {
}
});
facebookInterstitialAd.loadAd();
}
static class SplashThread implements Runnable{
//Handle memory leakage..
WeakReference<SplashActivity> weakReference;
SplashThread(SplashActivity splashActivity){
weakReference=new WeakReference<>(splashActivity);
}
#Override
public void run() {
SplashActivity mContext=weakReference.get();
if (mContext==null)
return;
if (mContext.isFinishing())
return;
//if ads loaded no need to call next activity here.
if (!mContext.isAdsLoad) {
if (mContext.rotateloading.getVisibility()==View.VISIBLE) {
mContext.rotateloading.stop();
mContext.rotateloading.setVisibility(View.GONE);
}
mContext.finish();
mContext.startActivity(new Intent(mContext, MainActivity.class));
}
}
}
#Override
protected void onDestroy() {
super.onDestroy();
handler.removeCallbacks(splashThread);
if (facebookInterstitialAd!=null)
facebookInterstitialAd.destroy();
}
}
This is the simplest method ever existed on the internet.
add bellow code in your onCreate method of Splash activity.
InterstitialAd ad;
ad = new InterstitialAd(this);
ad.setAdUnitId(getString(R.string.interstitial));
ad.loadAd(new AdRequest.Builder().build());
ad.setAdListener(new AdListener(){
#Override
public void onAdClosed() {
super.onAdClosed();
startActivity(new Intent(getApplicationContext(), PermissionsActivity.class));
finish();
}
});
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
if(ad.isLoaded()) {
ad.show();
}
else{
startActivity(new Intent(getApplicationContext(), PermissionsActivity.class));
finish();
}
}
}, 4000);
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;
public class Second extends AppCompatActivity {
TextView t1;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);
t1 = (TextView)findViewById(R.id.textView);
Bundle b = getIntent().getExtras();
String S = b.getString("key1");
t1.setText(S);
try {
wait(3000);
} catch (InterruptedException e) {
e.printStackTrace();
}
Intent i2 = new Intent();
i2.putExtra("reply","Everything is cool");
setResult(RESULT_OK,i2);
finish();
}
}
This is my second Activity code. Actually, I was seeing how intent works by implementing a very basic program. Program is working without wait, but the app is crashing if I put wait function. provide me some way so that i can stay on to the second activity for a longer time before sending back the r
Use Handler and try to start Intent from run() You can check below example,
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
#Override
public void run() {
Intent i2 = new Intent();
i2.putExtra("reply","Everything is cool");
setResult(RESULT_OK,i2);
finish();
}
}, 3000);
you can use service or acyncTask instead of
try {
wait(3000);
} catch (InterruptedException e) {
e.printStackTrace();
}
You could try this code
public void onclick(View v) {
mt = new MyTask();
mt.execute();
}
class MyTask extends AsyncTask<Void, Void, Void> {
#Override
protected void onPreExecute() {
super.onPreExecute();
}
#Override
protected Void doInBackground(Void... params) {
try {
TimeUnit.SECONDS.sleep(2);
} catch (InterruptedException e) {
e.printStackTrace();
}
return null;
}
#Override
protected void onPostExecute(Void result) {
super.onPostExecute(result);
}
}
Hope it will be helpful.
This code is homepage of my app. For this app i want to create splash .
main app code:-
package com.Wase.edittext;
import java.util.Timer;
import java.util.TimerTask;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.text.format.Time;
import android.widget.EditText;
public class Splash extends Activity {
Timer timer = new Timer();
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash_logo);
Time.schedule(new TimerTask() {
public void run() {
Intent intent = new Intent(Splash.this, MyAndroidAppActivity.class);
startActivity(intent);
finish();
}
}, 5000);
}
}
This my code for splash.. please see the mistake amd tell me ..
First of all create one new XML file and use whatever design you want and after that create activity (java) file and use below code and change your screen and variable name as per your requirement.
public class Splash extends Activity {
Timer timer = new Timer();
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
timer.schedule(new TimerTask() {
public void run() {
Intent intent = new Intent(Splash.this, MyAndroidAppActivity.class);
startActivity(intent);
finish();
}
}, 5000);
}
}
and this is your splash.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/splash"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFFFFF"
tools:context=".IMyCompany" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="153dp"
android:src="#drawable/logo" />
</RelativeLayout>
it will move to new activity after 5 seconds.
public class SplashScreen extends Activity {
public SplashScreen instance;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.xml_splashscreen);
if (instance != null) {
instance.finish();
}
instance = this;
Thread threadMenu = new Thread(new Runnable() {
public void run() {
try {
// sleep 3 second and go next page
Thread.sleep(400);
// Check Vefication Success then Load HomeScreen Check
Intent splash = new Intent(getBaseContext(),
MyAndroidAppActivity .class);
startActivity(splash);
finish();
overridePendingTransition(R.anim.push_in_from_left,
R.anim.push_out_to_right);
}
} catch (InterruptedException e) {
e.printStackTrace();
}
}
});
threadMenu.start();
}
}
in manifest file :
<activity
android:name="com.demo.SplashScreen"
android:label="#string/app_name"
android:screenOrientation="sensorPortait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".com.demo.MyAndroidAppActivity"
android:configChanges="keyboardHidden"
android:screenOrientation="sensorPortait"
android:windowSoftInputMode="stateHidden" />
use this code
====
public class SplashScreenActivity extends Activity {
final int splashTimeOut = 3000;
ImageView imgSplash;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splashscreen);
imgSplash = (ImageView) findViewById(R.id.imgsplash);
setContentBasedOnLayout();
// TODO Auto-generated method stub
Thread splashThread = new Thread() {
int wait = 0;
#Override
public void run() {
try {
super.run();
while (wait < splashTimeOut) {
sleep(100);
wait += 100;
}
} catch (Exception e) {
e.printStackTrace();
} finally {
//If You Want To Do Something Write Here Your Code
}
}
};
splashThread.start();
}
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
return true;
}
return super.onKeyDown(keyCode, event);
}
}
I want to show a "boot logo" or image before of setting the final layout of the main activity. Actually i do this:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.authors);
mContext = this;
showAuthors();
where showAuthors run this:
private void showAuthors()
{
setContentView(R.layout.authors);
Thread logoTimer = new Thread() {
public void run() {
try {
sleep(3000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
}
}
};
logoTimer.start();
try {
logoTimer.join();
setContentView(R.layout.activity_main);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
the file authors.xml ( R.layout.authors ) is the same of activity_main, but clean, containing just a pair of strings with my name and email:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:background="#raw/call2"
android:src="#raw/call2"
android:scaleType = "centerCrop"
tools:context=".MainActivity" >
<TextView
android:id="#+id/authorsTV"
android:textColor="#FF6600"
android:textSize="16.5sp"
android:textStyle="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginLeft="33dp"
android:text="#string/serviceStatus" />
</RelativeLayout>
the problem is: all works, but the screen is all white as an empty layout.
where i'm doing wrong? thank you all if consider to reply me!
You should not call thread.join from the main thread, because you can get an ANR crash.
Here's how to do it with minimal changes to your existing code. Remove everything after logoTimer.start(), and put this inside the try block, immediately after sleep(3000):
runOnUiThread(new Runnable(){
public void run(){
setContentView(R.layout.activity_main);
}
});
But it would be cleaner to rewrite that whole method like this:
private void showAuthors()
{
setContentView(R.layout.authors);
new Handler().postDelayed( new Runnable(){
public void run(){
setContentView(R.layout.activity_main);
}
}, 3000);
}
First you have two ways of showing a splash screen,
1.with activity
public class SplashActivity extends Activity implements Runnable
{
#Override
protected void onCreate(Bundle savedInstanceState)
{
...
setContentView(R.layout.act_spalsh);
hideSplashActivity();
}
private void hideSplashActivity()
{
new Handler().postDelayed(this, 3000);
}
#Override //from runnable
public void run()
{
startActivity(new Intent(this, MainActivity .class));
finish();
}
2.with dialog
public class MainActivity extends Activity implements Runnable
{
Dialog splashDialog;
#Override
protected void onCreate(Bundle savedInstanceState)
{
...
splashDialog = new Dialog(this,android.R.style.Theme_Black_NoTitleBar_Fullscreen);
splashDialog.setContentView(R.layout.dlg_splash);
splashDialog.show();
hideSplashDialog();
setContentView(R.layout.act_main);
}
private void hideSplashDialog()
{
new Handler().postDelayed(this, 3000);
}
#Override //from runnable
public void run()
{
splashDialog.dismiss();
splashDialog = null;
}
I prefer using dialog unless you have some trouble with that
I want to write a code that uses the splash screen .I have written this so far, but Can anyone tell me what is the missing here!?
here is my main code:
package com.example.splash;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.util.Log;
import android.view.Menu;
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
and here is my splash activity code:
package com.example.splash;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
public class splashscreen extends Activity {
protected int _splashTime = 5000;
private Thread splashTread;
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.splashh);
final splashscreen sPlashScreen = this;
splashTread = new Thread() {
#Override
public void run() {
try {
synchronized(this){
wait(_splashTime);
}
} catch(InterruptedException e) {}
finally {
finish();
Intent i = new Intent();
i.setClass(sPlashScreen,MainActivity.class);
startActivity(i);
//stop();
}
}
};
splashTread.start();
}
The problem is I do not know how to tell my main to go splash activity , if I use an intent I would stuck on infinite loop.
You can simply use this:
Handler handler=new Handler();
handler.postDelayed(new Runnable()
{
#Override
public void run()
{
Intent intent = new Intent(SplashViewController.this,HomeViewController.class);
startActivity(intent);
SplashViewController.this.finish();
}
}, 3000);
try this instead :
public class splashscreen extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_splash);
Thread t = new Thread(Splash_Runnable);
t.start();
}
Runnable Splash_Runnable = new Runnable() {
#Override
public void run() {
try {
Thread.sleep(3000);
startActivity(new Intent(splashscreen.this,
MainActivity.class));
splashscreen.this.finish();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
};
}
The problem (i guess) is that your app is starting with your MainActivity as your launcher Activity. Make splashscreen your laucher Activity in your Application Manifest XML and you will avoid the infinite loop.
Try this code:
private boolean _active = true;
private int _splashTime = 5000;
Thread splashTread = new Thread()
{
#Override
public void run()
{
try
{
int waited = 0;
while(_active && (waited < _splashTime))
{
sleep(100);
if(_active)
{
waited += 100;
}
}
}
catch(InterruptedException e)
{
e.printStackTrace();
}
finally
{
Intent intent = new Intent(SplashScreenActivity.this,MainActivity.class);
startActivity(intent);
finish();
}
};
splashTread.start();
in AndroidManifest mention your activity as Main Activity.
Try to change your SplashActivity code from here.
Splash and main activity error
Also make your splashactivtiy as your launcher activity and then redirect to the MainActivity from the SplashScreen
<activity
android:name="com.app.wablogic.SplashActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</intent-filter>
</activity>
Full detail of creating a splash Activity
Create a layout for Splash
splash.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#drawable/splash" >
</LinearLayout>
Now create a class Under package . Name it Splash
public class Splash extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
#Override
public void run() {
Intent openMainActivity = new Intent(Splash.this, MainActivity.class);
startActivity(openMainActivity);
finish();
}
}, 5000); //it will call the MainActivity after 5 seconds
}
Go to manifest and add the Activity to it.
and cut the intent-filter where main and Launcher are child and paste it in Splash Activity like
<activity
android:name="com.example.yourpackage.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>
You can create a Thread for doing something or just sleep for a few seconds to do, such as
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Thread background = new Thread() {
public void run() {
try {
// Thread will sleep for 3 seconds
sleep(3*1000);
// After 3 seconds redirect to another intent
Intent i=new Intent(getBaseContext(),MenuActivity.class);
startActivity(i);
//Remove activity
finish();
} catch (Exception e) {
}
}
};
background.start();
}
#Override
protected void onDestroy() {
super.onDestroy();
}
You can get more example here.