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

  • Home
  • SEARCH
  • 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 9002809
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:37:13+00:00 2026-06-16T00:37:13+00:00

I am New in Android and I create a application but it crash when

  • 0

I am New in Android and I create a application but it crash when I start same activity on button click and i also finish current Activity here is my error log . I am using Timer in my application and Background music also

12-18 05:55:15.776: D/AndroidRuntime(2345): Shutting down VM
12-18 05:55:15.776: W/dalvikvm(2345): threadid=1: thread exiting with uncaught exception (group=0x40a13300)
12-18 05:55:15.817: E/AndroidRuntime(2345): FATAL EXCEPTION: main
12-18 05:55:15.817: E/AndroidRuntime(2345): android.view.WindowManager$BadTokenException: Unable to add window -- token android.os.BinderProxy@41542480 is not valid; is your activity running?
12-18 05:55:15.817: E/AndroidRuntime(2345):     at android.view.ViewRootImpl.setView(ViewRootImpl.java:585)
12-18 05:55:15.817: E/AndroidRuntime(2345):     at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:326)
12-18 05:55:15.817: E/AndroidRuntime(2345):     at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:224)
12-18 05:55:15.817: E/AndroidRuntime(2345):     at android.view.WindowManagerImpl$CompatModeWrapper.addView(WindowManagerImpl.java:149)
12-18 05:55:15.817: E/AndroidRuntime(2345):     at android.view.Window$LocalWindowManager.addView(Window.java:547)
12-18 05:55:15.817: E/AndroidRuntime(2345):     at android.app.Dialog.show(Dialog.java:277)
12-18 05:55:15.817: E/AndroidRuntime(2345):     at android.app.AlertDialog$Builder.show(AlertDialog.java:932)
12-18 05:55:15.817: E/AndroidRuntime(2345):     at com.example.whowantto.play$timer.onFinish(play.java:722)
12-18 05:55:15.817: E/AndroidRuntime(2345):     at android.os.CountDownTimer$1.handleMessage(CountDownTimer.java:118)
12-18 05:55:15.817: E/AndroidRuntime(2345):     at android.os.Handler.dispatchMessage(Handler.java:99)
12-18 05:55:15.817: E/AndroidRuntime(2345):     at android.os.Looper.loop(Looper.java:137)
12-18 05:55:15.817: E/AndroidRuntime(2345):     at android.app.ActivityThread.main(ActivityThread.java:4745)
12-18 05:55:15.817: E/AndroidRuntime(2345):     at java.lang.reflect.Method.invokeNative(Native Method)
12-18 05:55:15.817: E/AndroidRuntime(2345):     at java.lang.reflect.Method.invoke(Method.java:511)
12-18 05:55:15.817: E/AndroidRuntime(2345):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
12-18 05:55:15.817: E/AndroidRuntime(2345):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
12-18 05:55:15.817: E/AndroidRuntime(2345):     at dalvik.system.NativeStart.main(Native Method)
12-18 05:55:57.476: E/Trace(2564): error opening trace file: No such file or directory (2)
12-18 05:55:57.546: D/AndroidRuntime(2564): Shutting down VM

Thanks in advance

  • 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-16T00:37:14+00:00Added an answer on June 16, 2026 at 12:37 am

    Your CountDownTimer tries to show an AlertDialog after the Activity has ended it’s lifecycle. Maybe you are calling finish() but don’t cancel() the task.

    You could add a variable that is checked by your timer if it should still show the dialog like in below sample

    public class TimerActivity extends Activity {
    
        private boolean mDialogEnabled;
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
    
            // add timer start to some button
            findViewById(R.id.button1).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    new CountDownTimer(5000, 1000) {
                        @Override
                        public void onTick(long millisUntilFinished) {
                            // something
                        }
    
                        @Override
                        public void onFinish() {
                            if (mDialogEnabled) // <<< check
                                new AlertDialog.Builder(TimerActivity.this)
                                    .show();
                        }
                    }.start();
                }
            });
        }
    
        // enable/disable showing the dialog in start / stop for example
    
        @Override
        protected void onStart() {
            super.onStart();
            mDialogEnabled = true;
        }
    
        @Override
        protected void onStop() {
            super.onStop();
            mDialogEnabled = false;
        }
    }
    

    Or you could go with a more sophisticated implementation that should retain the timer task and re-attach it to the next actvity instance like in below example. This way the Activity can be recreated on rotation for example and still use a timer started in an old activity instance.

    public class TimerActivity extends Activity {
    
        static class MyCountDownTimer extends CountDownTimer {
            private Context mContext;
            public MyCountDownTimer(long millisInFuture, long countDownInterval) {
                super(millisInFuture, countDownInterval);
            }
    
            public void setContext(Context context) {
                mContext = context;
            }
    
            @Override
            public void onFinish() {
                if (mContext != null) {
                    new AlertDialog.Builder(mContext)
                        .setMessage("Finished!")
                        .show();
                }
            }
            @Override
            public void onTick(long millisUntilFinished) {
                if (mContext != null) {
                    // do something
                }
            }
        }
    
        MyCountDownTimer mTimer;
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
    
            // restore timer to current Activity
            mTimer = (MyCountDownTimer) getLastNonConfigurationInstance();
    
            // add timer start to some button
            findViewById(R.id.button1).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    // cancel old timers
                    if (mTimer != null) {
                        mTimer.cancel();
                    }
                    mTimer = new MyCountDownTimer(5000, 1000);
                    mTimer.start();
                }
            });
    
        }
    
        @Override
        public Object onRetainNonConfigurationInstance() {
            // save timer and detach from Activity
            if (mTimer != null) {
                mTimer.setContext(null);
            }
            return mTimer;
        }
    
        @Override
        protected void onStart() {
            super.onStart();
            // Activity going to be visible now, attach timer
            if (mTimer != null)
                mTimer.setContext(this);
        }
    
        @Override
        protected void onStop() {
            super.onStop();
            // Activity going to be invisible, detach timer
            if (mTimer != null) {
                mTimer.setContext(null);
                // if activity is not to be recreated cancel it
                if (isFinishing()) {
                    mTimer.cancel();
                    mTimer = null;
                }
            }
        }
    }
    

    All code untested but it’s roughly how it should work.

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

Sidebar

Related Questions

I'm trying to create an intent to a new activity on an application but
I am new to phonegap and android, I have create a hello world application
I would know if there is the possibility to create a new Android Activity
I want to create a new web-browser for android, but this browser is not
I am new to android. I just create one application it download the file
I'm new to android and i would like to create an application that reads
Hello i am new in developing Android applications, I need to create an application
I'm trying to create an Android application that shows the current time. I want
I am new to Android application, create one xml file data.xml inside the Resource
I'm trying to create an Aler Dialog but when I click on button my

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.