0

I've tried many ways of creating a java class that would handle my location. Every time I get a nullpointerexception. What I have now is locationlistener in my mainactivity but when creating more activities that need a location it wouldn`t be that smart. Does anyone have any code on how to create such a class?

Gabe
  • 111
  • 5
  • How about reading the Google provided location awareness training available here - https://developer.android.com/training/location/index.html. It should tell you all you need to know. – clownba0t Nov 11 '16 at 20:02
  • That doesn`t show me how to create a java class to hold everything it just uses it in an activity which I would like to stay away from. – Gabe Nov 11 '16 at 20:35
  • Perhaps consider using an Android [`Service`](https://developer.android.com/guide/components/services.html) to run the location fetching and updating code in the background and provide it to any class which needs it via a listener, static methods, broadcasts, etc. [This SO post](https://stackoverflow.com/questions/14478179/background-service-with-location-listener-in-android) has a basic example which could be a good place to start from. Hope that helps! – clownba0t Nov 12 '16 at 07:07

0 Answers0