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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T11:48:33+00:00 2026-06-10T11:48:33+00:00

Hi I have a timer task that check a file every 1 minute public

  • 0

Hi I have a timer task that check a file every 1 minute

public class MyTimerTask extends TimerTask {
//java.io.File file = new java.io.File("/mnt/sdcard/Bluetooth/1.txt");
java.io.File file = new java.io.File("init.rc");
public void CheckTheFile() 
{
if (file.exists())
    {   
    // I want here to start the Activity GetGPS
    }
}
@Override
public void run() {
    CheckTheFile();
}

}

in the check of file.exists , I want if the file is there , activity called GetGPS.
Thanks.

  • 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-10T11:48:33+00:00Added an answer on June 10, 2026 at 11:48 am

    In your case I would recommend using Handler class. Here’s what I would do:

    private static class PromoScroller implements Runnable {
    
        private Handler _scrollHandler;
    
        public PromoScroller(Handler scrollHandler) {
            _scrollHandler = scrollHandler;
        }
    
        @Override
        public void run() {
            // .. 
            _scrollHandler.sendEmptyMessage(0);
        }
    }
    

    // somewhere in your activity:

    _promoScroller = new PromoScroller(new Handler() {
            @Override
            public void dispatchMessage(Message msg) {
                super.dispatchMessage(msg);
                // !! catch message and start the activity
                Intent = new Intent(YourCurrentActivty.this, YourTargetActivity.class);
            }
        });
        _scrollerThread = new Thread(_promoScroller);
        _scrollerThread.start();
    

    P.S. those are bits of code I use for scrolling timer, but you get the idea

    UPD

    // TASK
    public class YourTimerTask extends TimerTask {
        private Handler _Handler;
    
        public YourTimerTask(Handler handler) {
            _Handler = handler;
        }
    
        public void run() {
            _Handler.sendEmptyMessage(0);
        }
    }
    
    // TASK HANDLER (private property in your acitivity)
    private Handler _taskHandler = new Handler(){
        public void dispatchMessage(android.os.Message msg) {
            // do cleanup, close db cursors, file handler, etc.
            // start your target activity
            Intent viewTargetActivity = new Intent(YourCurrentActivity.this, YourTargetActivity.class);
    
        };
    };
    
    
    // IN YOUR ACTIVITY (for isntance, in onResume method)
    Timer timer = new Timer();
    timer.schedule(new YourTimerTask(_taskHandler), seconds*1000);
    

    This should do the job. For timer – just google.timer example

    UPD2

    my mistake – it should be Handler _timerHandler = .... for starting activity look here

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

Sidebar

Related Questions

I have two spring beans as follows: @Component(A) @Scope(prototype) public class A extends TimerTask
Right now, I have a class defined as such: public class Task { public
I have a long running timer task. Its a batch process actually that will
I have a question about timer in thread? My code : public partial class
I have a task that takes a rather long time and should run in
My goal is to have an AsyncTask that can execute multiple times (one task
I have an application in which I am starting a timer for two task:
So I have a TimerTask task calling a function onTimerComplete() in its run() onTimerComplete()
How can i have timer which runs for every 5 secs continously. below is
I have made a program that continuously monitors a log file. But I don't

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.