Click here to Skip to main content
13,664,232 members
Rate this:
 
Please Sign up or sign in to vote.
Hello Guys, I want to know how can I open my fragment activity after splash screen activity and in my splash screen I am using animation in my splash screen please help me how can I open it.
Thanks in Advance.

What I have tried:

package com.complainprotectioncell;

import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
public class SplashScreen extends AppCompatActivity {
    public MediaPlayer mp;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
       try {
//           getSupportActionBar().hide();
//           requestWindowFeature(Window.FEATURE_NO_TITLE);
//           getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
//                   WindowManager.LayoutParams.FLAG_FULLSCREEN);
           setContentView(R.layout.front_splash_screen);
           mp = MediaPlayer.create(this, R.raw.bgr_be_happy);
           mp.start();

           startAnimation();
       }catch(Exception ex)
       {
           Log.e("Exception" , "Found 1" + ex);
       }
    }

    public void startAnimation()
    {
try {
    final ImageView imageView = (ImageView) findViewById(R.id.imageView);
    final Animation animation_1 = AnimationUtils.loadAnimation(getBaseContext(), R.anim.rotate);
    final Animation animation_2 = AnimationUtils.loadAnimation(getBaseContext(), R.anim.antirotate);
    final Animation animation_3 = AnimationUtils.loadAnimation(getBaseContext(), R.anim.abc_fade_out);

    imageView.startAnimation(animation_2);
    animation_2.setAnimationListener(new Animation.AnimationListener() {
        @Override
        public void onAnimationStart(Animation animation) {

        }

        @Override
        public void onAnimationEnd(Animation animation) {
            imageView.startAnimation(animation_1);
        }

        @Override
        public void onAnimationRepeat(Animation animation) {

        }
    });

    animation_1.setAnimationListener(new Animation.AnimationListener() {
        @Override
        public void onAnimationStart(Animation animation) {

        }

        @Override
        public void onAnimationEnd(Animation animation) {
            try {
                startActivity(new Intent(getApplicationContext(), Login.class));
                finish();
                //imageView.startAnimation(animation_3);
                //mp.release();
            } catch (Exception ex) {
                Log.e("Exception Splash", ex + "");
//                    Toast.makeText(SplashScreen.this, "Sorry, Something went Wrong", Toast.LENGTH_SHORT).show();
            }
        }

        @Override
        public void onAnimationRepeat(Animation animation) {

        }
    });
}catch(Exception ex)
{
    Log.e("Exception" , "Found 2");
}
    }

    @Override
    protected void onStop() {
        super.onStop();
        try {
            if (mp != null && mp.isPlaying()) {
                mp.stop();
                mp.release();
                mp = null;
            }
        }catch(Exception ex)
        {
            Log.e("Exception Found", ex + "");
        }
    }
}
Posted 12-Jan-18 9:06am
Updated 12-Jan-18 15:15pm
v2

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

I took a far different approach with a splash screen for one of my apps because it should be ready immediately, even before a layout is inflated. So instead of using a layout, I specified the splash screen's background as the activity's theme background.

So, I changed the main activity to be SplashActivity in the AndroidManifest.xml file, like:
<activity
    android:name=".MainActivity"
    android:label="@string/app_name"
    android:theme="@style/AppTheme.NoActionBar">
</activity>

<activity
    android:name=".SplashActivity"
    android:theme="@style/SplashTheme" >
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />

        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>
The background/theme for the SplashActivity looks like:
<style name="SplashTheme" parent="Theme.AppCompat.NoActionBar">
    <item name="android:windowBackground">@drawable/background_splash</item>
</style>
...
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:drawable="@color/gray"/>

    <item>
        <bitmap android:gravity="center" android:src="@mipmap/ic_launcher"/>
    </item>

</layer-list>
The SplashActivity class then looks like:
public class SplashActivity extends AppCompatActivity
{
    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);

        Intent intent = new Intent(this, MainActivity.class);
        startActivity(intent);
        finish();
    }
}
Then in MainActivity, do whatever you want as normal. May not be exactly what you are looking for, but it is the way Google is doing this now, too.
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Cookies | Terms of Service
Web01-2016 | 2.8.180810.1 | Last Updated 12 Jan 2018
Copyright © CodeProject, 1999-2018
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100