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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T11:33:27+00:00 2026-06-05T11:33:27+00:00

I need that android application do something ant specific time of the day, for

  • 0

I need that android application do something ant specific time of the day, for example at 8:00 pm application should log out. I don’t want to use AlarmManager because it fired even if application is not running. also if phone was restarted of turned off schedule dispersers. Handler with Runnable will be very nice but if phone go asleep it don’t work.
So what i need is:

  • Application do something at specified time (which is saved in preferences)

  • This should happen only if application is running and logged in (even phone in asleep)

    What can you propose?

EDITED:

Also this task should wait until application ends its other work(sending, receiving data), even better if only executes in specific activity(like home or main where other work aren’t performing)

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

    The only way to wake the phone up when it is sleeping is by using the AlarmManager. There is no other way (well, you could hold a wake-lock and prevent the phone from going to sleep but that would drain the battery unnecessarily and your users would be angry).

    So you want to schedule an alarm using the AlarmManager. Then, when the alarm goes off, you can check yourself if the application is already running and logged in (save this information is some static (ckass) variables). If the application wasn’t already running and logged in, then just do nothing.

    EDIT: Add code example

    Create a public static (class) variable that can be accessed by all of the classes in your application:

    public class Globals {
        public static boolean applicationIsBusyDoingSomethingUseful = false;
    }
    

    In your application, whenever it is doing something useful and doesn’t want to get interrupted or logged-out by your timer-based alarm, it should set this variable to “true” and when it has completed its work and is no longer doing anything useful it should reset the variable to “false”:

    public void someUsefulWork() {
        // set flag while doing useful work
        Globals.applicationIsBusyDoingSomethingUseful = true;
        // do useful work
        // ...
        // end of useful work
        Globals.applicationIsBusyDoingSomethingUseful = false;
    }
    

    In your BroadcastReceiver, when the alarm goes off you can check if the application is doing anything useful. If it is, you just ignore the alarm and wait for the next one. If it isn’t doing anything useful, you log the user out.

    public class MyAlarmReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
            // Check if application is doing anything useful
            if (Globals.applicationIsBusyDoingSomethingUseful) {
                // Application is busy working, so ignore this alarm
            } else {
                // Log the user out or whatever...
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm doing an application for Android and something I need is that it shows
I'm developing android application for CAR usage and I need that in phone or
I'm developing an android application that contain many custom buttons. Do I need to
I need to have ALWAYS a background service that will synchronize my Android application
I need to add a shake feature that will refresh my Android application. All
I am developing an android mobile application using eclipse. I need a database that
I need to develop an application on Android platform that enables a client to
Hi i am working on web service application in android.i need a class that
I need an Android application which should be able to fetch data from the
I have problem with my Android application. I need an application that will send

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.