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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T17:16:03+00:00 2026-06-01T17:16:03+00:00

I want to run a Service only when the user is active or more

  • 0

I want to run a Service only when the user is active or more general: when the phone is active. There is no need that the service runs when the screen is off. But as soon as the user unlocks his phone, I want the service to run again.

How do I achieve this behaviour?

My actual task: I want to capture logcat. Therefore I created a Service which spawns a thread that reads the output of the “logcat” process.

How exactly does that background thread behave when the phone gets locked? It does not hold any wake locks or stuff. Will Android pause the thread when the phone goes to sleep or will that thread keep Android from going to sleep? How will it be resumed after the phone awakes?

I also thought about registering an alarm via ´AlarmManager´ that fires every 15 minutes and parses the logcat. But with this approach I will likely miss some of the logcat lines.

  • 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-01T17:16:04+00:00Added an answer on June 1, 2026 at 5:16 pm

    For restarting service:You can register a receiver for ACTION_USER_PRESENT or ACTION_SCREEN_ON : this Intent Sent by system when the user is present(when the phone is active) after device wakes up (e.g when the keyguard is gone). or when phone screen on.

    For stopping service: use ACTION_SCREEN_OFF intent this intent send by deivce when user is not present or mobile screen is OFF

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

Sidebar

Related Questions

I want to make a web service that runs other people's code locally. Naturally,
I want to run function inside web service (.asmx file) $.ajax({ type: POST, contentType:
Hi I want to create a soap service. When i run it, the service
I want to run javascript/Python/Ruby inside my application. I have an application that creates
We have a Service that continuously collects sensor data on the phone. This service
I need to create an activity that starts a service that monitors the users
I am working on a .NET Web Service and I want to run multiple
I want to create a script that will run whenever a server is turned
I want to grant a permission to my service to user/everyone. I can use
If I just want to run the new style web services on, say a

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.