GPS and SQLiteDatabase tied for functionality?


Last Updated:

  1. droidofdewm

    droidofdewm New Member This Topic's Starter

    Joined:
    Aug 8, 2010
    Messages:
    2
    Likes Received:
    0
    I'm creating an app that requires GPS to gather information and insert this information into a SQLiteDatabase. The app works perfectly fine as coded UNTIL the GPS is turned off. Apparently, when the GPS is turned off, my insert method for the database throws a NullPointerException. I figured it was because the location object was null since there was no actual GPS location. So, I created dummy variables to insert into the database in case the GPS was turned off, but am still getting a NullPointerException when calling db.insert with these dummy variables. I've checked all possible points of failure and know for a fact correct types and values are being sent. Does anyone know if for some strange reason that the SQLiteDatabase is tied to the GPS in any way, shape or form that would cause this to fail?
     

    Advertisement
  2. jonbonazza

    jonbonazza Well-Known Member

    Joined:
    Jul 13, 2010
    Messages:
    1,934
    Likes Received:
    458
    Why don't you just check the GPS state of the phone and only do the insert method if the GPS is active.
     
  3. droidofdewm

    droidofdewm New Member This Topic's Starter

    Joined:
    Aug 8, 2010
    Messages:
    2
    Likes Received:
    0
    Well the problem has officially been fixed. Apparently because the GPS lookup was in the foreground process, it would cause the application to force close upon leaving the Activity. Instead, I moved the GPS lookup and check to a background service and checked there. If the location wasn't null I got the info I needed and announced it back to the first Activity and then used a BroadcastReceiver to get the info. If location was null i announced dummy variables in the Service and posted those instead.
     

Share This Page

Loading...