Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6542667
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:15:19+00:00 2026-05-25T11:15:19+00:00

I start studying this: Android SplashScreen and my app works perfectly with this method.

  • 0

I start studying this: Android SplashScreen
and my app works perfectly with this method.
Unfortunately, I’ve developed a custom splash screen (not a progress dialog like in the other post) and I’m not able to use the same approach. My splashscreen is a different activity that I starts calling it from the onCreate as a different thread.

Instead of this.pd = ProgressDialog.show(this, "Working..", "Downloading Data...", true, false); in the onCreate I do:

        Thread splashThread = new Thread() {
                @Override
                public void run() {
                     // start the splash screen activity
                }
        };
        splashThread.start();
 }

The splashscreeen activity correctly starts.
So I call the AsyncTask as in the default method (doInBackground, onPostExecute) and I’m not able to end the activity that is running the splashscreen and come back to the main one, after all the variables are loaded in the doInBackground.

Any suggestion?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T11:15:20+00:00Added an answer on May 25, 2026 at 11:15 am

    Well, I finally thank JPM for the suggestion to use handlers and I solved with that:

    public class SplashScreen extends Activity {
    
            private static Handler mHandler ;
            private static Handler mainHandler ;
    
            protected static final int CLOSE_SPLASH = 0 ;
    
            /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.splash_screen);
    
            mHandler = new Handler(){
                    @Override
                    public void handleMessage(Message msg){
                            switch(msg.what){
                            case CLOSE_SPLASH:
                            finish();
                            break;
                            }
    
                    }
            };
        }
    
        @Override
        public void onStart(){
            super.onStart();
            if(mainHandler != null){
                    mainHandler.sendEmptyMessage(MainActivity.START_LOAD);
            }
        }
    
        @Override
        public boolean onKeyDown (int keyCode, KeyEvent event){
            if(keyCode == KeyEvent.KEYCODE_BACK){
                    mainHandler.sendEmptyMessage(MainActivity.ABORT_LOAD);
            }
            return super.onKeyDown(keyCode, event) ;
        }
        public static void setMainHandler(Handler h){
            mainHandler = h ;
        }
        public static void sendMessage(Message msg){
            mHandler.sendMessage(msg);
        }
        public static void sendMessage(int w){
            mHandler.sendEmptyMessage(w);
        }
    }
    

    In the MainActivity I manage handlers back and forth:

    public class MainActivity extends Activity {
    
            private MainActivity _this;
            private Handler mHandler;
    
            protected static final int FINISH_LOAD = 0 ;
            protected static final int START_LOAD = 1 ;
            protected static final int ABORT_LOAD = 2 ;
    
            /** Called when the activity is first created. */
            @Override
            public void onCreate(Bundle savedInstanceState) {
                    super.onCreate(savedInstanceState);
    
                    _this = this;
    
                    mHandler = new Handler() {
                            @Override
                            public void handleMessage(Message msg) {
                                    switch (msg.what) {
                                    case FINISH_LOAD:
                                       SplashScreen.sendMessage(SplashScreen.CLOSE_SPLASH);
                                            break;
                                    case START_LOAD:
                                            initializing();
                                            break;
                                    case ABORT_LOAD:
                                            finish();
                                    }
    
                            }
                    };
                    startSplash();
            }
    
            private void startSplash() {
                    Intent intent = new Intent(this, SplashScreen.class);
                    SplashScreen.setMainHandler(mHandler);
                    startActivity(intent);
            }
    
            private void initializing() {
                    new Thread() {
                            @Override
                            public void run() {    
                                    long start_time = android.os.SystemClock.uptimeMillis();
                                    doTheHeavyJob();
                                    long duration = android.os.SystemClock.uptimeMillis() - start_time;
                                    if (duration <=3000) {
                                       try {
                                           wait(3000-duration);
                           } catch (InterruptedException e) {
                              e.printStackTrace();
                        }
                            }
                            mHandler.sendEmptyMessage(FINISH_LOAD);
                      }
                }.start();
            }    
    }
    

    In this manner I can manage the doTheHeavyJob() function and finish the SplashScreen in both cases: after the job finish and at least after 3000 millis, the minimum duration of my splashscreen to be shown.
    I also want to tank Teskio on the anddev italian website for the most of the job done here.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm really interested in speech-to-text algorithms, but I'm not sure where to start studying
I don't want to download Visual Studio 2010. How can I start studying (not
/* I start with this: */ <Report> <prop1>4</prop1> <prop2>2255</prop2> <prop3>true</prop3> <prop4>false</prop4> <prop5>true</prop5> </Report> /*
I've just start studying NHibernate 2 days ago, and I'm looking for a CRUD
Ok, lemme start out by saying Im new to this! LOL I have done
I'm studying MEF and I'm not able to resolve a problem. I have a
I've been studying from the book Pro Android 2. I'm working through a Service
I was studying some sample examples for Android and one of them got me
I start studying ANT today in order to make Java compiling easier. I wrote
I'm studying graph search algorithms (for this question sake, lets limit algorithms only on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.