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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:07:17+00:00 2026-05-25T15:07:17+00:00

I searched for a while, but couldn’t find the same question. I am writing

  • 0

I searched for a while, but couldn’t find the same question.

I am writing an application where I need to schedule a lot of alarms a day, and then do different things throughout the day, and I’d love to be able to test, say 24 hours in 24 minutes, or something along those lines.

Is it possible to simulate a faster passage of time, either in emulator, or on-device?

If it is, this would be great for me to be able to test these things without losing development time. As it is, I’m writing them in a way that I think will work, doing spot tests, and then running the program myself to verify that the behavior is correct, but it greatly slows my development time to have to wait a day or two between seeing a poor behavior, and then trying to fix it and retesting it. Any help would be greatly 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-05-25T15:07:18+00:00Added an answer on May 25, 2026 at 3:07 pm

    If you abstract all time-dependent tasks into a single class, you could inherit that into a test-class, where all system times are multiplied by some constant, and all user times are divided by some constant. Instead of calling any time-dependent methods directly, you call it trough this class.

    class TimeHandler {
        protected Context context;
    
        public TimeHandler(Context context) {
            mContext = context;
        }
    
        public long toSystemMillis(long userMillis) {
            return userMillis;
        }
        public long toUserMillis(long systemMillis) {
            return systemMillis;
        }
        public long toSystemDelay(long userDelay) {
            return userDelay;
        }
        public long toUserDelay(long systemDelay) {
            return systemDelay;
        }
    
        public void setAlarmAt(long userMillis, PendingIntent operation) {
            long systemMillis = toSystemMillis(userMillis);
            AlarmManager am = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
            am.set(AlarmManager.RTC_WAKEUP, systemMillis, operation);
        }
    
        public void setAlarmAfter(long userDelay, PendingIntent operation) {
            long systemDelay = toSystemDelay(userDelay);
            AlarmManager am = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
            am.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, systemDelay, operation);
        }
    } // (scroll down)
    
    class OptimizedTimeHandler extends TimeHandler {
        protected static final long RATE = 60; // 1 minute -> 1 hour
        protected static final long START_TIME = Date.UTC(2011,9,18,0,0,0);
    
        public TestTimeHandler(Context context) {
            super(context);
        }
    
        @Override
        public long toSystemMillis(long userMillis) {
            return START_TIME + (userMillis - START_TIME)/RATE;
        }
        @Override
        public long toUserMillis(long systemMillis) {
            return START_TIME + (userMillis - START_TIME)*RATE;
        }
        @Override
        public long toSystemDelay(long userDelay) {
            return userDelay/RATE;
        }
        @Override
        public long toUserDelay(long systemDelay) {
            return systemDelay*RATE;
        }
    }
    

    UPDATE

    You could make the RATE and START_TIME constants into instance fields. Maybe even constructor arguments.

    Example usage:

    TimeHandler th = new TimeHandler();
    th.setAlarmAt(Date.UTC(2011,9,19,0,0,0), operation);
    // will fire at 2011-09-19 00:00:00 (real time)
    
    th = new OptimizedTimeHandler();
    th.setAlarmAt(Date.UTC(2011,9,19,0,0,0), operation);
    // will fire at 2011-09-18 00:24:00 (real time)
    

    If you can’t control the actual scheduling of the alarms, I don’t think there is any way to compress the time. You will have to use these classes to schedule the alarms when you are reading it from the database.

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

Sidebar

Related Questions

I searched google but couldn't find an answer to this rather simple question. I
Well I was curious about this and searched for a while but couldn't find
after searched for a while I still couldn't find any answer to my question,
I've searched quite a while in MSDN, couldn't find it. In fact, I don't
I'm sure this has been asked before, but I searched and couldn't find an
I searched for this and found Maudite's question about text editors but they were
I searched and found this question but did not like the answer. Is there
I searched the web, but I find a bunch of very different diagrams. Most
I have come across fluent API's while studying DSLs. I have searched a lot
I thought it will be a common question so I searched for a while

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.