1. Download our Official Android App: Forums for Android!

Help with splash screen

Discussion in 'Android Development' started by go6o78, Oct 10, 2017.

  1. go6o78

    go6o78 Lurker
    Thread Starter
    Rank:
    None
    Points:
    5
    Posts:
    7
    Joined:
    Sep 4, 2017

    Sep 4, 2017
    7
    0
    5
    Code (Text):
    1. package com.customlivewallpapercreator.live_wallpaper.amin;
    2.  
    3. import android.app.Activity;
    4. import android.content.Intent;
    5. import android.os.Bundle;
    6. import android.os.Handler;
    7.  
    8. public class SplashScreen extends Activity {
    9.  
    10.    // Splash screen timer
    11.    private static int SPLASH_TIME_OUT = 3000;
    12.  
    13.    @Override
    14.    protected void onCreate(Bundle savedInstanceState) {
    15.        super.onCreate(savedInstanceState);
    16.        setContentView(R.layout.activity_splash); - РЕДА С ГРЕШКАТА
    17.  
    18.        new Handler().postDelayed(new Runnable() {
    19.  
    20.            /*
    21.             * Showing splash screen with a timer. This will be useful when you
    22.             * want to show case your app logo / company
    23.             */
    24.  
    25.            @Override
    26.            public void run() {
    27.                // This method will be executed once the timer is over
    28.                // Start your app main activity
    29.                Intent i = new Intent(SplashScreen.this, MainActivity.class);
    30.                startActivity(i);
    31.  
    32.                // close this activity
    33.                finish();
    34.            }
    35.        }, SPLASH_TIME_OUT);
    36.    }
    37.  
    38. }
    Hello
    i try to add splash screen in my project and insert some admob ad code
    but i have some error
    here is my project
    https://drive.google.com/open?id=0B2u6yCWB2rETMjJhNXpOSEswNXc
    For splash screen i try this code
    https://www.androidhive.info/2013/07/how-to-implement-android-splash-screen-2/
    and few more but all of them give me some error
    this source
    https://www.androidhive.info/2013/07/how-to-implement-android-splash-screen-2/
    give me this errors .
    Can somebody help me
    Error:(16, 32) error: cannot find symbol variable activity_splash
    Error:Execution failed for task ':livewallpaper:compileDebugJavaWithJavac'.
    > Compilation failed; see the compiler error output for details.

    package com.customlivewallpapercreator.live_wallpaper.amin;

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

    public class SplashScreen extends Activity {

    // Splash screen timer
    private static int SPLASH_TIME_OUT = 3000;

    @override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_splash); **- --- the error**

    new Handler().postDelayed(new Runnable() {

    /*
    * Showing splash screen with a timer. This will be useful when you
    * want to show case your app logo / company
    */

    @override
    public void run() {
    // This method will be executed once the timer is over
    // Start your app main activity
    Intent i = new Intent(SplashScreen.this, MainActivity.class);
    startActivity(i);

    // close this activity
    finish();
    }
    }, SPLASH_TIME_OUT);
    }

    }
     

    Advertisement

  2. LV426

    LV426 I say we take off and nuke this place from orbit
    Moderator
    Rank:
     #11
    Points:
    1,988
    Posts:
    7,462
    Joined:
    Oct 16, 2015

    Oct 16, 2015
    7,462
    10,750
    1,988
    Male
    Software developer
    South West of England
    Looks like you haven't defined a layout with id "activity_splash".
    You need to create and build a corresponding layout for your Activity, using XML.
     
    scary alien likes this.
  3. go6o78

    go6o78 Lurker
    Thread Starter
    Rank:
    None
    Points:
    5
    Posts:
    7
    Joined:
    Sep 4, 2017

    Sep 4, 2017
    7
    0
    5
    i have activity_splash_screen.xml
    try this also
    setContentView(R.layout.activity_splash_screen);
    Code (Text):
    1. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    2.     xmlns:tools="http://schemas.android.com/tools"
    3.     android:layout_height="match_parent"
    4.     android:layout_width="match_parent"
    5.       tools:context=".MainActivity">
    6.  
    7.  
    8.     <com.google.android.gms.ads.AdView
    9.         xmlns:ads="http://schemas.android.com/apk/res-auto"
    10.         android:id="@+id/adView"
    11.         android:layout_width="wrap_content"
    12.         android:layout_height="wrap_content"
    13.         android:layout_centerHorizontal="true"
    14.         android:layout_alignParentBottom="true"
    15.         ads:adSize="BANNER"
    16.         ads:adUnitId="ca-app-pub-3940256099942544/6300978111">
    17.     </com.google.android.gms.ads.AdView>
    18.  
    19. </RelativeLayout>
     
  4. go6o78

    go6o78 Lurker
    Thread Starter
    Rank:
    None
    Points:
    5
    Posts:
    7
    Joined:
    Sep 4, 2017

    Sep 4, 2017
    7
    0
    5
    and now this code is working :)
    setContentView(R.layout.activity_splash_screen);
    before give me error :)

    i can make a build but app is crashing
     
    #4 go6o78, Oct 10, 2017
    Last edited: Oct 10, 2017
  5. LV426

    LV426 I say we take off and nuke this place from orbit
    Moderator
    Rank:
     #11
    Points:
    1,988
    Posts:
    7,462
    Joined:
    Oct 16, 2015

    Oct 16, 2015
    7,462
    10,750
    1,988
    Male
    Software developer
    South West of England
    Yup, it'll work when you use the correct layout id ;)
     
  6. go6o78

    go6o78 Lurker
    Thread Starter
    Rank:
    None
    Points:
    5
    Posts:
    7
    Joined:
    Sep 4, 2017

    Sep 4, 2017
    7
    0
    5
    yes but app is crashing :) on my phone
    in debug give me this
    Error running SplashScreen: The activity must be exported or contain an intent-filter
     
  7. LV426

    LV426 I say we take off and nuke this place from orbit
    Moderator
    Rank:
     #11
    Points:
    1,988
    Posts:
    7,462
    Joined:
    Oct 16, 2015

    Oct 16, 2015
    7,462
    10,750
    1,988
    Male
    Software developer
    South West of England
  8. go6o78

    go6o78 Lurker
    Thread Starter
    Rank:
    None
    Points:
    5
    Posts:
    7
    Joined:
    Sep 4, 2017

    Sep 4, 2017
    7
    0
    5
    Code (Text):
    1. <?xml version="1.0" encoding="utf-8"?>
    2. <manifest xmlns:android="http://schemas.android.com/apk/res/android"
    3.     package="com.customlivewallpapercreator.live_wallpaper.amin"
    4.     android:versionCode="100"
    5.     android:versionName="1.00">
    6.  
    7.     <uses-sdk
    8.         android:minSdkVersion="19"
    9.         android:targetSdkVersion="19" />
    10.  
    11.     <uses-feature android:name="android.software.live_wallpaper" />
    12.  
    13.     <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    14.     <uses-permission android:name="android.permission.READ_PHONE_STATE" />
    15.     <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    16.  
    17.     <application
    18.         android:allowBackup="true"
    19.         android:icon="@drawable/icon"
    20.         android:label="@string/appName"
    21.         android:largeHeap="true">
    22.  
    23.         <!-- Wallpaper Service -->
    24.         <service
    25.             android:name=".CustomWallpaper"
    26.             android:label="@string/appName"
    27.             android:permission="android.permission.BIND_WALLPAPER">
    28.             <intent-filter>
    29.                 <action android:name="android.service.wallpaper.WallpaperService" />
    30.             </intent-filter>
    31.  
    32.             <meta-data
    33.                 android:name="android.service.wallpaper"
    34.                 android:resource="@xml/wallpaper" />
    35.         </service>
    36.         <!-- Splash screen -->
    37.         <activity
    38.             android:name="info.androidhive.androidsplashscreentimer.SplashScreen"
    39.                        android:screenOrientation="portrait"
    40.             android:theme="@android:style/Theme.Black.NoTitleBar" >
    41.             <intent-filter>
    42.                 <action android:name="android.intent.action.MAIN" />
    43.  
    44.                 <category android:name="android.intent.category.LAUNCHER" />
    45.             </intent-filter>
    46.         </activity>
    47.         <activity android:name=".MainActivity" />
    48.         <activity android:name=".SplashScreen"></activity>
    49.         <activity
    50.             android:name="info.androidhive.androidsplashscreentimer.MainActivity">
    51.         </activity>
    52.  
    53.               <!-- Splash screen -->
    54.         <activity
    55.             android:name="info.androidhive.androidsplashscreentimer.SplashScreen"
    56.             android:screenOrientation="portrait"
    57.             android:theme="@android:style/Theme.Black.NoTitleBar" >
    58.             <intent-filter>
    59.                 <action android:name="android.intent.action.MAIN" />
    60.  
    61.                 <category android:name="android.intent.category.LAUNCHER" />
    62.             </intent-filter>
    63.         </activity>
    64.  
    65.         <!-- Main activity -->
    66.         <activity
    67.             android:name="info.androidhive.androidsplashscreentimer.MainActivity">
    68.         </activity>
    69.     </application>
    70.  
    71. </manifest>
     
  9. LV426

    LV426 I say we take off and nuke this place from orbit
    Moderator
    Rank:
     #11
    Points:
    1,988
    Posts:
    7,462
    Joined:
    Oct 16, 2015

    Oct 16, 2015
    7,462
    10,750
    1,988
    Male
    Software developer
    South West of England
    I think you modified a project and forgot to change the package name in the Manifest. In the code, your Activity SplashScreen is declared in package

    Code (Text):
    1.  
    2. package com.customlivewallpapercreator.live_wallpaper.amin;
    3.  
    But your Manifest refers to a different package

    Code (Text):
    1.  
    2. android:name="info.androidhive.androidsplashscreentimer.SplashScreen"
    3.  
     
  10. go6o78

    go6o78 Lurker
    Thread Starter
    Rank:
    None
    Points:
    5
    Posts:
    7
    Joined:
    Sep 4, 2017

    Sep 4, 2017
    7
    0
    5
    i want to add the splash screen before my app
    first i made the project and its working ok. After i add splash screen the project crash
    Now i saw the Manifest has some changes.
    Can you tell me what exactly i must edit
    I'm not a programer :)
     

Share This Page

Loading...