Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Load MainActivity during Splash Screen

I currently have a splashScreenActivity that requires the User the press on a button to go to the MainActivity.

Would it be possible to load all the contents of MainActivity WITHOUT MainActivity's UI APPEARING ON TOP OF splashScreenActivity's UI so that when he does presses the button, he is redirected to the MainActivity and all the data is 100% loaded?

Thanks in advance

like image 446
DanielRM Avatar asked Dec 08 '22 18:12

DanielRM


2 Answers

I found an answer to my problem!

Note that in my case MainActivity can be any activity

Having a Splash Screen as a fragment instead of an activity allows you to overlay the MainActivity with the fragment, while the MainActivity data loads in the background.

At this point, whenever you are ready, simply set the visibility of the fragment to View.GONE or pop it off the fragment stack getFragmentManager().popBackStack();, and you will return (never really left) to your MainActivity with all the data loaded.

like image 112
DanielRM Avatar answered Dec 10 '22 12:12

DanielRM


Use Full Screen Dialog With Runnable on Main Activity

public void showsplash() {

        final Dialog dialog = new Dialog(MainActivity.this, android.R.style.Theme_Black_NoTitleBar_Fullscreen);
        dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
        dialog.setContentView(R.layout.activity_splash_screen);
        dialog.setCancelable(true);
        dialog.show();

        final Handler handler  = new Handler();
        final Runnable runnable = new Runnable() {
            @Override
            public void run() {
                {
                    dialog.dismiss();
                }
            }
        };
        handler.postDelayed(runnable, 30000);
    }
like image 34
Tarun Valecha Avatar answered Dec 10 '22 11:12

Tarun Valecha