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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T05:08:48+00:00 2026-05-19T05:08:48+00:00

I m looking for the best practice to implement a service for logging gps-

  • 0

I m looking for the best practice to implement a service for logging gps- or other sensor-values periodically (every 10-60 sec). The service should deal with the standby mode, when the phone goes asleep.

Any help, even pseudo-code, is very 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-05-19T05:08:49+00:00Added an answer on May 19, 2026 at 5:08 am

    It looks like it is impossible to let the orientation sensors work constantly for hours even though the device may fall asleep (refer to http://code.google.com/p/android/issues/detail?id=3708#makechanges

    As soon as the display goes off, the sensors will do alike… 🙁

    I now implemented a wakelock (needs permission)

    <uses-permission android:name="android.permission.WAKE_LOCK" /> 
    

    in conjunction with a timer and a broadcastreciever that will turn the display back on again. This is of course crazy for battery life but I found no other way so far.

    This is my onCreate method in the service:

    @Override
    public void onCreate() {
    mNM = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    CONTEXT = this;
    PowerManager pm = (PowerManager) CONTEXT.getSystemService(Context.POWER_SERVICE);
    this.mWakeLock = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, "my tag");
    mWakeLock.acquire();
    Log.d(TAG, "Wakelock acquired");
    // register receiver that handles screen on and screen off logic
                IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_ON);
                filter.addAction(Intent.ACTION_SCREEN_OFF);
                BroadcastReceiver mReceiver = new ScreenReceiver();
                registerReceiver(mReceiver, filter);
    }
    

    this the onStart method of the service:

    @Override
    public void onStart(Intent intent, int startid) {
    Toast.makeText(this, "My Service Started", Toast.LENGTH_SHORT).show();
    Log.d(TAG, "onStart");
    boolean screenOn = intent.getBooleanExtra("screen_state", false);
                if (!screenOn) {
                    Log.d(TAG, "Screen is on");
                } else {
                 Log.d(TAG, "Screen is off");
             Timer timer = new Timer("DigitalClock");
         timer.schedule(new TimerTask() {
            @Override
            public void run() {
             Log.d(TAG,"Waiting 1 sec for switching the screen back on again...");
         PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
         mWakeLock = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP,
             "my tag");
         mWakeLock.acquire();
            }
         }, 1000);
                 mWakeLock.acquire();
                    }
    }
    

    and this is the BroadcastReceiver class:

    public class ScreenReceiver extends BroadcastReceiver {
         private boolean screenOff;
         @Override
         public void onReceive(Context context, Intent intent) {
                 if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) {
                         screenOff = true;
                 } else if (intent.getAction().equals(Intent.ACTION_SCREEN_ON)) {
                         screenOff = false;
                 }
                 Intent i = new Intent(context, MyService.class);
                 i.putExtra("screen_state", screenOff);
                 context.startService(i);
         }
    

    }

    This workaround will also do with a device UN-plugged from the debugger via USB (I first had an issue with this).

    Please let me know if you have a better solution, or if there is fix in 2.3. Thanx!

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

Sidebar

Related Questions

We are developing a new web service and are looking into the best practice
I am looking for a best practice for End to End Authentication for internal
Looking for advice (perhaps best practice). We have a MS Word document (Office 2007)
I am looking for guidance regarding the best practice around the use of the
I am looking for best practices for detecting and preventing DOS in the service
I'm looking for best practices for establishing connections between Oracle 8 and Visual Studio
I'm looking for best practices for performing strict (whitelist) validation/filtering of user-submitted HTML. Main
I'm looking for best practices for using the same data in different places without
I am looking for best practices in regards to printing from a WinForms application.
I'm looking for best-practices for designing a site that with accessibility in mind. The

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.