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 9193175
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T21:05:54+00:00 2026-06-17T21:05:54+00:00

I want to stop a running thread while click on the splash screen, if

  • 0

I want to stop a running thread while click on the splash screen, if I don’t click on screen, after the thread execution, it will launch another Activity. But getting UnSupportedException, how do I solve it?

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_splash);
    iImage = (ImageView) findViewById(R.id.iIcon);
    splashImage = (ImageView) findViewById(R.id.splash_image);

    iImage.setOnClickListener(this);
    splashImage.setOnClickListener(this);
}

@Override
protected void onStart() {
    super.onStart();
    splashTimer = new Thread(new Runnable() {
        @Override
        public void run() {
            try {
                Thread.sleep(5000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            startActivity(new Intent(SplashActivity.this, LoginAuthenticationActivity.class));
            finish();
        }
    });
    splashTimer.start();
}

@Override
public void onClick(View view) {
    if(splashTimer.isAlive())
        splashTimer.stop();
    switch (view.getId()) {
        case R.id.iIcon:
            startActivity(new Intent(this, AboutUsActivity.class));
            break;
        case R.id.splash_image:
            startActivity(new Intent(this, LoginAuthenticationActivity.class));
            break;
        default:
            break;
    }
    finish();
}

Log:

01-27 03:27:01.189: W/dalvikvm(1080): threadid=1: thread exiting with uncaught exception (group=0x409c01f8)
01-27 03:27:01.209: E/AndroidRuntime(1080): FATAL EXCEPTION: main
01-27 03:27:01.209: E/AndroidRuntime(1080): java.lang.UnsupportedOperationException
01-27 03:27:01.209: E/AndroidRuntime(1080):     at java.lang.Thread.stop(Thread.java:1076)
01-27 03:27:01.209: E/AndroidRuntime(1080):     at java.lang.Thread.stop(Thread.java:1063)
01-27 03:27:01.209: E/AndroidRuntime(1080):     at com.app.wooqer.SplashActivity.onClick(SplashActivity.java:48)
01-27 03:27:01.209: E/AndroidRuntime(1080):     at android.view.View.performClick(View.java:3511)
01-27 03:27:01.209: E/AndroidRuntime(1080):     at android.view.View$PerformClick.run(View.java:14105)
01-27 03:27:01.209: E/AndroidRuntime(1080):     at android.os.Handler.handleCallback(Handler.java:605)
01-27 03:27:01.209: E/AndroidRuntime(1080):     at android.os.Handler.dispatchMessage(Handler.java:92)
01-27 03:27:01.209: E/AndroidRuntime(1080):     at android.os.Looper.loop(Looper.java:137)
01-27 03:27:01.209: E/AndroidRuntime(1080):     at android.app.ActivityThread.main(ActivityThread.java:4424)
01-27 03:27:01.209: E/AndroidRuntime(1080):     at java.lang.reflect.Method.invokeNative(Native Method)
01-27 03:27:01.209: E/AndroidRuntime(1080):     at java.lang.reflect.Method.invoke(Method.java:511)
01-27 03:27:01.209: E/AndroidRuntime(1080):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
01-27 03:27:01.209: E/AndroidRuntime(1080):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
01-27 03:27:01.209: E/AndroidRuntime(1080):     at dalvik.system.NativeStart.main(Native Method)
  • 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-06-17T21:05:55+00:00Added an answer on June 17, 2026 at 9:05 pm

    What you’re doing is very wasteful (any splash screen is wasteful, but using Threads like this is more so), but to fix your issue:

    use interrrupt(); intead of stop();

    As the docs say for stop()

    Throws UnsupportedOperationException.
    

    And to fix the duplicate issue, move the startActivity() inside the try so it looks like this:

    public void run() {
      try {
        Thread.sleep(5000);
        startActivity(new Intent(SplashActivity.this, LoginAuthenticationActivity.class));
      } catch (InterruptedException e) {
        e.printStackTrace();
      }
      finish();
    }
    

    That way when you call interrupt() all your Activity does is finish() and the duplicate startActivity() is not called.

    To further explain:

    Very first issue: stop() throws an exception by default, since it’s an unsafe method which you’re not supposed to use.

    Then when you used interrupt(), you had startActivity() in the run method after the catch block. When you interrupted, startActivity() was called once in run() and once in onClick(). By moving startActivity() inside the try block to right after Thread.sleep(), when interrupt() interrupts the Thread, the rest of the try block isn’t executed. This means that you now only have one startActivity() call instead of two. For more information, read up on exceptions.

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

Sidebar

Related Questions

Since input and raw_input() stop the program from running anymore, I want to use
I want to stop click on any links until the page is loaded. Can
picturebox1.image = image.fromfile(c:/anim.gif) after i import the animation, i want to Stop the animation
I want to end a loop running in a separate thread using a global
While the following code is executing, I want the ability to stop it from
I want to stop a looping thread when a signal was emitted so here
I have made two thread running together with Netbeans and i want to add
I want to stop the end users from being able to resize a GUI
I want to stop outgoing call and open the application. The app is able
Is there any way to stop polling server in SignalR? I want to stop

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.