-1

i'm a newwbie in java, and i want to add splash screen to a code. so i have created a layout XML named splash.xml :

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/splash" >

</RelativeLayout>

and i have created a java classe named splash.java :

package com.test.test;


import android.app.Activity;
import android.content.Intent;
import android.os.Handler;
import android.os.Bundle;
import android.view.Window;

import com.test.test.R;


public class Splash extends Activity {

private boolean backbtnPress;
private static final int SPLASH_DURATION = 3000;
private Handler myHandler;

@Override
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    getWindow().requestFeature(Window.FEATURE_ACTION_BAR);
    getActionBar().hide();

    setContentView(R.layout.splash);

    myHandler = new Handler();
    myHandler.postDelayed(new Runnable() {

        @Override
        public void run() {
            finish();

            if(!backbtnPress)
            {
                Intent intent = new Intent(Splash.this,MainActivity.class);
                Splash.this.startActivity(intent);
            }

        }
    }, SPLASH_DURATION);

}

@Override
public void onBackPressed() {
    // TODO Auto-generated method stub

    backbtnPress = true;
    super.onBackPressed();
}
}

but it does not work, when i run the app i find two app icons on device.

can you help me please

Thank you in advance!

Youness
  • 21
  • 4

3 Answers3

1

May be you have to intent filter in yout manifest.xml like this :

 <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
 </intent-filter>

edit it and set intent filter just for splash activity

FarshidABZ
  • 3,860
  • 4
  • 32
  • 63
0
<activity
    android:name=".Splash"
 >     
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />>     
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
< /activity>
loadjang
  • 327
  • 1
  • 3
  • Check my optimal and easy solution: https://medium.com/@vatani.ahmad/android-optimal-splash-screen-without-extra-activity-or-fragment-b60fea45a0cc – Ahmad Vatani May 01 '20 at 10:16
0

here is androidManifest

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

<uses-sdk
    android:minSdkVersion="11"
    android:targetSdkVersion="19" />

<uses-permission android:name="android.permission.KILL_BACKGROUND_PROCESSES" />
<uses-permission android:name="android.permission.CLEAR_APP_CACHE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/application_name"
    android:logo="@drawable/ic_launcher"
    android:theme="@style/Theme.Easyrambooster" >
    <activity
        android:name="com.test.test.MainActivity"
        android:label="@string/application_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

    <service android:name="com.test.test.QuickBoosterService" >
    </service>

        <activity
        android:name="com.test.test.Splash">
        <intent-filter>
        <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

    <meta-data
        android:name="com.google.android.gms.version"
        android:value="@integer/google_play_services_version" />

    <activity
        android:name="com.google.android.gms.ads.AdActivity"

android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" />

</manifest>
Youness
  • 21
  • 4