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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T05:20:40+00:00 2026-06-16T05:20:40+00:00

I am making an application that attaches both location and sensor listeners, so that

  • 0

I am making an application that attaches both location and sensor listeners, so that it can then record changes from them into a file.

What’s strange is that one of the phones using the application was Force Closing in some instances, which I narrowed down to orientation changes: if the phone changed orientation during recording, the SensorManager attribute I had stored inside the activity as ‘mSensorManager’ would then be set to null.

This leads into my question: should I not store the SensorManager reference, due to it being a bad design choice? Or is it okay, and should I just check if the reference is null before using it?

EDIT: Two things to add:

  1. I found out that not only the accelerometer and magnetometer attributes were also nullified (which kind of made sense), but also
    the locationmanager (which doesn’t make much change, as it has
    nothing to do with orientation determination);

  2. Should I store those attributes inside something other than the activity, that won’t nullify the references upon an orientation
    change?

What did it for me:
Correcting listener, manager and sensor instantiation to be done from within the activity’s lifecycle. Then the only problem was with the wake-lock, which was destroyed, but I needed to be kept through the orientation changes. I changed it to be acquired during the activity lifecycle aswell, albeit in a different phase.

  • 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-16T05:20:41+00:00Added an answer on June 16, 2026 at 5:20 am

    What did it for me: Correcting listener, manager and sensor instantiation to be done from within the activity’s lifecycle. Then the only problem was with the wake-lock, which was destroyed, but I needed to be kept through the orientation changes. I changed it to be acquired during the activity lifecycle aswell, albeit in a different phase.

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

Sidebar

Related Questions

I'm making an application that directly takes images from a site and downloads them
I am making an application that involves controlling Safari from Applescript. Is there a
I'm making an application that recovers lottery numbers and displays them in a window.
I am making a simple application that uses a NSSlider, which can be put
I am making an android application that loads files from a directory on the
I'm making a chat application that works with long-polling to emulate a push from
How would you go about making an application that can edit it's own look
I'm making an application that parses text and images from the Internet and displays
I'm making an application that can search a table 'employee' and return results. I'm
I'm making an application that can search a table 'employee' and return results. How

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.