<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Todor Kostov</title>
    <description>The latest articles on DEV Community by Todor Kostov (@kostovtd).</description>
    <link>https://dev.to/kostovtd</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F376064%2F992ae3be-c408-4adf-841b-284f5c057258.jpg</url>
      <title>DEV Community: Todor Kostov</title>
      <link>https://dev.to/kostovtd</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/kostovtd"/>
    <language>en</language>
    <item>
      <title>Location without Google Services</title>
      <dc:creator>Todor Kostov</dc:creator>
      <pubDate>Thu, 06 Oct 2022 16:11:14 +0000</pubDate>
      <link>https://dev.to/kostovtd/location-without-google-services-1moa</link>
      <guid>https://dev.to/kostovtd/location-without-google-services-1moa</guid>
      <description>&lt;p&gt;These days you will rarely find an app that doesn’t have some kind of location-based functionality. Things like navigation, geofencing or location tracking are more and more common. It’s all good when you can rely on Google Play Services. Sadly, that’s not always the case. Sometimes the devices that your users are going to use don’t have Play Services installed. Such devices can be manufactured by some weird and unknown company, can have a custom ROM installed on them, or be located in a country where Google is not allowed to operate. No matter the reason, the fact that Google Play Services are missing from the device can make the task of obtaining the user’s location quit challenging. So let’s try to find out what options we have to solve this problem.&lt;/p&gt;

&lt;p&gt;There are two different ways of obtaining a location without using Google Play Services:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;By using the Location Manager&lt;/li&gt;
&lt;li&gt;By using a 3rd party Network Location Provider (NLP)&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Location Manager
&lt;/h2&gt;

&lt;p&gt;This is the old school way of obtaining a location. By using the Location Manager we can choose between four different providers:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;GPS&lt;/strong&gt; - a precise way to determine the current location of the user. Although there are some drawbacks. This method is a bit slow and is not suitable for indoors use. The reason is that an actual connection with at least three GPS satellites must be established. The process is called triangulation. &lt;a href="https://en.wikipedia.org/wiki/Global_Positioning_System"&gt;https://en.wikipedia.org/wiki/Global_Positioning_System&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Network&lt;/strong&gt; - that’s faster than using the GPS provider. It relies on using data about your current Wi-Fi or mobile network. It’s not that accurate compared to the GPS provider, but it’s faster and can be used indoors as well. It’s an interesting process, and it was developed long before the invention of GPS. You can read more here &lt;a href="https://en.wikipedia.org/wiki/Mobile_phone_tracking"&gt;https://en.wikipedia.org/wiki/Mobile_phone_tracking&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Passive&lt;/strong&gt; - by using it we will get a location only if some other app had requested it. It’s power efficient, but it’s not reliable at all.
Fused (since API 31) - it’s a combination between the other providers.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You can find a simple gist with examples here - &lt;a href="https://gist.github.com/kostovtd/9bbe9352c7ef6adfc313bac193b48424"&gt;https://gist.github.com/kostovtd/9bbe9352c7ef6adfc313bac193b48424&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The good thing about using the Location Manager is that it is so old that it actually doesn’t use the Google Play Services under the hood. 😆&lt;/p&gt;

&lt;h2&gt;
  
  
  3rd party Network Location Providers (NLPs)
&lt;/h2&gt;

&lt;p&gt;These Network Location Providers work somehow in a similar fashion like the Location Manager’s Network provider. The difference is that the phone sends a HTTP request with some data regarding cell tower coverage, IP address, etc. Based on this information, the corresponding service executes a search in it’s database and hopefully figures out your current location.&lt;/p&gt;

&lt;p&gt;There are multiple services out there which provide a variety of different price packages, response formats and have different limitations. These are just three suggestions:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;a href="https://github.com/microg/UnifiedNlp"&gt;https://github.com/microg/UnifiedNlp&lt;/a&gt; - acts as a middle ware for multiple backends which have network location features.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://ichnaea.readthedocs.io/en/latest/index.html"&gt;https://ichnaea.readthedocs.io/en/latest/index.html&lt;/a&gt; - a geolocation service that uses both Bluetooth, WiFi and Cell data. The project is open only for not commercial use.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://aws.amazon.com/location/"&gt;https://aws.amazon.com/location/&lt;/a&gt; - provides a huge set of maps and location based features. Although, I was not able to find a simple way of getting the current location of the user.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Feel free to share, comment &amp;amp; give your opinion on the topic!&lt;/p&gt;

</description>
      <category>android</category>
      <category>location</category>
      <category>gps</category>
    </item>
    <item>
      <title>Lifecycle changes after API 28</title>
      <dc:creator>Todor Kostov</dc:creator>
      <pubDate>Sat, 27 Aug 2022 12:41:01 +0000</pubDate>
      <link>https://dev.to/kostovtd/lifecycle-changes-after-api-28-4jm0</link>
      <guid>https://dev.to/kostovtd/lifecycle-changes-after-api-28-4jm0</guid>
      <description>&lt;p&gt;Some time ago, I was going through the documentation about the infamous Activity class. All was good and even uneventful until I came across an interesting paragraph stating the following:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--R0O_a-0T--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/h9qgxccdp0vei3st3f6n.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--R0O_a-0T--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/h9qgxccdp0vei3st3f6n.jpg" alt="Diagram of the lifecycle changes" width="880" height="406"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;A question popped up in my head- but why the change in the order?&lt;/p&gt;

&lt;p&gt;My first idea was to search for any articles on the topic. Sadly, with no result.&lt;/p&gt;

&lt;p&gt;Then, I decided to go through the source code of the Activity class. There was also nothing that could provide some insight on the topic.&lt;/p&gt;

&lt;p&gt;My last resort was to search for some discussions on Stack Overflow. To my surprise, there was a useful reference to the Android documentation.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--X0WbZi3i--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4plwb7fa34u6aprebzlr.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--X0WbZi3i--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4plwb7fa34u6aprebzlr.jpg" alt="A possible reason for the changes" width="880" height="178"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Although the last paragraph throws some light on the topic, I was still not satisfied with it.&lt;/p&gt;

&lt;p&gt;After initiating a discussion on Stack Overflow, I can conclude the following - First of all, it’s hard to come up with a precise answer to this question without actually involving some engineers from Google. For sure, they will be able to give enough information on the topic. Thus, the following statement is just speculation. The one possible reason behind this change is &lt;strong&gt;consistency&lt;/strong&gt;. Before API 28, we couldn’t be 100% sure that the code in on Save Instance State will be executed at all. That can lead to losing important data and the inability to properly recreate the state. With the changes introduced in API 28, we can now be sure that our data will be saved.&lt;/p&gt;

&lt;p&gt;Thanks to &lt;a href="https://stackoverflow.com/users/2684/martin-marconcini"&gt;Martin Marconcini&lt;/a&gt; for giving his 5 cents on the topic.&lt;/p&gt;

&lt;p&gt;Feel free to share, comment &amp;amp; give your opinion on the topic!&lt;/p&gt;

</description>
      <category>android</category>
      <category>mobile</category>
    </item>
  </channel>
</rss>
