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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T16:16:27+00:00 2026-06-07T16:16:27+00:00

THE PROBLEM I am having problems stopping the Timer whilst developing in android. The

  • 0

THE PROBLEM
I am having problems stopping the Timer whilst developing in android.

The timer is already null when it comes to stopping it.

I then move the timer initialisation to outside of a method just like the TimerTask which solves the null problem but still doesn’t cancel when timer.cancel(); is called upon it.

The code below is an example of the timer already being null when it comes to stopping the recording.

TimerTask

My TimerTask is initialized inside the class but outside of a method and the codes below…

private TimerTask task = new TimerTask() {
    @Override
    public void run() {
      Log.e("TRACK_RECORDING_SERVICE","Timer Running");
    }
  };

Timer & Timer Start

I then have a startRecroding method which is called when I want to start the timer…

public void startRecording(){
     timer = new Timer("Message Timer");
     timer.scheduleAtFixedRate(this.task, 0, 1000);
 }

Timer Stop

I then call the below method when I want to stop the timer…

public void stopRecording() {
     if (timer != null) {
         timer.cancel();
         timer = null;
     } else {
         Log.e("TRACK_RECORDING_SERVICE","Timer already null.");
     }
 }

Any help would be much appreciated.

  • 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-07T16:16:30+00:00Added an answer on June 7, 2026 at 4:16 pm
    timer = new Timer("Message Timer"); 
    

    Here your object timer is not a static so timer.cancel(); will cancel another instance of the Timer class. I suggest you to create a static instance variable of Timer Class on the top of the class, like below,

    private static Timer timer;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having problems starting & stopping NSTimers. The docs say that a timer is
im having problems starting a codeigniter project, the problem is that when i do
Having problems iterating. Problem has to do with const correctness, I think. I assume
I have a problem in my company where suddenly 2 users were having problems
Spent some time troubleshooting a problem whereby a PHP/MySQL web application was having problems
I can't solve this problem... I'm having some problems with fetched properties (not with
I'm having a problem stopping the 'feed'; the cancel argument doesn't seem to have
so im having problems with android clipping the button click area on my view.
The problem that I'm having is when running my android app, if I run
I am having problems with stoping NSTimer started on button click. [timer invalidate] and

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.