<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>dajsiepoznac2017 Archives - CodeJourney.net</title>
	<atom:link href="https://www.codejourney.net/tag/dajsiepoznac2017/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.codejourney.net/tag/dajsiepoznac2017/</link>
	<description>Pragmatic full stack software development</description>
	<lastBuildDate>Wed, 17 May 2023 12:41:54 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>https://i0.wp.com/www.codejourney.net/wp-content/uploads/2018/10/cropped-512px-na-512px-JPEG-BEZ-NAPISU-1.jpg?fit=32%2C32&#038;ssl=1</url>
	<title>dajsiepoznac2017 Archives - CodeJourney.net</title>
	<link>https://www.codejourney.net/tag/dajsiepoznac2017/</link>
	<width>32</width>
	<height>32</height>
</image> 
<site xmlns="com-wordpress:feed-additions:1">123174533</site>	<item>
		<title>DajSiePoznac2017 &#8211; summary</title>
		<link>https://www.codejourney.net/dajsiepoznac2017-summary/</link>
					<comments>https://www.codejourney.net/dajsiepoznac2017-summary/#comments</comments>
		
		<dc:creator><![CDATA[Dawid Sibiński]]></dc:creator>
		<pubDate>Wed, 31 May 2017 20:33:04 +0000</pubDate>
				<category><![CDATA[Others]]></category>
		<category><![CDATA[dajsiepoznac2017]]></category>
		<guid isPermaLink="false">http://www.dsibinski.pl/?p=2315</guid>

					<description><![CDATA[<p>It has just started&#8230; but yes, today is the last day of DajSiePoznac2017 and it&#8217;s officially my last blog post for the competition. It feels weird somehow&#8230; 😉 Time to sum it up! General feelings Today I can definitely say I feel proud of myself 🙂 Even though I could have made some of my posts published&#8230;</p>
<p>The post <a href="https://www.codejourney.net/dajsiepoznac2017-summary/">DajSiePoznac2017 &#8211; summary</a> appeared first on <a href="https://www.codejourney.net">CodeJourney.net</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>It has <a href="https://www.codejourney.net/2017/02/hello-dajsiepoznac2017/" target="_blank" rel="noopener noreferrer">just started</a>&#8230; but yes, today is the last day of <a href="http://dajsiepoznac.pl" target="_blank" rel="noopener noreferrer">DajSiePoznac2017</a> and it&#8217;s <strong>officially my last blog post for the competition</strong>. It feels weird somehow&#8230; <img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f609.png" alt="😉" class="wp-smiley" style="height: 1em; max-height: 1em;" /></p>
<p>Time to sum it up!<br />
<span id="more-2315"></span></p>
<h2>General feelings</h2>
<p>Today I can definitely say <strong>I feel proud of myself</strong> <img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f642.png" alt="🙂" class="wp-smiley" style="height: 1em; max-height: 1em;" /> Even though I could have made some of <a href="https://www.codejourney.net/category/dajsiepoznac2017/" target="_blank" rel="noopener noreferrer">my posts published during the competition</a> better. Even though I could have made <a href="https://www.codejourney.net/2017/03/moneyback-requirements-functionalities-and-technologies/" target="_blank" rel="noopener noreferrer">my <em>MoneyBack</em> app developed during the project</a> faaaaar more advanced.</p>
<p>I already wrote in the beginning of the competition, that for me neither completing the application nor becoming a perfect blogger with thousands of readers was the point here. The real goal was to arrive to the end, meet the competition&#8217;s requirements and feel proud at the end of this story &#8211; and this is undoubtedly how I feel now <img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f609.png" alt="😉" class="wp-smiley" style="height: 1em; max-height: 1em;" /></p>
<h2>Statistics</h2>
<p>I&#8217;d like to shortly presents a few interesting statistics concerning the content I produced during the 3 months of the competition (March-May 2017):</p>
<ul>
<li>I wrote <strong><a href="https://www.codejourney.net/category/dajsiepoznac2017/" target="_blank" rel="noopener noreferrer">21 competition&#8217;s posts</a></strong> (including <a href="https://www.codejourney.net/2017/02/hello-dajsiepoznac2017/" target="_blank" rel="noopener noreferrer">1 published in February</a>, so not really counted)</li>
<li>I checked-in (added, changed or removed) <strong><a href="https://github.com/dsibinski/MoneyBack/graphs/contributors" target="_blank" rel="noopener noreferrer">19,381 lines of code</a></strong> (including auto-generated parts)</li>
<li>top-viewed post: <a href="https://www.codejourney.net/2017/03/simple-habits-for-better-productivity/" target="_blank" rel="noopener noreferrer">Simple habits for better productivity</a> with <strong>~2600 views</strong> for the time of writing this post</li>
<li>best-ever number of daily blog&#8217;s views: <strong>2121 views </strong>on 28.05.2017</li>
<li>top referrers: <strong><a href="https://www.reddit.com/" target="_blank" rel="noopener noreferrer">Reddit</a> with</strong> <strong>613 views</strong>, <a href="http://dotnetomaniak.pl/" target="_blank" rel="noopener noreferrer">dotnetomaniak.pl</a> with <strong>603 views</strong>, Google Search with <strong>365 views</strong></li>
<li>most views from: <strong>United States</strong> (<strong>1503</strong>), Poland (<strong>1418</strong>), United Kingdom (<strong>274</strong>)</li>
<li><strong>33 comments</strong> added in total on the published blog posts.</li>
</ul>
<h2><span style="text-decoration: underline;">What was good</span></h2>
<p>I have listed several aspects of taking part in DSP competition that I feel especially good about. These include achieved goals, as well as some activities I wanted to begin doing since a piece of time.</p>
<h5>(+) Blogging</h5>
<p>Starting a technical blog is one of my best achievements in the competition. It showed me that I really like to publish my insights, share my knowledge with the others and just write solutions to precise issues I&#8217;ve met here. Even during those 3 months I referred back to the posts I&#8217;ve wrote few weeks ago when I needed to refresh something I already did. Writing a blog post about something, which is public and read by other people (in many cases more experienced programmers) enforces the writer to organize and collect the knowledge he or she is willing to share. This helps making self-learning process really solid and more effective.</p>
<h5>(+) Learning mobile development with Xamarin</h5>
<p>For a piece of time already I&#8217;ve wanted to start mobile development with Xamarin platform. Maybe I haven&#8217;t arrived to deeply advanced development stuff, but I definitely learnt the basics of Xamarin and implementing Android apps using it. I was able do it with my daily-used C#, so there was no big entry threshold here, even with many really frustrating issues met on my &#8220;Xamarin way&#8221; which I&#8217;ve been sharing with you here <img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f609.png" alt="😉" class="wp-smiley" style="height: 1em; max-height: 1em;" /></p>
<h5>(+) Open-source contribution</h5>
<p>I had an opportunity to publish my source code on <a href="https://github.com/dsibinski/MoneyBack" target="_blank" rel="noopener noreferrer">public GitHub repository</a>, so other people can potentially see and make a use of it.  I really love the idea of open-source, so it was another nice experience. I even found out that each public repository should have <a href="https://github.com/dsibinski/MoneyBack/blob/master/LICENSE" target="_blank" rel="noopener noreferrer">a license file</a> added to be considered &#8220;really open-source&#8221; <img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f642.png" alt="🙂" class="wp-smiley" style="height: 1em; max-height: 1em;" /></p>
<h5>(+) Reading other participants&#8217; blogs</h5>
<p>During my DSP adventure I&#8217;ve been reading many blog posts published by the other competition&#8217;s members. I&#8217;d even say that I&#8217;ve never read that many posts from different authors in such short period of time. It allowed me to see different writing styles and get the knowledge about various kinds of technologies I had never worked with.</p>
<h5>(+) Learning, learning, learning&#8230;</h5>
<p>Basically &#8211; I learn maaaany things during the competition. Starting from technical stuff about Xamarin, through writing a blog, configuring and setting-up WordPress, promoting myself on Twitter, Facebook, LinkedIn or Reddit to gaining a lot of knowledge by reading another blog posts on totally various topics. Those 3 months definitely generated a lot of valuable knowledge of different kinds in my head.</p>
<h2><span style="text-decoration: underline;">What was bad</span></h2>
<p>Of course I also have few aspects of my activity during the competition that I consider as done in a wrong way. I&#8217;m also putting here few things that made me frustrated during the competition and wasn&#8217;t even my personal mistakes.</p>
<h5>(-) Wrong planning</h5>
<p>The most basic mistake I&#8217;ve made (and I make it in many aspects of my life, as many of us, probably <img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f642.png" alt="🙂" class="wp-smiley" style="height: 1em; max-height: 1em;" /> ) was a wrong planning. I wanted to write it was too ambitious, but it&#8217;s not even really the case. In the beginning of the competition I should have made a long-perspective planning (what parts of my app should be completed until what date, how many posts should I publish each week/month etc). It would probably help me to do more and eliminate lack of time I&#8217;ve met during the contest.</p>
<h5>(-) Irregularity in posts&#8217; publishing</h5>
<p>I know that I was publishing my posts totally irregularly, sometimes at late hours when everyone potentially interested was already sleeping <img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f609.png" alt="😉" class="wp-smiley" style="height: 1em; max-height: 1em;" /> I also didn&#8217;t establish any constant days on which posts on my blog were to be published. This was wrong. It&#8217;s another consequence of wrong planning.</p>
<h5>(-) Not promoting the blog enough</h5>
<p>In general, promotion of my blog posts boiled down to publishing the URLs on Twitter, Facebook and LinkedIn. By the end of DSP I realized the power of Reddit &#8211; it&#8217;s really worth thinking about promoting good content we produce there. I also could have been more involved in DSP channel on <a href="http://devspl.slack.com" target="_blank" rel="noopener noreferrer">Devs PL Slack</a> &#8211; many interesting discussions were held there and people got to know each other <img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f642.png" alt="🙂" class="wp-smiley" style="height: 1em; max-height: 1em;" /></p>
<h5>(-) Too long blog posts</h5>
<p>During few weeks in those 3 last months, I had really limited time to work on my DSP project &#8211; especially when it came to publishing a blog post, which was a mandatory requirement. Sometimes I really felt this is a <strong>mandatory requirement, not a pleasure. </strong>However, if I&#8217;d have written shorter blog posts, but maybe with a bit less of content, I wouldn&#8217;t have such feeling. When writing my posts I was many times starting a post with &#8220;In this short post (&#8230;)&#8221; and then, after 1 or 2 hours writing it, I came back to the introduction in order to remove the &#8220;short&#8221; word from it <img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f600.png" alt="😀" class="wp-smiley" style="height: 1em; max-height: 1em;" /></p>
<h5>(-) Fighting with &#8220;machines&#8221;</h5>
<p>That&#8217;s the part I surely never enjoy about the programming &#8211; fighting with weird, unknown issues met during development. Few weeks during the last 3 months were really hard in terms of time for the competition&#8217;s tasks, but some were really loose during which I was initially highly motivated to make a significant progress in development of <em>MoneyBack </em>app. However, then I was encountering mysterious problems with Xamarin, Visual Studio and other things which only made me really frustrated and burnt out all the motivation I&#8217;ve had. There are some positive aspects of it &#8211; for instance creating and self-answering <a href="https://stackoverflow.com/questions/43294345/visual-studio-2017-xamarin-the-file-obj-debug-android-bin-packaged-resource" target="_blank" rel="noopener noreferrer">a StackOverflow&#8217;s thread</a> which really bumped my statistics on that portal <img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f609.png" alt="😉" class="wp-smiley" style="height: 1em; max-height: 1em;" /></p>
<h2><span style="text-decoration: underline;">What I would change the next time</span></h2>
<p>If I take part in the competition again (next year, maybe? <img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f609.png" alt="😉" class="wp-smiley" style="height: 1em; max-height: 1em;" /> ), I&#8217;d obviously try to get rid of all above-mentioned bad aspects of my work. The must-dos for the next time are:</p>
<ul>
<li>plan the work from the beginning to the end of the competition (set concrete, long-perspective <strong>deadlines</strong>)</li>
<li>publish tasks list (like Trello board) in the beginning on the project so the deadlines set are &#8220;promised&#8221; publicly</li>
<li>set-up fixed days and times during the week when blog posts are published (use WordPress&#8217;s automatic delayed publishing)</li>
<li>write shorter blog posts that can be read in ~5 minutes with less, but more decent content</li>
<li>before using a particular solution for an issue, better examine the other possibilities, i.e. don&#8217;t choose to use the UI component firstly found in Xamarin docs (which are not always very good quality) &#8211; explore the other blog posts on that topic and see what other people used.</li>
</ul>
<h2>Summary &#8211; so what&#8217;s next?</h2>
<p>For sure I will still work on <em>MoneyBack</em> project. You can follow the progress <a href="https://github.com/dsibinski/MoneyBack" target="_blank" rel="noopener noreferrer">on its GitHub repository</a>. It&#8217;s a great app for pet-project which I was missing before.</p>
<p>Of course, I will also run this blog as I really enjoy sharing my knowledge here, both for the others and for myself to be able to refer back to it after some time.</p>
<p>I&#8217;d like to congratulate all DajSiePoznac2017&#8217;s participants for your endurance and the commitment we all did to both open-source world and programming blogosphere. I wish you all the best of luck in voting for the best DSP blog/project. Hopefully see you on 17.06.2017 in Warsaw on the official closing of the competition <img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f642.png" alt="🙂" class="wp-smiley" style="height: 1em; max-height: 1em;" /></p>
<p>I also want to say thank you to Daga who supported me in my way throughout the competition and many evenings spent on writing blog posts or programming <img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f642.png" alt="🙂" class="wp-smiley" style="height: 1em; max-height: 1em;" /></p>
<p>I&#8217;m also very grateful to all blog&#8217;s readers and supporters who left any feedback or comments here &#8211; your insights were very helpful!</p>
<p>See ya!</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>The post <a href="https://www.codejourney.net/dajsiepoznac2017-summary/">DajSiePoznac2017 &#8211; summary</a> appeared first on <a href="https://www.codejourney.net">CodeJourney.net</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.codejourney.net/dajsiepoznac2017-summary/feed/</wfw:commentRss>
			<slash:comments>4</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">2315</post-id>	</item>
		<item>
		<title>Xamarin.Android &#8211; debugging via WiFi</title>
		<link>https://www.codejourney.net/xamarin-android-debugging-via-wifi/</link>
					<comments>https://www.codejourney.net/xamarin-android-debugging-via-wifi/#comments</comments>
		
		<dc:creator><![CDATA[Dawid Sibiński]]></dc:creator>
		<pubDate>Tue, 30 May 2017 21:08:38 +0000</pubDate>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[android]]></category>
		<category><![CDATA[dajsiepoznac2017]]></category>
		<category><![CDATA[xamarin]]></category>
		<guid isPermaLink="false">http://www.dsibinski.pl/?p=2296</guid>

					<description><![CDATA[<p>In this short post, I&#8217;m going to show you a very handy feature of Android Debug Bridge (adb) &#8211; possibility to debug Xamarin.Android apps in Visual Studio via WiFi connection. Using ADB to debug Android apps By default, adb is configured to &#8220;map&#8221; Android devices connected via USB ports to the computer as debug devices, which are then&#8230;</p>
<p>The post <a href="https://www.codejourney.net/xamarin-android-debugging-via-wifi/">Xamarin.Android &#8211; debugging via WiFi</a> appeared first on <a href="https://www.codejourney.net">CodeJourney.net</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>In this short post, I&#8217;m going to show you a very handy feature of <a href="https://developer.android.com/studio/command-line/adb.html" target="_blank" rel="noopener noreferrer">Android Debug Bridge</a> (<em>adb</em>) &#8211; possibility to debug Xamarin.Android apps in Visual Studio via WiFi connection.<br />
<span id="more-2296"></span></p>
<h2>Using ADB to debug Android apps</h2>
<p>By default, <em>adb</em> is configured to &#8220;map&#8221; Android devices connected via USB ports to the computer as <em>debug devices</em>, which are then available e.g. in Visual Studio as the device on which our app can be deployed and debugged. In may cases we debug apps on Android emulators, which is frequently fair enough, but at some point we need to make our tests on a physical device.</p>
<p>It may not be very comfortable to have the phone connected using USB cable all the time, especially when testing some physical sensors like accelerometer or gyroscope. For such purposes, ADB gives us the possibility to connect Android devices via WiFi instead of USB. Let&#8217;s see how to configure it.</p>
<h2>Configure ADB to work on WiFi</h2>
<p>The first requirement is &#8211; obviously &#8211; that both our development PC and Android device must be connected to the same WiFi network. Then we need to find out what is the IP address of our Android device &#8211; it can be checked by going to <strong>Settings -&gt; WiFi -&gt; Menu &#8211; Advanced settings </strong>(Android 6.0):</p>
<figure id="attachment_2297" aria-describedby="caption-attachment-2297" style="width: 222px" class="wp-caption aligncenter"><a href="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/HuaweiP8_IP.png?ssl=1" target="_blank" rel="noopener noreferrer"><img data-recalc-dims="1" fetchpriority="high" decoding="async" data-attachment-id="2297" data-permalink="https://www.codejourney.net/xamarin-android-debugging-via-wifi/huaweip8_ip/" data-orig-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/HuaweiP8_IP.png?fit=1080%2C1920&amp;ssl=1" data-orig-size="1080,1920" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="HuaweiP8_IP" data-image-description="" data-image-caption="" data-large-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/HuaweiP8_IP.png?fit=576%2C1024&amp;ssl=1" class="wp-image-2297" src="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/HuaweiP8_IP.png?resize=222%2C394&#038;ssl=1" alt="" width="222" height="394" srcset="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/HuaweiP8_IP.png?resize=169%2C300&amp;ssl=1 169w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/HuaweiP8_IP.png?resize=768%2C1365&amp;ssl=1 768w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/HuaweiP8_IP.png?resize=576%2C1024&amp;ssl=1 576w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/HuaweiP8_IP.png?resize=720%2C1280&amp;ssl=1 720w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/HuaweiP8_IP.png?w=1080&amp;ssl=1 1080w" sizes="(max-width: 222px) 100vw, 222px" /></a><figcaption id="caption-attachment-2297" class="wp-caption-text">Android 6.0 &#8211; IP address</figcaption></figure>
<p>As soon as you have IP address of the device noted, <strong>connect it to the computer via USB port</strong>.</p>
<p>Now we need to use <em>adb.exe</em> to configure it for connecting with the device via WiFi. You can either add system environmental variable pointing to where the <em>adb.exe</em> is stored or just open <em>cmd</em>, go to the catalogue where it&#8217;s located (<em>Android\platform-tools\</em>) and execute the following commands:</p>
<ol>
<li>Change ADB to listen on TCP port:</li>
</ol>
<pre><pre class="brush: bash; title: ; notranslate">adb tcpip 5555</pre>
<p>This will make ADB listening on TCP port 5555 instead of USB ports (<strong>NOTE</strong>: since now the computer won&#8217;t listen to any devices connected by USB ports):</p>
<p><a href="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/cmd_1.png?ssl=1" target="_blank" rel="noopener noreferrer"><img data-recalc-dims="1" decoding="async" data-attachment-id="2307" data-permalink="https://www.codejourney.net/xamarin-android-debugging-via-wifi/cmd_1/" data-orig-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/cmd_1.png?fit=553%2C58&amp;ssl=1" data-orig-size="553,58" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="cmd_1" data-image-description="" data-image-caption="" data-large-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/cmd_1.png?fit=553%2C58&amp;ssl=1" class="aligncenter wp-image-2307" src="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/cmd_1.png?resize=319%2C33&#038;ssl=1" alt="" width="319" height="33" srcset="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/cmd_1.png?resize=300%2C31&amp;ssl=1 300w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/cmd_1.png?w=553&amp;ssl=1 553w" sizes="(max-width: 319px) 100vw, 319px" /></a></p>
<p>Now,<strong> disconnect the Android device from USB port</strong>.</p>
<p>2. Make ADB connect to your Android device:</p>
<pre><pre class="brush: bash; title: ; notranslate">adb connect 192.168.0.101:5555</pre>
<p>This command is used to connect to Android device (of course IP address must be changed with your device&#8217;s one) on port 5555 using WiFi:</p>
<p><a href="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/cmd_2.png?ssl=1" target="_blank" rel="noopener noreferrer"><img data-recalc-dims="1" decoding="async" data-attachment-id="2308" data-permalink="https://www.codejourney.net/xamarin-android-debugging-via-wifi/cmd_2/" data-orig-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/cmd_2.png?fit=723%2C55&amp;ssl=1" data-orig-size="723,55" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="cmd_2" data-image-description="" data-image-caption="" data-large-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/cmd_2.png?fit=723%2C55&amp;ssl=1" class="aligncenter wp-image-2308" src="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/cmd_2.png?resize=430%2C33&#038;ssl=1" alt="" width="430" height="33" srcset="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/cmd_2.png?resize=300%2C23&amp;ssl=1 300w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/cmd_2.png?resize=720%2C55&amp;ssl=1 720w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/cmd_2.png?w=723&amp;ssl=1 723w" sizes="(max-width: 430px) 100vw, 430px" /></a></p>
<p>
3. Since now you should see the device in Visual Studio connected using WiFi connection:</p>
<figure id="attachment_2309" aria-describedby="caption-attachment-2309" style="width: 671px" class="wp-caption aligncenter"><a href="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/Huawei_connectedWifi.png?ssl=1" target="_blank" rel="noopener noreferrer"><img data-recalc-dims="1" loading="lazy" decoding="async" data-attachment-id="2309" data-permalink="https://www.codejourney.net/xamarin-android-debugging-via-wifi/huawei_connectedwifi/" data-orig-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/Huawei_connectedWifi.png?fit=1150%2C65&amp;ssl=1" data-orig-size="1150,65" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="Huawei_connectedWifi" data-image-description="" data-image-caption="" data-large-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/Huawei_connectedWifi.png?fit=1024%2C58&amp;ssl=1" class="wp-image-2309" src="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/Huawei_connectedWifi.png?resize=671%2C38&#038;ssl=1" alt="" width="671" height="38" srcset="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/Huawei_connectedWifi.png?resize=300%2C17&amp;ssl=1 300w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/Huawei_connectedWifi.png?resize=768%2C43&amp;ssl=1 768w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/Huawei_connectedWifi.png?resize=1024%2C58&amp;ssl=1 1024w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/Huawei_connectedWifi.png?resize=720%2C41&amp;ssl=1 720w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/Huawei_connectedWifi.png?w=1150&amp;ssl=1 1150w" sizes="auto, (max-width: 671px) 100vw, 671px" /></a><figcaption id="caption-attachment-2309" class="wp-caption-text">WiFi Android device visible in Visual Studio</figcaption></figure>
<p>and you can of course deploy the app remotely on the device and debug it <img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f609.png" alt="😉" class="wp-smiley" style="height: 1em; max-height: 1em;" /></p>
<p>4. As soon as you&#8217;re done with WiFi debugging, run the following command:</p>
<pre><pre class="brush: bash; title: ; notranslate">adb usb</pre>
<p>It will make ADB listening for USB devices again:</p>
<p><a href="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/Commands_UsbRestored.jpg?ssl=1"><img data-recalc-dims="1" loading="lazy" decoding="async" data-attachment-id="2310" data-permalink="https://www.codejourney.net/xamarin-android-debugging-via-wifi/commands_usbrestored/" data-orig-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/Commands_UsbRestored.jpg?fit=479%2C55&amp;ssl=1" data-orig-size="479,55" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;Dawid Sibi\u0144ski&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;1496180723&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;1&quot;}" data-image-title="Commands_UsbRestored" data-image-description="" data-image-caption="" data-large-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/Commands_UsbRestored.jpg?fit=479%2C55&amp;ssl=1" class="aligncenter wp-image-2310" src="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/Commands_UsbRestored.jpg?resize=353%2C40&#038;ssl=1" alt="" width="353" height="40" srcset="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/Commands_UsbRestored.jpg?resize=300%2C34&amp;ssl=1 300w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/Commands_UsbRestored.jpg?w=479&amp;ssl=1 479w" sizes="auto, (max-width: 353px) 100vw, 353px" /></a></p>
<p><strong>TIP</strong>: if during performing any <em>cmd</em> commands <em>adb.exe </em>is stuck or not reacting, try plugging out and re-plugging in your Android device to USB port.</p>
<h2>Summary</h2>
<p>This post described how to use remote debugging on Android devices using WiFi connection.</p>
<p>I hope you&#8217;ll find it useful <img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f642.png" alt="🙂" class="wp-smiley" style="height: 1em; max-height: 1em;" /></p>
<p>The post <a href="https://www.codejourney.net/xamarin-android-debugging-via-wifi/">Xamarin.Android &#8211; debugging via WiFi</a> appeared first on <a href="https://www.codejourney.net">CodeJourney.net</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.codejourney.net/xamarin-android-debugging-via-wifi/feed/</wfw:commentRss>
			<slash:comments>4</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">2296</post-id>	</item>
		<item>
		<title>Managing Activity state changes using Bundle</title>
		<link>https://www.codejourney.net/managing-activity-state-changes-using-bundle/</link>
					<comments>https://www.codejourney.net/managing-activity-state-changes-using-bundle/#respond</comments>
		
		<dc:creator><![CDATA[Dawid Sibiński]]></dc:creator>
		<pubDate>Mon, 29 May 2017 21:28:42 +0000</pubDate>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[android]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[dajsiepoznac2017]]></category>
		<category><![CDATA[moneyback]]></category>
		<category><![CDATA[xamarin]]></category>
		<guid isPermaLink="false">http://www.dsibinski.pl/?p=2281</guid>

					<description><![CDATA[<p>Today we&#8217;re going to see how to manage (keep and restore) state of Activities in Xamarin.Android application in order to keep the app consistent and reactive for configuration/state changes. Why to keep and restore Activity&#8217;s state? As I already described in my post about Android Activities, the OS may react to some &#8220;constant&#8221; state changes&#8230;</p>
<p>The post <a href="https://www.codejourney.net/managing-activity-state-changes-using-bundle/">Managing Activity state changes using Bundle</a> appeared first on <a href="https://www.codejourney.net">CodeJourney.net</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Today we&#8217;re going to see how to manage (keep and restore) state of <a href="https://www.codejourney.net/2017/03/xamarin-android-activities/" target="_blank" rel="noopener noreferrer">Activities</a> in Xamarin.Android application in order to keep the app consistent and reactive for configuration/state changes.<br />
<span id="more-2281"></span></p>
<h2>Why to keep and restore Activity&#8217;s state?</h2>
<p>As I already described in <a href="https://www.codejourney.net/2017/03/xamarin-android-activities/" target="_blank" rel="noopener noreferrer">my post about Android Activities</a>, the OS may react to some &#8220;constant&#8221; state changes by calling lifecycle methods during Activity&#8217;s life, which may be overridden by the programmer in order to take some additional actions. However, there are some behaviors in Android apps that may change its configuration, after which the state of the Activity (for instance: arrangement or some UI elements or checkboxes&#8217; selections) may be lost if not handled properly.</p>
<p>To give you a real example: in <em>MoneyBack</em> application there is a main screen with two tabs. I noticed that when the second tab is selected:</p>
<figure id="attachment_2282" aria-describedby="caption-attachment-2282" style="width: 229px" class="wp-caption aligncenter"><a href="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/MoneyBack_SecondTab.png?ssl=1" target="_blank" rel="noopener noreferrer"><img data-recalc-dims="1" loading="lazy" decoding="async" data-attachment-id="2282" data-permalink="https://www.codejourney.net/managing-activity-state-changes-using-bundle/moneyback_secondtab/" data-orig-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/MoneyBack_SecondTab.png?fit=1080%2C1920&amp;ssl=1" data-orig-size="1080,1920" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="MoneyBack_SecondTab" data-image-description="" data-image-caption="" data-large-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/MoneyBack_SecondTab.png?fit=576%2C1024&amp;ssl=1" class="wp-image-2282" src="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/MoneyBack_SecondTab.png?resize=229%2C406&#038;ssl=1" alt="" width="229" height="406" srcset="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/MoneyBack_SecondTab.png?resize=169%2C300&amp;ssl=1 169w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/MoneyBack_SecondTab.png?resize=768%2C1365&amp;ssl=1 768w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/MoneyBack_SecondTab.png?resize=576%2C1024&amp;ssl=1 576w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/MoneyBack_SecondTab.png?resize=720%2C1280&amp;ssl=1 720w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/MoneyBack_SecondTab.png?w=1080&amp;ssl=1 1080w" sizes="auto, (max-width: 229px) 100vw, 229px" /></a><figcaption id="caption-attachment-2282" class="wp-caption-text"><em>MoneyBack</em> &#8211; 2nd tab selected</figcaption></figure>
<p>and the device is rotated:</p>
<figure id="attachment_2283" aria-describedby="caption-attachment-2283" style="width: 478px" class="wp-caption aligncenter"><a href="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/MoneyBack_AfterRotateFirstTab.png?ssl=1" target="_blank" rel="noopener noreferrer"><img data-recalc-dims="1" loading="lazy" decoding="async" data-attachment-id="2283" data-permalink="https://www.codejourney.net/managing-activity-state-changes-using-bundle/moneyback_afterrotatefirsttab/" data-orig-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/MoneyBack_AfterRotateFirstTab.png?fit=1920%2C1080&amp;ssl=1" data-orig-size="1920,1080" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="MoneyBack_AfterRotateFirstTab" data-image-description="" data-image-caption="&lt;p&gt;MoneyBack &amp;#8211; 1st tab selected after rotating&lt;/p&gt;
" data-large-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/MoneyBack_AfterRotateFirstTab.png?fit=1024%2C576&amp;ssl=1" class="wp-image-2283" src="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/MoneyBack_AfterRotateFirstTab.png?resize=478%2C269&#038;ssl=1" alt="" width="478" height="269" srcset="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/MoneyBack_AfterRotateFirstTab.png?resize=300%2C169&amp;ssl=1 300w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/MoneyBack_AfterRotateFirstTab.png?resize=768%2C432&amp;ssl=1 768w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/MoneyBack_AfterRotateFirstTab.png?resize=1024%2C576&amp;ssl=1 1024w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/MoneyBack_AfterRotateFirstTab.png?resize=720%2C405&amp;ssl=1 720w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/MoneyBack_AfterRotateFirstTab.png?w=1920&amp;ssl=1 1920w" sizes="auto, (max-width: 478px) 100vw, 478px" /></a><figcaption id="caption-attachment-2283" class="wp-caption-text"><em>MoneyBack</em> &#8211; 1st tab selected after rotating</figcaption></figure>
<p><strong>first tab becomes selected</strong>. User is losing his input (selection of the 2nd tab).</p>
<p>Screen orientation change is one of the reasons why we should care about saving and restoring Activities&#8217; states.</p>
<h2>Keeping state changes &#8211; OnSaveInstanceState()</h2>
<p>Each Activity allows us to override <span style="color: #ff9900;">OnSaveInstanceState(<span style="color: #ff6600;">Bundle</span> outState)</span> method, which is called when the current Activity is to be killed (e.g. when device&#8217;s screen orientation is changing or the Activity needs to be killed by Android in order to release some resources).</p>
<p><strong>Please don&#8217;t confuse it with Activity Lifecycle Methods</strong> (which I already described <a href="https://www.codejourney.net/2017/03/xamarin-android-activities/" target="_blank" rel="noopener noreferrer">here</a>), like <span style="color: #ff9900;">OnPause()</span> or <span style="color: #ff9900;">OnStop()</span> which are always called by the OS when particular action occurs. <span style="color: #ff9900;">OnSaveInstanceState()</span> method is <strong>generally</strong> called after <span style="color: #ff9900;">OnPause()</span> and before <span style="color: #ff9900;">OnStop()</span>, but <strong>it&#8217;s not always the case</strong>. For instance, it won&#8217;t be called at all when user navigates back from <em>ActivityB</em> to <em>ActivityA</em>, as in this case <em>ActivityB</em> will never be killed. More details can be found in <a href="https://developer.android.com/reference/android/app/Activity.html#onSaveInstanceState%28android.os.Bundle%29" target="_blank" rel="noopener noreferrer">official Android documentation</a>.</p>
<p><span style="color: #ff9900;">OnSaveInstanceState()</span> is called with <span style="color: #ff9900;">Bundle</span> parameter provided. It represents a simple key-value dictionary, which is additionally serialized, so it should be used for storing simple values like strings, integers etc. There are other structures and techniques for storing more complex data on state changes events (see the link in &#8220;Summary&#8221; section of this post).</p>
<p>In order to save currently selected tab, we can implement the method as follows:</p>
<p><style>.gist table { margin-bottom: 0; }</style>
<div style="tab-size: 8" id="gist48172254" class="gist">
<div class="gist-file" translate="no" data-color-mode="light" data-light-theme="light">
<div class="gist-data">
<div class="js-gist-file-update-container js-task-list-container">
<div id="file-onsaveinstancestate-cs" class="file my-2">
<div itemprop="text"
      class="Box-body p-0 blob-wrapper data type-c  "
      style="overflow: auto" tabindex="0" role="region"
      aria-label="OnSaveInstanceState.cs content, created by dsibinski on 08:28PM on May 29, 2017."
    ></p>
<div class="js-check-hidden-unicode js-blob-code-container blob-code-content">
<p>  <template class="js-file-alert-template"></p>
<div data-view-component="true" class="flash flash-warn flash-full d-flex flex-items-center">
  <svg aria-hidden="true" data-component="Octicon" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-alert">
    <path d="M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"></path>
</svg><br />
    <span><br />
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.<br />
      <a class="Link--inTextBlock" href="https://github.co/hiddenchars" target="_blank">Learn more about bidirectional Unicode characters</a><br />
    </span></p>
<div data-view-component="true" class="flash-action">        <a href="{{ revealButtonHref }}" data-view-component="true" class="btn-sm btn">    Show hidden characters<br />
</a>
</div>
</div>
<p></template><br />
<template class="js-line-alert-template"><br />
  <span aria-label="This line has hidden Unicode characters" data-view-component="true" class="line-alert tooltipped tooltipped-e"><br />
    <svg aria-hidden="true" data-component="Octicon" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-alert">
    <path d="M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"></path>
</svg><br />
</span></template></p>
<table data-hpc class="highlight tab-size js-file-line-container" data-tab-size="4" data-paste-markdown-skip data-tagsearch-path="OnSaveInstanceState.cs">
<tr>
<td id="file-onsaveinstancestate-cs-L1" class="blob-num js-line-number js-blob-rnum" data-line-number="1"></td>
<td id="file-onsaveinstancestate-cs-LC1" class="blob-code blob-code-inner js-file-line">  protected override void OnSaveInstanceState(Bundle outState)</td>
</tr>
<tr>
<td id="file-onsaveinstancestate-cs-L2" class="blob-num js-line-number js-blob-rnum" data-line-number="2"></td>
<td id="file-onsaveinstancestate-cs-LC2" class="blob-code blob-code-inner js-file-line">  {</td>
</tr>
<tr>
<td id="file-onsaveinstancestate-cs-L3" class="blob-num js-line-number js-blob-rnum" data-line-number="3"></td>
<td id="file-onsaveinstancestate-cs-LC3" class="blob-code blob-code-inner js-file-line">      var tabSelectedPosition = this.ActionBar.SelectedNavigationIndex;</td>
</tr>
<tr>
<td id="file-onsaveinstancestate-cs-L4" class="blob-num js-line-number js-blob-rnum" data-line-number="4"></td>
<td id="file-onsaveinstancestate-cs-LC4" class="blob-code blob-code-inner js-file-line">      outState.PutInt(&quot;selectedTabPosition&quot;, tabSelectedPosition);</td>
</tr>
<tr>
<td id="file-onsaveinstancestate-cs-L5" class="blob-num js-line-number js-blob-rnum" data-line-number="5"></td>
<td id="file-onsaveinstancestate-cs-LC5" class="blob-code blob-code-inner js-file-line">
</td>
</tr>
<tr>
<td id="file-onsaveinstancestate-cs-L6" class="blob-num js-line-number js-blob-rnum" data-line-number="6"></td>
<td id="file-onsaveinstancestate-cs-LC6" class="blob-code blob-code-inner js-file-line">      base.OnSaveInstanceState(outState);</td>
</tr>
<tr>
<td id="file-onsaveinstancestate-cs-L7" class="blob-num js-line-number js-blob-rnum" data-line-number="7"></td>
<td id="file-onsaveinstancestate-cs-LC7" class="blob-code blob-code-inner js-file-line">  }</td>
</tr>
</table>
</div></div>
</p></div>
</div></div>
<div class="gist-meta">
        <a href="https://gist.github.com/dsibinski/58260052f1fd8a7daffe99d4c63d634c/raw/1b9d19cc7369122ea997616b929899480521dc1e/OnSaveInstanceState.cs" style="float:right" class="Link--inTextBlock">view raw</a><br />
        <a href="https://gist.github.com/dsibinski/58260052f1fd8a7daffe99d4c63d634c#file-onsaveinstancestate-cs" class="Link--inTextBlock"><br />
          OnSaveInstanceState.cs<br />
        </a><br />
        hosted with &#10084; by <a class="Link--inTextBlock" href="https://github.com">GitHub</a>
      </div>
</p></div>
</div>
<p>Now, each screen orientation change will make this method called and the index of selected tab will be saved into <span style="color: #ff9900;">Bundle</span> <span style="color: #ff9900;">outState</span> dictionary under <em>&#8220;selectedTabPosition&#8221;</em> key.</p>
<h2>Restoring state changes &#8211; OnRestoreInstanceState()</h2>
<p>As soon as the Activity considered backs to life (is being resumed), <span style="color: #ff9900;">OnRestoreInstanceState(<span style="color: #ff6600;">Bundle</span> savedInstanceState)</span> method is called by the OS. <strong>It will only be called if there is a saved instance kept by calling <span style="color: #ff9900;">OnSaveInstanceState()</span> method before</strong>. As you can see, this method also comes with a <span style="color: #ff9900;">Bundle</span> parameter, which is the same key-value serialized dictionary we used for saving the Activity&#8217;s state.</p>
<p>In case of tabs selection restoring, we can implement this method as the following code presents:</p>
<p><style>.gist table { margin-bottom: 0; }</style>
<div style="tab-size: 8" id="gist48172407" class="gist">
<div class="gist-file" translate="no" data-color-mode="light" data-light-theme="light">
<div class="gist-data">
<div class="js-gist-file-update-container js-task-list-container">
<div id="file-onrestoreinstancestate-cs" class="file my-2">
<div itemprop="text"
      class="Box-body p-0 blob-wrapper data type-c  "
      style="overflow: auto" tabindex="0" role="region"
      aria-label="OnRestoreInstanceState.cs content, created by dsibinski on 08:34PM on May 29, 2017."
    ></p>
<div class="js-check-hidden-unicode js-blob-code-container blob-code-content">
<p>  <template class="js-file-alert-template"></p>
<div data-view-component="true" class="flash flash-warn flash-full d-flex flex-items-center">
  <svg aria-hidden="true" data-component="Octicon" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-alert">
    <path d="M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"></path>
</svg><br />
    <span><br />
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.<br />
      <a class="Link--inTextBlock" href="https://github.co/hiddenchars" target="_blank">Learn more about bidirectional Unicode characters</a><br />
    </span></p>
<div data-view-component="true" class="flash-action">        <a href="{{ revealButtonHref }}" data-view-component="true" class="btn-sm btn">    Show hidden characters<br />
</a>
</div>
</div>
<p></template><br />
<template class="js-line-alert-template"><br />
  <span aria-label="This line has hidden Unicode characters" data-view-component="true" class="line-alert tooltipped tooltipped-e"><br />
    <svg aria-hidden="true" data-component="Octicon" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-alert">
    <path d="M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"></path>
</svg><br />
</span></template></p>
<table data-hpc class="highlight tab-size js-file-line-container" data-tab-size="4" data-paste-markdown-skip data-tagsearch-path="OnRestoreInstanceState.cs">
<tr>
<td id="file-onrestoreinstancestate-cs-L1" class="blob-num js-line-number js-blob-rnum" data-line-number="1"></td>
<td id="file-onrestoreinstancestate-cs-LC1" class="blob-code blob-code-inner js-file-line">  protected override void OnRestoreInstanceState(Bundle savedInstanceState)</td>
</tr>
<tr>
<td id="file-onrestoreinstancestate-cs-L2" class="blob-num js-line-number js-blob-rnum" data-line-number="2"></td>
<td id="file-onrestoreinstancestate-cs-LC2" class="blob-code blob-code-inner js-file-line">  {</td>
</tr>
<tr>
<td id="file-onrestoreinstancestate-cs-L3" class="blob-num js-line-number js-blob-rnum" data-line-number="3"></td>
<td id="file-onrestoreinstancestate-cs-LC3" class="blob-code blob-code-inner js-file-line">      base.OnRestoreInstanceState(savedInstanceState);</td>
</tr>
<tr>
<td id="file-onrestoreinstancestate-cs-L4" class="blob-num js-line-number js-blob-rnum" data-line-number="4"></td>
<td id="file-onrestoreinstancestate-cs-LC4" class="blob-code blob-code-inner js-file-line">
</td>
</tr>
<tr>
<td id="file-onrestoreinstancestate-cs-L5" class="blob-num js-line-number js-blob-rnum" data-line-number="5"></td>
<td id="file-onrestoreinstancestate-cs-LC5" class="blob-code blob-code-inner js-file-line">      var previouslySelectedTabPosition = savedInstanceState.GetInt(&quot;selectedTabPosition&quot;, 0);</td>
</tr>
<tr>
<td id="file-onrestoreinstancestate-cs-L6" class="blob-num js-line-number js-blob-rnum" data-line-number="6"></td>
<td id="file-onrestoreinstancestate-cs-LC6" class="blob-code blob-code-inner js-file-line">      this.ActionBar.SetSelectedNavigationItem(previouslySelectedTabPosition);</td>
</tr>
<tr>
<td id="file-onrestoreinstancestate-cs-L7" class="blob-num js-line-number js-blob-rnum" data-line-number="7"></td>
<td id="file-onrestoreinstancestate-cs-LC7" class="blob-code blob-code-inner js-file-line">  }</td>
</tr>
</table>
</div></div>
</p></div>
</div></div>
<div class="gist-meta">
        <a href="https://gist.github.com/dsibinski/f620e7ae733cda6333cddd9abeced90c/raw/066fc7034dadbcfef47a358ec1c86bbb9a31b7f2/OnRestoreInstanceState.cs" style="float:right" class="Link--inTextBlock">view raw</a><br />
        <a href="https://gist.github.com/dsibinski/f620e7ae733cda6333cddd9abeced90c#file-onrestoreinstancestate-cs" class="Link--inTextBlock"><br />
          OnRestoreInstanceState.cs<br />
        </a><br />
        hosted with &#10084; by <a class="Link--inTextBlock" href="https://github.com">GitHub</a>
      </div>
</p></div>
</div>
<p><span style="color: #ff9900;">previouslySelectedTabPosition </span>variable will be initialized with integer value from <span style="color: #ff9900;">Bundle</span> dictionary saved under <em>&#8220;selectedTabPosition&#8221;</em> key, or default value (<em>0</em>) if nothing saved for the key is found.</p>
<p><strong>NOTE</strong>: <span style="color: #ff9900;">Bundle</span> parameter provided in <span style="color: #ff9900;">OnRestoreInstanceState()</span> is exactly the same, as the one available in <span style="color: #ff9900;">OnCreate(<span style="color: #ff6600;">Bundle</span> bundle)</span> method called on Activity&#8217;s creation. We could actually also retrieve our saved value there, but in many cases restoring the state (like selecting previously selected tab) requires some UI elements to be already initialized, which should be handled within <span style="color: #ff9900;">OnCreate()</span> method before. Because of that, I&#8217;d rather suggest to restore Activity&#8217;s state using <span style="color: #ff9900;">OnRestoreInstanceState()</span> as a general rule (of course there may be some exceptional cases <img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f609.png" alt="😉" class="wp-smiley" style="height: 1em; max-height: 1em;" /> ). <span style="color: #ff9900;">OnRestoreInstanceState()</span> will always be called <strong>after</strong> <span style="color: #ff9900;">OnCreate()</span>.</p>
<p>Moreover, if we wanted to use <span style="color: #ff9900;">Bundle</span> parameter in <span style="color: #ff9900;">OnCreate()</span> method, we&#8217;d need to check each time if <span style="color: #ff9900;">bundle</span> is not NULL (as we don&#8217;t know whether <span style="color: #ff9900;">OnSaveInstanceState()</span> had been called before).</p>
<p>As a result, the same tab as previously is selected even after rotating the device on <em>MoneyBack</em>&#8216;s <span style="color: #ff9900;">MainActivity</span>:</p>
<figure id="attachment_2287" aria-describedby="caption-attachment-2287" style="width: 826px" class="wp-caption aligncenter"><a href="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/MoneyBack_rotate2-1.png?ssl=1" target="_blank" rel="noopener noreferrer"><img data-recalc-dims="1" loading="lazy" decoding="async" data-attachment-id="2287" data-permalink="https://www.codejourney.net/managing-activity-state-changes-using-bundle/moneyback_rotate2-2/" data-orig-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/MoneyBack_rotate2-1.png?fit=4052%2C1968&amp;ssl=1" data-orig-size="4052,1968" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="MoneyBack_rotate2" data-image-description="" data-image-caption="" data-large-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/MoneyBack_rotate2-1.png?fit=1024%2C497&amp;ssl=1" class="wp-image-2287" src="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/MoneyBack_rotate2-1.png?resize=826%2C402&#038;ssl=1" alt="" width="826" height="402" srcset="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/MoneyBack_rotate2-1.png?resize=300%2C146&amp;ssl=1 300w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/MoneyBack_rotate2-1.png?resize=768%2C373&amp;ssl=1 768w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/MoneyBack_rotate2-1.png?resize=1024%2C497&amp;ssl=1 1024w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/MoneyBack_rotate2-1.png?resize=720%2C350&amp;ssl=1 720w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/MoneyBack_rotate2-1.png?w=2280&amp;ssl=1 2280w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/MoneyBack_rotate2-1.png?w=3420&amp;ssl=1 3420w" sizes="auto, (max-width: 826px) 100vw, 826px" /></a><figcaption id="caption-attachment-2287" class="wp-caption-text"><em>MoneyBack</em> &#8211; keeping tab selected when rotating</figcaption></figure>
<h2>&#8220;Automatic&#8221; state changes handled by Android OS</h2>
<p>Maybe you noticed in your Android application, that not every UI element needs to be handled &#8220;manually&#8221; by implementing the above-mentioned methods in order to save its state. Android performs some kind of &#8220;automatic&#8221; saving and restoration of basic UI elements&#8217; states.</p>
<p>The rule here is that as long as UI element (like <span style="color: #ff9900;">TextView</span> or <span style="color: #ff9900;">Button</span>) has its <span style="color: #ff9900;">android:id</span> set in <em>.axml</em> layout file, OS will automatically manage those elements&#8217; states (e.g. text entered into <span style="color: #ff9900;">EditText</span>).</p>
<p>For example, for <span style="color: #ff9900;">EditText</span> declared like that:</p>
<p><style>.gist table { margin-bottom: 0; }</style>
<div style="tab-size: 8" id="gist48172903" class="gist">
<div class="gist-file" translate="no" data-color-mode="light" data-light-theme="light">
<div class="gist-data">
<div class="js-gist-file-update-container js-task-list-container">
<div id="file-edittext-axml" class="file my-2">
<div itemprop="text"
      class="Box-body p-0 blob-wrapper data type-xml  "
      style="overflow: auto" tabindex="0" role="region"
      aria-label="EditText.axml content, created by dsibinski on 08:51PM on May 29, 2017."
    ></p>
<div class="js-check-hidden-unicode js-blob-code-container blob-code-content">
<p>  <template class="js-file-alert-template"></p>
<div data-view-component="true" class="flash flash-warn flash-full d-flex flex-items-center">
  <svg aria-hidden="true" data-component="Octicon" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-alert">
    <path d="M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"></path>
</svg><br />
    <span><br />
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.<br />
      <a class="Link--inTextBlock" href="https://github.co/hiddenchars" target="_blank">Learn more about bidirectional Unicode characters</a><br />
    </span></p>
<div data-view-component="true" class="flash-action">        <a href="{{ revealButtonHref }}" data-view-component="true" class="btn-sm btn">    Show hidden characters<br />
</a>
</div>
</div>
<p></template><br />
<template class="js-line-alert-template"><br />
  <span aria-label="This line has hidden Unicode characters" data-view-component="true" class="line-alert tooltipped tooltipped-e"><br />
    <svg aria-hidden="true" data-component="Octicon" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-alert">
    <path d="M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"></path>
</svg><br />
</span></template></p>
<table data-hpc class="highlight tab-size js-file-line-container" data-tab-size="4" data-paste-markdown-skip data-tagsearch-path="EditText.axml">
<tr>
<td id="file-edittext-axml-L1" class="blob-num js-line-number js-blob-rnum" data-line-number="1"></td>
<td id="file-edittext-axml-LC1" class="blob-code blob-code-inner js-file-line">  &lt;EditText</td>
</tr>
<tr>
<td id="file-edittext-axml-L2" class="blob-num js-line-number js-blob-rnum" data-line-number="2"></td>
<td id="file-edittext-axml-LC2" class="blob-code blob-code-inner js-file-line">  android:layout_width=&quot;match_parent&quot;</td>
</tr>
<tr>
<td id="file-edittext-axml-L3" class="blob-num js-line-number js-blob-rnum" data-line-number="3"></td>
<td id="file-edittext-axml-LC3" class="blob-code blob-code-inner js-file-line">  android:layout_height=&quot;wrap_content&quot;</td>
</tr>
<tr>
<td id="file-edittext-axml-L4" class="blob-num js-line-number js-blob-rnum" data-line-number="4"></td>
<td id="file-edittext-axml-LC4" class="blob-code blob-code-inner js-file-line">  android:id=&quot;@+id/inputEventName&quot;</td>
</tr>
<tr>
<td id="file-edittext-axml-L5" class="blob-num js-line-number js-blob-rnum" data-line-number="5"></td>
<td id="file-edittext-axml-LC5" class="blob-code blob-code-inner js-file-line">  android:fadingEdge=&quot;none&quot; /&gt;</td>
</tr>
</table>
</div></div>
</p></div>
</div></div>
<div class="gist-meta">
        <a href="https://gist.github.com/dsibinski/0b3920ba34d87ac7b8d70bab199dd430/raw/c41dc4d096994c0be50c064a2f3331c7e7a710d3/EditText.axml" style="float:right" class="Link--inTextBlock">view raw</a><br />
        <a href="https://gist.github.com/dsibinski/0b3920ba34d87ac7b8d70bab199dd430#file-edittext-axml" class="Link--inTextBlock"><br />
          EditText.axml<br />
        </a><br />
        hosted with &#10084; by <a class="Link--inTextBlock" href="https://github.com">GitHub</a>
      </div>
</p></div>
</div>
<p>its properties (especially its <strong>Text</strong> property) will be automatically saved and restored on screen orientation changes.</p>
<h2>Summary</h2>
<p>We&#8217;ve seen how to handle Android Activities&#8217; state changes caused by configuration modification (e.g. screen orientation change, Activity being killed by the OS in order to free some resources etc.) by implementing <span style="color: #ff9900;">OnSaveInstanceState()</span> and <span style="color: #ff9900;">OnRestoreInstanceState()</span>, where we added and retrieved key-value data to/from <span style="color: #ff9900;">Bundle</span> serialized dictionary. We just need to remember that those methods are not always called (e.g. when navigating between Activities using &#8220;back&#8221; button), so these should be used only for certain kind of state changes.</p>
<p>We&#8217;ve also seen that UI controls with their <span style="color: #ff9900;">android:id</span> defined in layout files have their states <em>resistant</em> for configuration changes (handled automatically by Android OS).</p>
<p><span style="color: #ff9900;">Bundle</span> dictionary is serialized for better performance and memory utilization, so only simple-typed values should be stored in it (like strings or integers). In order to store more complex data, Android provides different possibilities of managing it (e.g. using <a href="https://developer.android.com/reference/android/app/Activity.html#onRetainNonConfigurationInstance()" target="_blank" rel="noopener noreferrer">OnRetainNonConfigurationInstance</a>).</p>
<p>The post <a href="https://www.codejourney.net/managing-activity-state-changes-using-bundle/">Managing Activity state changes using Bundle</a> appeared first on <a href="https://www.codejourney.net">CodeJourney.net</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.codejourney.net/managing-activity-state-changes-using-bundle/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">2281</post-id>	</item>
		<item>
		<title>Date selection using DatePickerDialog in Xamarin.Android</title>
		<link>https://www.codejourney.net/date-selection-using-datepickerdialog-in-xamarin-android/</link>
					<comments>https://www.codejourney.net/date-selection-using-datepickerdialog-in-xamarin-android/#respond</comments>
		
		<dc:creator><![CDATA[Dawid Sibiński]]></dc:creator>
		<pubDate>Sat, 27 May 2017 13:19:47 +0000</pubDate>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[android]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[dajsiepoznac2017]]></category>
		<category><![CDATA[moneyback]]></category>
		<category><![CDATA[xamarin]]></category>
		<guid isPermaLink="false">http://www.dsibinski.pl/?p=2266</guid>

					<description><![CDATA[<p>In this post, we&#8217;re going to see how to provide a nice Android UI control for selecting the date using DatePickerDialog. The dialog looks as follows: It may be opened e.g. when clicking on a button in the app, as I used it in MoneyBack. Creating DatePickerFragment First of all, we will implement the dialog to be displayed&#8230;</p>
<p>The post <a href="https://www.codejourney.net/date-selection-using-datepickerdialog-in-xamarin-android/">Date selection using DatePickerDialog in Xamarin.Android</a> appeared first on <a href="https://www.codejourney.net">CodeJourney.net</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>In this post, we&#8217;re going to see how to provide a nice Android UI control for selecting the date using <span style="color: #ff9900;">DatePickerDialog</span>.<br />
<span id="more-2266"></span></p>
<p>The dialog looks as follows:</p>
<figure id="attachment_2267" aria-describedby="caption-attachment-2267" style="width: 238px" class="wp-caption aligncenter"><a href="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/Event_DatePicker.png?ssl=1" target="_blank" rel="noopener noreferrer"><img data-recalc-dims="1" loading="lazy" decoding="async" data-attachment-id="2267" data-permalink="https://www.codejourney.net/date-selection-using-datepickerdialog-in-xamarin-android/event_datepicker/" data-orig-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/Event_DatePicker.png?fit=1080%2C1920&amp;ssl=1" data-orig-size="1080,1920" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="Event_DatePicker" data-image-description="" data-image-caption="" data-large-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/Event_DatePicker.png?fit=576%2C1024&amp;ssl=1" class="wp-image-2267 " src="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/Event_DatePicker.png?resize=238%2C423&#038;ssl=1" alt="" width="238" height="423" srcset="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/Event_DatePicker.png?resize=169%2C300&amp;ssl=1 169w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/Event_DatePicker.png?resize=768%2C1365&amp;ssl=1 768w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/Event_DatePicker.png?resize=576%2C1024&amp;ssl=1 576w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/Event_DatePicker.png?resize=720%2C1280&amp;ssl=1 720w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/Event_DatePicker.png?w=1080&amp;ssl=1 1080w" sizes="auto, (max-width: 238px) 100vw, 238px" /></a><figcaption id="caption-attachment-2267" class="wp-caption-text">DatePickerDialog</figcaption></figure>
<p>It may be opened e.g. when clicking on a button in the app, as I used it in <em>MoneyBack</em>.</p>
<h2>Creating DatePickerFragment</h2>
<p>First of all, we will implement the dialog to be displayed within <span style="color: #ff6600;">DialogFragment.</span> Doing that our dialog will be able to be displayed as independent piece of UI on the top of any Activity.</p>
<p>The second requirement is to implement <span style="color: #ff6600;">IOnDateSetListener</span> interface (coming from Java/Android), which provides a callback on date selection action done by the user.</p>
<p>The <span style="color: #ff6600;">DatePickerFragment</span> meeting those two requirements may look as follows:</p>
<p><style>.gist table { margin-bottom: 0; }</style>
<div style="tab-size: 8" id="gist48103396" class="gist">
<div class="gist-file" translate="no" data-color-mode="light" data-light-theme="light">
<div class="gist-data">
<div class="js-gist-file-update-container js-task-list-container">
<div id="file-datepickerfragment-cs" class="file my-2">
<div itemprop="text"
      class="Box-body p-0 blob-wrapper data type-c  "
      style="overflow: auto" tabindex="0" role="region"
      aria-label="DatePickerFragment.cs content, created by dsibinski on 12:35PM on May 27, 2017."
    ></p>
<div class="js-check-hidden-unicode js-blob-code-container blob-code-content">
<p>  <template class="js-file-alert-template"></p>
<div data-view-component="true" class="flash flash-warn flash-full d-flex flex-items-center">
  <svg aria-hidden="true" data-component="Octicon" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-alert">
    <path d="M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"></path>
</svg><br />
    <span><br />
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.<br />
      <a class="Link--inTextBlock" href="https://github.co/hiddenchars" target="_blank">Learn more about bidirectional Unicode characters</a><br />
    </span></p>
<div data-view-component="true" class="flash-action">        <a href="{{ revealButtonHref }}" data-view-component="true" class="btn-sm btn">    Show hidden characters<br />
</a>
</div>
</div>
<p></template><br />
<template class="js-line-alert-template"><br />
  <span aria-label="This line has hidden Unicode characters" data-view-component="true" class="line-alert tooltipped tooltipped-e"><br />
    <svg aria-hidden="true" data-component="Octicon" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-alert">
    <path d="M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"></path>
</svg><br />
</span></template></p>
<table data-hpc class="highlight tab-size js-file-line-container" data-tab-size="4" data-paste-markdown-skip data-tagsearch-path="DatePickerFragment.cs">
<tr>
<td id="file-datepickerfragment-cs-L1" class="blob-num js-line-number js-blob-rnum" data-line-number="1"></td>
<td id="file-datepickerfragment-cs-LC1" class="blob-code blob-code-inner js-file-line">  public class DatePickerFragment : DialogFragment, DatePickerDialog.IOnDateSetListener</td>
</tr>
<tr>
<td id="file-datepickerfragment-cs-L2" class="blob-num js-line-number js-blob-rnum" data-line-number="2"></td>
<td id="file-datepickerfragment-cs-LC2" class="blob-code blob-code-inner js-file-line">  {</td>
</tr>
<tr>
<td id="file-datepickerfragment-cs-L3" class="blob-num js-line-number js-blob-rnum" data-line-number="3"></td>
<td id="file-datepickerfragment-cs-LC3" class="blob-code blob-code-inner js-file-line">      public static readonly string TAG = &quot;X:&quot; + typeof(DatePickerFragment).Name.ToUpper();</td>
</tr>
<tr>
<td id="file-datepickerfragment-cs-L4" class="blob-num js-line-number js-blob-rnum" data-line-number="4"></td>
<td id="file-datepickerfragment-cs-LC4" class="blob-code blob-code-inner js-file-line">
</td>
</tr>
<tr>
<td id="file-datepickerfragment-cs-L5" class="blob-num js-line-number js-blob-rnum" data-line-number="5"></td>
<td id="file-datepickerfragment-cs-LC5" class="blob-code blob-code-inner js-file-line">      Action&lt;DateTime&gt; _dateSelectedHandler = delegate { };</td>
</tr>
<tr>
<td id="file-datepickerfragment-cs-L6" class="blob-num js-line-number js-blob-rnum" data-line-number="6"></td>
<td id="file-datepickerfragment-cs-LC6" class="blob-code blob-code-inner js-file-line">
</td>
</tr>
<tr>
<td id="file-datepickerfragment-cs-L7" class="blob-num js-line-number js-blob-rnum" data-line-number="7"></td>
<td id="file-datepickerfragment-cs-LC7" class="blob-code blob-code-inner js-file-line">      public DatePickerFragment(Action&lt;DateTime&gt; onDateSelected)</td>
</tr>
<tr>
<td id="file-datepickerfragment-cs-L8" class="blob-num js-line-number js-blob-rnum" data-line-number="8"></td>
<td id="file-datepickerfragment-cs-LC8" class="blob-code blob-code-inner js-file-line">      {</td>
</tr>
<tr>
<td id="file-datepickerfragment-cs-L9" class="blob-num js-line-number js-blob-rnum" data-line-number="9"></td>
<td id="file-datepickerfragment-cs-LC9" class="blob-code blob-code-inner js-file-line">          _dateSelectedHandler = onDateSelected;</td>
</tr>
<tr>
<td id="file-datepickerfragment-cs-L10" class="blob-num js-line-number js-blob-rnum" data-line-number="10"></td>
<td id="file-datepickerfragment-cs-LC10" class="blob-code blob-code-inner js-file-line">      }</td>
</tr>
<tr>
<td id="file-datepickerfragment-cs-L11" class="blob-num js-line-number js-blob-rnum" data-line-number="11"></td>
<td id="file-datepickerfragment-cs-LC11" class="blob-code blob-code-inner js-file-line">
</td>
</tr>
<tr>
<td id="file-datepickerfragment-cs-L12" class="blob-num js-line-number js-blob-rnum" data-line-number="12"></td>
<td id="file-datepickerfragment-cs-LC12" class="blob-code blob-code-inner js-file-line">      public override Dialog OnCreateDialog(Bundle savedInstanceState)</td>
</tr>
<tr>
<td id="file-datepickerfragment-cs-L13" class="blob-num js-line-number js-blob-rnum" data-line-number="13"></td>
<td id="file-datepickerfragment-cs-LC13" class="blob-code blob-code-inner js-file-line">      {</td>
</tr>
<tr>
<td id="file-datepickerfragment-cs-L14" class="blob-num js-line-number js-blob-rnum" data-line-number="14"></td>
<td id="file-datepickerfragment-cs-LC14" class="blob-code blob-code-inner js-file-line">          DateTime now = DateTime.Now;</td>
</tr>
<tr>
<td id="file-datepickerfragment-cs-L15" class="blob-num js-line-number js-blob-rnum" data-line-number="15"></td>
<td id="file-datepickerfragment-cs-LC15" class="blob-code blob-code-inner js-file-line">          return new DatePickerDialog(Activity, </td>
</tr>
<tr>
<td id="file-datepickerfragment-cs-L16" class="blob-num js-line-number js-blob-rnum" data-line-number="16"></td>
<td id="file-datepickerfragment-cs-LC16" class="blob-code blob-code-inner js-file-line">              this,</td>
</tr>
<tr>
<td id="file-datepickerfragment-cs-L17" class="blob-num js-line-number js-blob-rnum" data-line-number="17"></td>
<td id="file-datepickerfragment-cs-LC17" class="blob-code blob-code-inner js-file-line">              now.Year,</td>
</tr>
<tr>
<td id="file-datepickerfragment-cs-L18" class="blob-num js-line-number js-blob-rnum" data-line-number="18"></td>
<td id="file-datepickerfragment-cs-LC18" class="blob-code blob-code-inner js-file-line">              now.Month,</td>
</tr>
<tr>
<td id="file-datepickerfragment-cs-L19" class="blob-num js-line-number js-blob-rnum" data-line-number="19"></td>
<td id="file-datepickerfragment-cs-LC19" class="blob-code blob-code-inner js-file-line">              now.Day);</td>
</tr>
<tr>
<td id="file-datepickerfragment-cs-L20" class="blob-num js-line-number js-blob-rnum" data-line-number="20"></td>
<td id="file-datepickerfragment-cs-LC20" class="blob-code blob-code-inner js-file-line">      }</td>
</tr>
<tr>
<td id="file-datepickerfragment-cs-L21" class="blob-num js-line-number js-blob-rnum" data-line-number="21"></td>
<td id="file-datepickerfragment-cs-LC21" class="blob-code blob-code-inner js-file-line">
</td>
</tr>
<tr>
<td id="file-datepickerfragment-cs-L22" class="blob-num js-line-number js-blob-rnum" data-line-number="22"></td>
<td id="file-datepickerfragment-cs-LC22" class="blob-code blob-code-inner js-file-line">      public void OnDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth)</td>
</tr>
<tr>
<td id="file-datepickerfragment-cs-L23" class="blob-num js-line-number js-blob-rnum" data-line-number="23"></td>
<td id="file-datepickerfragment-cs-LC23" class="blob-code blob-code-inner js-file-line">      {</td>
</tr>
<tr>
<td id="file-datepickerfragment-cs-L24" class="blob-num js-line-number js-blob-rnum" data-line-number="24"></td>
<td id="file-datepickerfragment-cs-LC24" class="blob-code blob-code-inner js-file-line">          DateTime selectedDate = new DateTime(year, monthOfYear + 1, dayOfMonth);</td>
</tr>
<tr>
<td id="file-datepickerfragment-cs-L25" class="blob-num js-line-number js-blob-rnum" data-line-number="25"></td>
<td id="file-datepickerfragment-cs-LC25" class="blob-code blob-code-inner js-file-line">          _dateSelectedHandler(selectedDate);</td>
</tr>
<tr>
<td id="file-datepickerfragment-cs-L26" class="blob-num js-line-number js-blob-rnum" data-line-number="26"></td>
<td id="file-datepickerfragment-cs-LC26" class="blob-code blob-code-inner js-file-line">      }</td>
</tr>
<tr>
<td id="file-datepickerfragment-cs-L27" class="blob-num js-line-number js-blob-rnum" data-line-number="27"></td>
<td id="file-datepickerfragment-cs-LC27" class="blob-code blob-code-inner js-file-line">  }</td>
</tr>
</table>
</div></div>
</p></div>
</div></div>
<div class="gist-meta">
        <a href="https://gist.github.com/dsibinski/6bddb5f760a83b1d190d7d20362f1546/raw/eb5d54ac22e31860c2925eaa58ec078d545d43d2/DatePickerFragment.cs" style="float:right" class="Link--inTextBlock">view raw</a><br />
        <a href="https://gist.github.com/dsibinski/6bddb5f760a83b1d190d7d20362f1546#file-datepickerfragment-cs" class="Link--inTextBlock"><br />
          DatePickerFragment.cs<br />
        </a><br />
        hosted with &#10084; by <a class="Link--inTextBlock" href="https://github.com">GitHub</a>
      </div>
</p></div>
</div>
<p>There are few crucial parts in above-listed class:</p>
<ul>
<li>Line 1: as said before, the class derives from <span style="color: #ff6600;">DialogFragment</span> and implements <span style="color: #ff6600;">IOnDateSetListener</span> interface</li>
<li>Line 3: here we have <span style="color: #ff6600;">public static readonly string TAG</span> variable defined &#8211; it is used as a unique identifier of the <span style="color: #ff6600;">Fragment</span>; in some cases, <span style="color: #ff6600;">Fragments</span> can be displayed without any UI &#8211; in such case the only possibility to identify and get the <span style="color: #ff6600;">Fragment</span> is by using <a href="https://developer.android.com/reference/android/app/FragmentManager.html#findFragmentByTag(java.lang.String)" target="_blank" rel="noopener noreferrer">findFragmentByTag()</a> method</li>
<li>Lines 5-10: define <span style="color: #ff6600;">_dateSelectedHandler</span> delegate which may be provided to the constructor of our <span style="color: #ff6600;">DatePickerFragment</span> with the method to be called-back when user selects a date</li>
<li>Lines 12-20: inheriting from <span style="color: #ff6600;">DialogFragment</span> allows us to override its <a href="https://developer.android.com/reference/android/app/DialogFragment.html#Lifecycle" target="_blank" rel="noopener noreferrer">lifecycle methods</a> &#8211; one of them is <span style="color: #ff6600;">Dialog <span style="color: #993300;">OnCreateDialog</span>(Bundle <span style="color: #993300;">savedInstanceState</span>)</span>, in which we actually create the <span style="color: #ff6600;">Dialog</span>-inheriting class &#8211; in our case &#8211; <span style="color: #ff6600;">DatePickerDialog</span> &#8211; with initially selected date (set to current date in the provided example)</li>
<li>Lines 22-26: implementing <span style="color: #ff9900;">IOnDateSetListener </span>interface requires to implement <span style="color: #ff9900;">OnDateSet</span> method, which is called when the user selects the date and clicks &#8220;OK&#8221; button;<b><br />
NOTE</b>: one of this method&#8217;s arguments is <span style="color: #ff9900;">monthOfYear</span> integer value, which contains month number expressed as values 0-11 (NOT 1-12) for compatibility with <a href="https://developer.android.com/reference/java/util/Calendar.html#MONTH" target="_blank" rel="noopener noreferrer">java.util.Calendar.MONTH</a></li>
</ul>
<h2>Using DatePickerFragment</h2>
<p>In <em>MoneyBack</em> application I&#8217;ve used <span style="color: #ff9900;">DatePickerFragment</span> on creating/modifying an event, when user needs to select its date:</p>
<figure id="attachment_2275" aria-describedby="caption-attachment-2275" style="width: 223px" class="wp-caption aligncenter"><a href="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/Event_DateSelection.png?ssl=1" target="_blank" rel="noopener noreferrer"><img data-recalc-dims="1" loading="lazy" decoding="async" data-attachment-id="2275" data-permalink="https://www.codejourney.net/date-selection-using-datepickerdialog-in-xamarin-android/event_dateselection/" data-orig-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/Event_DateSelection.png?fit=1080%2C1920&amp;ssl=1" data-orig-size="1080,1920" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="Event_DateSelection" data-image-description="" data-image-caption="" data-large-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/Event_DateSelection.png?fit=576%2C1024&amp;ssl=1" class="wp-image-2275" src="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/Event_DateSelection.png?resize=223%2C396&#038;ssl=1" alt="" width="223" height="396" srcset="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/Event_DateSelection.png?resize=169%2C300&amp;ssl=1 169w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/Event_DateSelection.png?resize=768%2C1365&amp;ssl=1 768w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/Event_DateSelection.png?resize=576%2C1024&amp;ssl=1 576w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/Event_DateSelection.png?resize=720%2C1280&amp;ssl=1 720w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/Event_DateSelection.png?w=1080&amp;ssl=1 1080w" sizes="auto, (max-width: 223px) 100vw, 223px" /></a><figcaption id="caption-attachment-2275" class="wp-caption-text"><em>MoneyBack</em> &#8211; event&#8217;s date selection</figcaption></figure>
<p>As soon as the button is clicked, the following code executes:</p>
<p><style>.gist table { margin-bottom: 0; }</style>
<div style="tab-size: 8" id="gist48103872" class="gist">
<div class="gist-file" translate="no" data-color-mode="light" data-light-theme="light">
<div class="gist-data">
<div class="js-gist-file-update-container js-task-list-container">
<div id="file-eventdetailsactivity_dateclick-cs" class="file my-2">
<div itemprop="text"
      class="Box-body p-0 blob-wrapper data type-c  "
      style="overflow: auto" tabindex="0" role="region"
      aria-label="EventDetailsActivity_DateClick.cs content, created by dsibinski on 12:57PM on May 27, 2017."
    ></p>
<div class="js-check-hidden-unicode js-blob-code-container blob-code-content">
<p>  <template class="js-file-alert-template"></p>
<div data-view-component="true" class="flash flash-warn flash-full d-flex flex-items-center">
  <svg aria-hidden="true" data-component="Octicon" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-alert">
    <path d="M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"></path>
</svg><br />
    <span><br />
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.<br />
      <a class="Link--inTextBlock" href="https://github.co/hiddenchars" target="_blank">Learn more about bidirectional Unicode characters</a><br />
    </span></p>
<div data-view-component="true" class="flash-action">        <a href="{{ revealButtonHref }}" data-view-component="true" class="btn-sm btn">    Show hidden characters<br />
</a>
</div>
</div>
<p></template><br />
<template class="js-line-alert-template"><br />
  <span aria-label="This line has hidden Unicode characters" data-view-component="true" class="line-alert tooltipped tooltipped-e"><br />
    <svg aria-hidden="true" data-component="Octicon" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-alert">
    <path d="M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"></path>
</svg><br />
</span></template></p>
<table data-hpc class="highlight tab-size js-file-line-container" data-tab-size="4" data-paste-markdown-skip data-tagsearch-path="EventDetailsActivity_DateClick.cs">
<tr>
<td id="file-eventdetailsactivity_dateclick-cs-L1" class="blob-num js-line-number js-blob-rnum" data-line-number="1"></td>
<td id="file-eventdetailsactivity_dateclick-cs-LC1" class="blob-code blob-code-inner js-file-line">  private void _btnSelectDate_Click(object sender, EventArgs e)</td>
</tr>
<tr>
<td id="file-eventdetailsactivity_dateclick-cs-L2" class="blob-num js-line-number js-blob-rnum" data-line-number="2"></td>
<td id="file-eventdetailsactivity_dateclick-cs-LC2" class="blob-code blob-code-inner js-file-line">  {</td>
</tr>
<tr>
<td id="file-eventdetailsactivity_dateclick-cs-L3" class="blob-num js-line-number js-blob-rnum" data-line-number="3"></td>
<td id="file-eventdetailsactivity_dateclick-cs-LC3" class="blob-code blob-code-inner js-file-line">      new DatePickerFragment(delegate(DateTime time)</td>
</tr>
<tr>
<td id="file-eventdetailsactivity_dateclick-cs-L4" class="blob-num js-line-number js-blob-rnum" data-line-number="4"></td>
<td id="file-eventdetailsactivity_dateclick-cs-LC4" class="blob-code blob-code-inner js-file-line">          {</td>
</tr>
<tr>
<td id="file-eventdetailsactivity_dateclick-cs-L5" class="blob-num js-line-number js-blob-rnum" data-line-number="5"></td>
<td id="file-eventdetailsactivity_dateclick-cs-LC5" class="blob-code blob-code-inner js-file-line">              _selectedDate = time;</td>
</tr>
<tr>
<td id="file-eventdetailsactivity_dateclick-cs-L6" class="blob-num js-line-number js-blob-rnum" data-line-number="6"></td>
<td id="file-eventdetailsactivity_dateclick-cs-LC6" class="blob-code blob-code-inner js-file-line">              _btnSelectDate.Text = _selectedDate.ToLongDateString();</td>
</tr>
<tr>
<td id="file-eventdetailsactivity_dateclick-cs-L7" class="blob-num js-line-number js-blob-rnum" data-line-number="7"></td>
<td id="file-eventdetailsactivity_dateclick-cs-LC7" class="blob-code blob-code-inner js-file-line">          })</td>
</tr>
<tr>
<td id="file-eventdetailsactivity_dateclick-cs-L8" class="blob-num js-line-number js-blob-rnum" data-line-number="8"></td>
<td id="file-eventdetailsactivity_dateclick-cs-LC8" class="blob-code blob-code-inner js-file-line">          .Show(FragmentManager, DatePickerFragment.TAG);</td>
</tr>
<tr>
<td id="file-eventdetailsactivity_dateclick-cs-L9" class="blob-num js-line-number js-blob-rnum" data-line-number="9"></td>
<td id="file-eventdetailsactivity_dateclick-cs-LC9" class="blob-code blob-code-inner js-file-line">  }</td>
</tr>
</table>
</div></div>
</p></div>
</div></div>
<div class="gist-meta">
        <a href="https://gist.github.com/dsibinski/930a05f6a51752d773651941b1dd5135/raw/4ef6b702c3c5ee9580a66ee6aef6310772856ad7/EventDetailsActivity_DateClick.cs" style="float:right" class="Link--inTextBlock">view raw</a><br />
        <a href="https://gist.github.com/dsibinski/930a05f6a51752d773651941b1dd5135#file-eventdetailsactivity_dateclick-cs" class="Link--inTextBlock"><br />
          EventDetailsActivity_DateClick.cs<br />
        </a><br />
        hosted with &#10084; by <a class="Link--inTextBlock" href="https://github.com">GitHub</a>
      </div>
</p></div>
</div>
<p>As you can see, to <span style="color: #ff9900;">DatePickerFragment</span>&#8216;s constructor I&#8217;m providing the delegate with a method to be called when the date is selected by the user (setting <span style="color: #ff9900;">_selectedDate</span> property with selected <span style="color: #ff9900;">time</span> and putting the date in short format as button&#8217;s <span style="color: #ff9900;">Text</span>).</p>
<p>In order to display a dialog, <a href="https://developer.android.com/reference/android/app/DialogFragment.html#show(android.app.FragmentManager, java.lang.String)" target="_blank" rel="noopener noreferrer">Show</a> method is called, taking current <span style="color: #ff9900;">FragmentManager</span> and already mentioned per-Fragment-unique <span style="color: #ff9900;">tag string</span>, defined statically in <span style="color: #ff9900;">DatePickerFragment</span> class.</p>
<h2>Summary</h2>
<p>Today&#8217;s short post presented how to easily create a <span style="color: #ff9900;">DialogFragment</span> showing <span style="color: #ff9900;">DatePickerDialog</span> for date selection, which allows to provide any method to be called-back when the date is selected by the user.</p>
<p>I hope you&#8217;ll find it useful <img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f609.png" alt="😉" class="wp-smiley" style="height: 1em; max-height: 1em;" /></p>
<p>The post <a href="https://www.codejourney.net/date-selection-using-datepickerdialog-in-xamarin-android/">Date selection using DatePickerDialog in Xamarin.Android</a> appeared first on <a href="https://www.codejourney.net">CodeJourney.net</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.codejourney.net/date-selection-using-datepickerdialog-in-xamarin-android/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">2266</post-id>	</item>
		<item>
		<title>SQLite-Net Extensions – one-to-many relationships</title>
		<link>https://www.codejourney.net/sqlite-net-extensions-one-to-many-relationships/</link>
					<comments>https://www.codejourney.net/sqlite-net-extensions-one-to-many-relationships/#comments</comments>
		
		<dc:creator><![CDATA[Dawid Sibiński]]></dc:creator>
		<pubDate>Mon, 22 May 2017 22:01:46 +0000</pubDate>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[android]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[dajsiepoznac2017]]></category>
		<category><![CDATA[sqlite-net-extensions]]></category>
		<category><![CDATA[xamarin]]></category>
		<guid isPermaLink="false">http://www.dsibinski.pl/?p=2251</guid>

					<description><![CDATA[<p>In the 3rd post from SQLite-Net Extensions series we are covering the last type of relationship &#8211; one-to-many (and the opposite &#8211; many-to-one). One-to-many, many-to-one One-to-many relationships are used in general for parent-children or whole-elements relations. Classic examples are: bus and passengers, document and elements etc. One-to-many relationship means that the one-end entity knows about its&#8230;</p>
<p>The post <a href="https://www.codejourney.net/sqlite-net-extensions-one-to-many-relationships/">SQLite-Net Extensions – one-to-many relationships</a> appeared first on <a href="https://www.codejourney.net">CodeJourney.net</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>In the 3rd post from <a href="https://www.codejourney.net/tag/sqlite-net-extensions/" target="_blank" rel="noopener noreferrer">SQLite-Net Extensions series</a> we are covering the last type of relationship &#8211; <em>one-to-many</em> (and the opposite &#8211; <em>many-to-one</em>).<br />
<span id="more-2251"></span></p>
<h2>One-to-many, many-to-one</h2>
<p><strong>One-to-many</strong> relationships are used in general for <em>parent-children</em> or <em>whole-elements</em> relations. Classic examples are: bus and passengers, document and elements etc.</p>
<p>One-to-many relationship means that the <em>one-end</em> entity knows about its children and <em>many-end</em> entity has a reference (foreign key) to its parent (but not necessarily <span style="text-decoration: underline;">knows</span> about it).</p>
<p>On the other hand, the opposite relationship to one-to-many is <strong>many-to-one</strong>. In that case, <em>many-end</em> entity has a reference to its parent and <span style="text-decoration: underline;">knows </span>about it, but the <em>one-end</em> entity doesn&#8217;t necessarily <span style="text-decoration: underline;">know</span> about its children (at least not directly).</p>
<p>I used a verb <span style="text-decoration: underline;">to know</span> several times &#8211; so it&#8217;s time to explain it 🙂 By &#8220;knowing&#8221; about the other end of a relationship I understand <span style="text-decoration: underline;">having a reference to it</span>. It means that, for instance, in many-to-one relationship, the one-end of it doesn&#8217;t have a reference to its children.</p>
<p>However in most cases what we&#8217;d like to have is a <strong>hybrid of one-to-many and many-to-one relationships</strong>. I will call it <strong>one-to-many with inversion</strong>. We want both parent to know about its children, and each children to know about its parent.</p>
<p>In this post we&#8217;ll cover one-to-many with no reversion and one-to-many with reversion, as it also includes many-to-one relationship so you can have a comprehensive overview. We are going to see it on the example of <strong>Employee</strong> and <strong>Duty*</strong> entities. Each employee has a list of his duties, whilst each single duty is assigned to only one employee.</p>
<p><span style="font-size: 10pt;">* &#8220;Task&#8221; would probably be a better name, but I didn&#8217;t want to make it confused with <a href="https://msdn.microsoft.com/en-us/library/system.threading.tasks.task(v=vs.110).aspx" target="_blank" rel="noopener noreferrer">.NET Tasks</a> 🙂</span></p>
<h2>One-to-many with no inversion</h2>
<p>Firstly, let&#8217;s model this kind of relationship:</p>
<figure id="attachment_2252" aria-describedby="caption-attachment-2252" style="width: 485px" class="wp-caption aligncenter"><a href="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/1tm_noInv_UML.jpg?ssl=1" target="_blank" rel="noopener noreferrer"><img data-recalc-dims="1" loading="lazy" decoding="async" data-attachment-id="2252" data-permalink="https://www.codejourney.net/sqlite-net-extensions-one-to-many-relationships/1tm_noinv_uml/" data-orig-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/1tm_noInv_UML.jpg?fit=783%2C149&amp;ssl=1" data-orig-size="783,149" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;Dawid Sibi\u0144ski&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;1495493793&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="1tm_noInv_UML" data-image-description="" data-image-caption="&lt;p&gt;One-to-many with no inversion &amp;#8211; class diagram&lt;/p&gt;
" data-large-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/1tm_noInv_UML.jpg?fit=783%2C149&amp;ssl=1" class="wp-image-2252" src="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/1tm_noInv_UML.jpg?resize=485%2C92&#038;ssl=1" alt="" width="485" height="92" srcset="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/1tm_noInv_UML.jpg?resize=300%2C57&amp;ssl=1 300w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/1tm_noInv_UML.jpg?resize=768%2C146&amp;ssl=1 768w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/1tm_noInv_UML.jpg?resize=720%2C137&amp;ssl=1 720w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/1tm_noInv_UML.jpg?w=783&amp;ssl=1 783w" sizes="auto, (max-width: 485px) 100vw, 485px" /></a><figcaption id="caption-attachment-2252" class="wp-caption-text">One-to-many with no inversion &#8211; class diagram</figcaption></figure>
<p>Now we can transform it into C# classes:</p>
<p><style>.gist table { margin-bottom: 0; }</style>
<div style="tab-size: 8" id="gist47944669" class="gist">
<div class="gist-file" translate="no" data-color-mode="light" data-light-theme="light">
<div class="gist-data">
<div class="js-gist-file-update-container js-task-list-container">
<div id="file-employee-cs" class="file my-2">
<div itemprop="text"
      class="Box-body p-0 blob-wrapper data type-c  "
      style="overflow: auto" tabindex="0" role="region"
      aria-label="Employee.cs content, created by dsibinski on 08:58PM on May 22, 2017."
    ></p>
<div class="js-check-hidden-unicode js-blob-code-container blob-code-content">
<p>  <template class="js-file-alert-template"></p>
<div data-view-component="true" class="flash flash-warn flash-full d-flex flex-items-center">
  <svg aria-hidden="true" data-component="Octicon" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-alert">
    <path d="M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"></path>
</svg><br />
    <span><br />
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.<br />
      <a class="Link--inTextBlock" href="https://github.co/hiddenchars" target="_blank">Learn more about bidirectional Unicode characters</a><br />
    </span></p>
<div data-view-component="true" class="flash-action">        <a href="{{ revealButtonHref }}" data-view-component="true" class="btn-sm btn">    Show hidden characters<br />
</a>
</div>
</div>
<p></template><br />
<template class="js-line-alert-template"><br />
  <span aria-label="This line has hidden Unicode characters" data-view-component="true" class="line-alert tooltipped tooltipped-e"><br />
    <svg aria-hidden="true" data-component="Octicon" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-alert">
    <path d="M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"></path>
</svg><br />
</span></template></p>
<table data-hpc class="highlight tab-size js-file-line-container" data-tab-size="4" data-paste-markdown-skip data-tagsearch-path="Employee.cs">
<tr>
<td id="file-employee-cs-L1" class="blob-num js-line-number js-blob-rnum" data-line-number="1"></td>
<td id="file-employee-cs-LC1" class="blob-code blob-code-inner js-file-line">    [Table(&quot;Employees&quot;)]</td>
</tr>
<tr>
<td id="file-employee-cs-L2" class="blob-num js-line-number js-blob-rnum" data-line-number="2"></td>
<td id="file-employee-cs-LC2" class="blob-code blob-code-inner js-file-line">    public class Employee</td>
</tr>
<tr>
<td id="file-employee-cs-L3" class="blob-num js-line-number js-blob-rnum" data-line-number="3"></td>
<td id="file-employee-cs-LC3" class="blob-code blob-code-inner js-file-line">    {</td>
</tr>
<tr>
<td id="file-employee-cs-L4" class="blob-num js-line-number js-blob-rnum" data-line-number="4"></td>
<td id="file-employee-cs-LC4" class="blob-code blob-code-inner js-file-line">        [PrimaryKey, AutoIncrement]</td>
</tr>
<tr>
<td id="file-employee-cs-L5" class="blob-num js-line-number js-blob-rnum" data-line-number="5"></td>
<td id="file-employee-cs-LC5" class="blob-code blob-code-inner js-file-line">        public int Id { get; set; }</td>
</tr>
<tr>
<td id="file-employee-cs-L6" class="blob-num js-line-number js-blob-rnum" data-line-number="6"></td>
<td id="file-employee-cs-LC6" class="blob-code blob-code-inner js-file-line">
</td>
</tr>
<tr>
<td id="file-employee-cs-L7" class="blob-num js-line-number js-blob-rnum" data-line-number="7"></td>
<td id="file-employee-cs-LC7" class="blob-code blob-code-inner js-file-line">        public string Name { get; set; }</td>
</tr>
<tr>
<td id="file-employee-cs-L8" class="blob-num js-line-number js-blob-rnum" data-line-number="8"></td>
<td id="file-employee-cs-LC8" class="blob-code blob-code-inner js-file-line">        public string LastName { get; set; }</td>
</tr>
<tr>
<td id="file-employee-cs-L9" class="blob-num js-line-number js-blob-rnum" data-line-number="9"></td>
<td id="file-employee-cs-LC9" class="blob-code blob-code-inner js-file-line">
</td>
</tr>
<tr>
<td id="file-employee-cs-L10" class="blob-num js-line-number js-blob-rnum" data-line-number="10"></td>
<td id="file-employee-cs-LC10" class="blob-code blob-code-inner js-file-line">        [OneToMany]</td>
</tr>
<tr>
<td id="file-employee-cs-L11" class="blob-num js-line-number js-blob-rnum" data-line-number="11"></td>
<td id="file-employee-cs-LC11" class="blob-code blob-code-inner js-file-line">        public List&lt;Duty&gt; Duties { get; set; }</td>
</tr>
<tr>
<td id="file-employee-cs-L12" class="blob-num js-line-number js-blob-rnum" data-line-number="12"></td>
<td id="file-employee-cs-LC12" class="blob-code blob-code-inner js-file-line">    }</td>
</tr>
</table>
</div></div>
</p></div>
</div></div>
<div class="gist-meta">
        <a href="https://gist.github.com/dsibinski/7a4bba5b4769a57e286b951d7d830965/raw/5eea39ad5f5ed9597cad5cd3c3677da964b7e42f/Employee.cs" style="float:right" class="Link--inTextBlock">view raw</a><br />
        <a href="https://gist.github.com/dsibinski/7a4bba5b4769a57e286b951d7d830965#file-employee-cs" class="Link--inTextBlock"><br />
          Employee.cs<br />
        </a><br />
        hosted with &#10084; by <a class="Link--inTextBlock" href="https://github.com">GitHub</a>
      </div>
</p></div>
</div>
<p>In the <span style="color: #ff6600;">Employee</span> class (parent, one-end of the relationship) we define the collection of children, decorated with <span style="color: #ff6600;">OneToManyAttribute</span>. Collections types supported as for the time of writing this post by SQLite-Net Extensions are <a href="https://msdn.microsoft.com/en-us/library/6sh2ey19(v=vs.110).aspx" target="_blank" rel="noopener noreferrer">List</a> and <a href="https://msdn.microsoft.com/en-us/library/system.array(v=vs.110).aspx" target="_blank" rel="noopener noreferrer">Array</a> and can be used as you prefer.</p>
<p>Let&#8217;s now see how the child entity (<span style="color: #ff6600;">Duty</span>) looks like:</p>
<p><style>.gist table { margin-bottom: 0; }</style>
<div style="tab-size: 8" id="gist47944678" class="gist">
<div class="gist-file" translate="no" data-color-mode="light" data-light-theme="light">
<div class="gist-data">
<div class="js-gist-file-update-container js-task-list-container">
<div id="file-duty-cs" class="file my-2">
<div itemprop="text"
      class="Box-body p-0 blob-wrapper data type-c  "
      style="overflow: auto" tabindex="0" role="region"
      aria-label="Duty.cs content, created by dsibinski on 08:59PM on May 22, 2017."
    ></p>
<div class="js-check-hidden-unicode js-blob-code-container blob-code-content">
<p>  <template class="js-file-alert-template"></p>
<div data-view-component="true" class="flash flash-warn flash-full d-flex flex-items-center">
  <svg aria-hidden="true" data-component="Octicon" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-alert">
    <path d="M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"></path>
</svg><br />
    <span><br />
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.<br />
      <a class="Link--inTextBlock" href="https://github.co/hiddenchars" target="_blank">Learn more about bidirectional Unicode characters</a><br />
    </span></p>
<div data-view-component="true" class="flash-action">        <a href="{{ revealButtonHref }}" data-view-component="true" class="btn-sm btn">    Show hidden characters<br />
</a>
</div>
</div>
<p></template><br />
<template class="js-line-alert-template"><br />
  <span aria-label="This line has hidden Unicode characters" data-view-component="true" class="line-alert tooltipped tooltipped-e"><br />
    <svg aria-hidden="true" data-component="Octicon" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-alert">
    <path d="M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"></path>
</svg><br />
</span></template></p>
<table data-hpc class="highlight tab-size js-file-line-container" data-tab-size="4" data-paste-markdown-skip data-tagsearch-path="Duty.cs">
<tr>
<td id="file-duty-cs-L1" class="blob-num js-line-number js-blob-rnum" data-line-number="1"></td>
<td id="file-duty-cs-LC1" class="blob-code blob-code-inner js-file-line">    [Table(&quot;Duties&quot;)]</td>
</tr>
<tr>
<td id="file-duty-cs-L2" class="blob-num js-line-number js-blob-rnum" data-line-number="2"></td>
<td id="file-duty-cs-LC2" class="blob-code blob-code-inner js-file-line">    public class Duty</td>
</tr>
<tr>
<td id="file-duty-cs-L3" class="blob-num js-line-number js-blob-rnum" data-line-number="3"></td>
<td id="file-duty-cs-LC3" class="blob-code blob-code-inner js-file-line">    {</td>
</tr>
<tr>
<td id="file-duty-cs-L4" class="blob-num js-line-number js-blob-rnum" data-line-number="4"></td>
<td id="file-duty-cs-LC4" class="blob-code blob-code-inner js-file-line">        [PrimaryKey, AutoIncrement]</td>
</tr>
<tr>
<td id="file-duty-cs-L5" class="blob-num js-line-number js-blob-rnum" data-line-number="5"></td>
<td id="file-duty-cs-LC5" class="blob-code blob-code-inner js-file-line">        public int Id { get; set; }</td>
</tr>
<tr>
<td id="file-duty-cs-L6" class="blob-num js-line-number js-blob-rnum" data-line-number="6"></td>
<td id="file-duty-cs-LC6" class="blob-code blob-code-inner js-file-line">
</td>
</tr>
<tr>
<td id="file-duty-cs-L7" class="blob-num js-line-number js-blob-rnum" data-line-number="7"></td>
<td id="file-duty-cs-LC7" class="blob-code blob-code-inner js-file-line">        public string Description { get; set; }</td>
</tr>
<tr>
<td id="file-duty-cs-L8" class="blob-num js-line-number js-blob-rnum" data-line-number="8"></td>
<td id="file-duty-cs-LC8" class="blob-code blob-code-inner js-file-line">
</td>
</tr>
<tr>
<td id="file-duty-cs-L9" class="blob-num js-line-number js-blob-rnum" data-line-number="9"></td>
<td id="file-duty-cs-LC9" class="blob-code blob-code-inner js-file-line">        public DateTime Deadline { get; set; }</td>
</tr>
<tr>
<td id="file-duty-cs-L10" class="blob-num js-line-number js-blob-rnum" data-line-number="10"></td>
<td id="file-duty-cs-LC10" class="blob-code blob-code-inner js-file-line">
</td>
</tr>
<tr>
<td id="file-duty-cs-L11" class="blob-num js-line-number js-blob-rnum" data-line-number="11"></td>
<td id="file-duty-cs-LC11" class="blob-code blob-code-inner js-file-line">        [ForeignKey(typeof(Employee))]</td>
</tr>
<tr>
<td id="file-duty-cs-L12" class="blob-num js-line-number js-blob-rnum" data-line-number="12"></td>
<td id="file-duty-cs-LC12" class="blob-code blob-code-inner js-file-line">        public int EmployeeId { get; set; }</td>
</tr>
<tr>
<td id="file-duty-cs-L13" class="blob-num js-line-number js-blob-rnum" data-line-number="13"></td>
<td id="file-duty-cs-LC13" class="blob-code blob-code-inner js-file-line">    }</td>
</tr>
</table>
</div></div>
</p></div>
</div></div>
<div class="gist-meta">
        <a href="https://gist.github.com/dsibinski/194a755eb249ea9b4b2a2957c8a5bdbd/raw/b482ad831f693d7d06db28e89c462c3fe3f055d9/Duty.cs" style="float:right" class="Link--inTextBlock">view raw</a><br />
        <a href="https://gist.github.com/dsibinski/194a755eb249ea9b4b2a2957c8a5bdbd#file-duty-cs" class="Link--inTextBlock"><br />
          Duty.cs<br />
        </a><br />
        hosted with &#10084; by <a class="Link--inTextBlock" href="https://github.com">GitHub</a>
      </div>
</p></div>
</div>
<p>In the <span style="color: #ff6600;">Duty</span> class (child, many-end of the relationship) we need to have a foreign key to parent entity defined. For that purpose, we create a property representing it (<span style="color: #ff6600;">EmployeeId</span>), decorating it with <span style="color: #ff6600;">ForeignKeyAttribute</span>, additionally specifying the type of parent referenced (<span style="color: #ff6600;">Employee</span>).</p>
<p>That&#8217;s it. We can already use it in our code:</p>
<p><style>.gist table { margin-bottom: 0; }</style>
<div style="tab-size: 8" id="gist47944855" class="gist">
<div class="gist-file" translate="no" data-color-mode="light" data-light-theme="light">
<div class="gist-data">
<div class="js-gist-file-update-container js-task-list-container">
<div id="file-employeeduty_noinv-cs" class="file my-2">
<div itemprop="text"
      class="Box-body p-0 blob-wrapper data type-c  "
      style="overflow: auto" tabindex="0" role="region"
      aria-label="EmployeeDuty_noInv.cs content, created by dsibinski on 09:05PM on May 22, 2017."
    ></p>
<div class="js-check-hidden-unicode js-blob-code-container blob-code-content">
<p>  <template class="js-file-alert-template"></p>
<div data-view-component="true" class="flash flash-warn flash-full d-flex flex-items-center">
  <svg aria-hidden="true" data-component="Octicon" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-alert">
    <path d="M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"></path>
</svg><br />
    <span><br />
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.<br />
      <a class="Link--inTextBlock" href="https://github.co/hiddenchars" target="_blank">Learn more about bidirectional Unicode characters</a><br />
    </span></p>
<div data-view-component="true" class="flash-action">        <a href="{{ revealButtonHref }}" data-view-component="true" class="btn-sm btn">    Show hidden characters<br />
</a>
</div>
</div>
<p></template><br />
<template class="js-line-alert-template"><br />
  <span aria-label="This line has hidden Unicode characters" data-view-component="true" class="line-alert tooltipped tooltipped-e"><br />
    <svg aria-hidden="true" data-component="Octicon" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-alert">
    <path d="M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"></path>
</svg><br />
</span></template></p>
<table data-hpc class="highlight tab-size js-file-line-container" data-tab-size="4" data-paste-markdown-skip data-tagsearch-path="EmployeeDuty_noInv.cs">
<tr>
<td id="file-employeeduty_noinv-cs-L1" class="blob-num js-line-number js-blob-rnum" data-line-number="1"></td>
<td id="file-employeeduty_noinv-cs-LC1" class="blob-code blob-code-inner js-file-line">  var db = new SQLiteConnection(new SQLitePlatformAndroid(), Constants.DbFilePath);</td>
</tr>
<tr>
<td id="file-employeeduty_noinv-cs-L2" class="blob-num js-line-number js-blob-rnum" data-line-number="2"></td>
<td id="file-employeeduty_noinv-cs-LC2" class="blob-code blob-code-inner js-file-line">  db.CreateTable&lt;Employee&gt;();</td>
</tr>
<tr>
<td id="file-employeeduty_noinv-cs-L3" class="blob-num js-line-number js-blob-rnum" data-line-number="3"></td>
<td id="file-employeeduty_noinv-cs-LC3" class="blob-code blob-code-inner js-file-line">  db.CreateTable&lt;Duty&gt;();</td>
</tr>
<tr>
<td id="file-employeeduty_noinv-cs-L4" class="blob-num js-line-number js-blob-rnum" data-line-number="4"></td>
<td id="file-employeeduty_noinv-cs-LC4" class="blob-code blob-code-inner js-file-line">
</td>
</tr>
<tr>
<td id="file-employeeduty_noinv-cs-L5" class="blob-num js-line-number js-blob-rnum" data-line-number="5"></td>
<td id="file-employeeduty_noinv-cs-LC5" class="blob-code blob-code-inner js-file-line">  var employee = new Employee</td>
</tr>
<tr>
<td id="file-employeeduty_noinv-cs-L6" class="blob-num js-line-number js-blob-rnum" data-line-number="6"></td>
<td id="file-employeeduty_noinv-cs-LC6" class="blob-code blob-code-inner js-file-line">  {</td>
</tr>
<tr>
<td id="file-employeeduty_noinv-cs-L7" class="blob-num js-line-number js-blob-rnum" data-line-number="7"></td>
<td id="file-employeeduty_noinv-cs-LC7" class="blob-code blob-code-inner js-file-line">      Name = &quot;Andrew&quot;,</td>
</tr>
<tr>
<td id="file-employeeduty_noinv-cs-L8" class="blob-num js-line-number js-blob-rnum" data-line-number="8"></td>
<td id="file-employeeduty_noinv-cs-LC8" class="blob-code blob-code-inner js-file-line">      LastName = &quot;Programmer&quot;</td>
</tr>
<tr>
<td id="file-employeeduty_noinv-cs-L9" class="blob-num js-line-number js-blob-rnum" data-line-number="9"></td>
<td id="file-employeeduty_noinv-cs-LC9" class="blob-code blob-code-inner js-file-line">  };</td>
</tr>
<tr>
<td id="file-employeeduty_noinv-cs-L10" class="blob-num js-line-number js-blob-rnum" data-line-number="10"></td>
<td id="file-employeeduty_noinv-cs-LC10" class="blob-code blob-code-inner js-file-line">
</td>
</tr>
<tr>
<td id="file-employeeduty_noinv-cs-L11" class="blob-num js-line-number js-blob-rnum" data-line-number="11"></td>
<td id="file-employeeduty_noinv-cs-LC11" class="blob-code blob-code-inner js-file-line">  var duty1 = new Duty()</td>
</tr>
<tr>
<td id="file-employeeduty_noinv-cs-L12" class="blob-num js-line-number js-blob-rnum" data-line-number="12"></td>
<td id="file-employeeduty_noinv-cs-LC12" class="blob-code blob-code-inner js-file-line">  {</td>
</tr>
<tr>
<td id="file-employeeduty_noinv-cs-L13" class="blob-num js-line-number js-blob-rnum" data-line-number="13"></td>
<td id="file-employeeduty_noinv-cs-LC13" class="blob-code blob-code-inner js-file-line">      Description = &quot;Project A Management&quot;,</td>
</tr>
<tr>
<td id="file-employeeduty_noinv-cs-L14" class="blob-num js-line-number js-blob-rnum" data-line-number="14"></td>
<td id="file-employeeduty_noinv-cs-LC14" class="blob-code blob-code-inner js-file-line">      Deadline = new DateTime(2017, 10, 31)</td>
</tr>
<tr>
<td id="file-employeeduty_noinv-cs-L15" class="blob-num js-line-number js-blob-rnum" data-line-number="15"></td>
<td id="file-employeeduty_noinv-cs-LC15" class="blob-code blob-code-inner js-file-line">  };</td>
</tr>
<tr>
<td id="file-employeeduty_noinv-cs-L16" class="blob-num js-line-number js-blob-rnum" data-line-number="16"></td>
<td id="file-employeeduty_noinv-cs-LC16" class="blob-code blob-code-inner js-file-line">
</td>
</tr>
<tr>
<td id="file-employeeduty_noinv-cs-L17" class="blob-num js-line-number js-blob-rnum" data-line-number="17"></td>
<td id="file-employeeduty_noinv-cs-LC17" class="blob-code blob-code-inner js-file-line">  var duty2 = new Duty()</td>
</tr>
<tr>
<td id="file-employeeduty_noinv-cs-L18" class="blob-num js-line-number js-blob-rnum" data-line-number="18"></td>
<td id="file-employeeduty_noinv-cs-LC18" class="blob-code blob-code-inner js-file-line">  {</td>
</tr>
<tr>
<td id="file-employeeduty_noinv-cs-L19" class="blob-num js-line-number js-blob-rnum" data-line-number="19"></td>
<td id="file-employeeduty_noinv-cs-LC19" class="blob-code blob-code-inner js-file-line">      Description = &quot;Reporting work time&quot;,</td>
</tr>
<tr>
<td id="file-employeeduty_noinv-cs-L20" class="blob-num js-line-number js-blob-rnum" data-line-number="20"></td>
<td id="file-employeeduty_noinv-cs-LC20" class="blob-code blob-code-inner js-file-line">      Deadline = new DateTime(2022, 12, 31)</td>
</tr>
<tr>
<td id="file-employeeduty_noinv-cs-L21" class="blob-num js-line-number js-blob-rnum" data-line-number="21"></td>
<td id="file-employeeduty_noinv-cs-LC21" class="blob-code blob-code-inner js-file-line">  };</td>
</tr>
<tr>
<td id="file-employeeduty_noinv-cs-L22" class="blob-num js-line-number js-blob-rnum" data-line-number="22"></td>
<td id="file-employeeduty_noinv-cs-LC22" class="blob-code blob-code-inner js-file-line">
</td>
</tr>
<tr>
<td id="file-employeeduty_noinv-cs-L23" class="blob-num js-line-number js-blob-rnum" data-line-number="23"></td>
<td id="file-employeeduty_noinv-cs-LC23" class="blob-code blob-code-inner js-file-line">  db.Insert(employee);</td>
</tr>
<tr>
<td id="file-employeeduty_noinv-cs-L24" class="blob-num js-line-number js-blob-rnum" data-line-number="24"></td>
<td id="file-employeeduty_noinv-cs-LC24" class="blob-code blob-code-inner js-file-line">  db.Insert(duty1);</td>
</tr>
<tr>
<td id="file-employeeduty_noinv-cs-L25" class="blob-num js-line-number js-blob-rnum" data-line-number="25"></td>
<td id="file-employeeduty_noinv-cs-LC25" class="blob-code blob-code-inner js-file-line">  db.Insert(duty2);</td>
</tr>
<tr>
<td id="file-employeeduty_noinv-cs-L26" class="blob-num js-line-number js-blob-rnum" data-line-number="26"></td>
<td id="file-employeeduty_noinv-cs-LC26" class="blob-code blob-code-inner js-file-line">
</td>
</tr>
<tr>
<td id="file-employeeduty_noinv-cs-L27" class="blob-num js-line-number js-blob-rnum" data-line-number="27"></td>
<td id="file-employeeduty_noinv-cs-LC27" class="blob-code blob-code-inner js-file-line">  employee.Duties = new List&lt;Duty&gt; {duty1, duty2};</td>
</tr>
<tr>
<td id="file-employeeduty_noinv-cs-L28" class="blob-num js-line-number js-blob-rnum" data-line-number="28"></td>
<td id="file-employeeduty_noinv-cs-LC28" class="blob-code blob-code-inner js-file-line">  db.UpdateWithChildren(employee);</td>
</tr>
<tr>
<td id="file-employeeduty_noinv-cs-L29" class="blob-num js-line-number js-blob-rnum" data-line-number="29"></td>
<td id="file-employeeduty_noinv-cs-LC29" class="blob-code blob-code-inner js-file-line">
</td>
</tr>
<tr>
<td id="file-employeeduty_noinv-cs-L30" class="blob-num js-line-number js-blob-rnum" data-line-number="30"></td>
<td id="file-employeeduty_noinv-cs-LC30" class="blob-code blob-code-inner js-file-line">  var employeeStored = db.GetWithChildren&lt;Employee&gt;(employee.Id);</td>
</tr>
</table>
</div></div>
</p></div>
</div></div>
<div class="gist-meta">
        <a href="https://gist.github.com/dsibinski/75df037ed90ffab99e5bb313241e8e3c/raw/b24fce0392c8be8078423f1d4c472ced73eef96a/EmployeeDuty_noInv.cs" style="float:right" class="Link--inTextBlock">view raw</a><br />
        <a href="https://gist.github.com/dsibinski/75df037ed90ffab99e5bb313241e8e3c#file-employeeduty_noinv-cs" class="Link--inTextBlock"><br />
          EmployeeDuty_noInv.cs<br />
        </a><br />
        hosted with &#10084; by <a class="Link--inTextBlock" href="https://github.com">GitHub</a>
      </div>
</p></div>
</div>
<p>No rocket-science here. What&#8217;s interesting for us it how <span style="color: #ff6600;">employeeStored</span> looks in the end:</p>
<figure id="attachment_2260" aria-describedby="caption-attachment-2260" style="width: 468px" class="wp-caption aligncenter"><a href="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/1tM_noInv_debug-1.png?ssl=1" target="_blank" rel="noopener noreferrer"><img data-recalc-dims="1" loading="lazy" decoding="async" data-attachment-id="2260" data-permalink="https://www.codejourney.net/sqlite-net-extensions-one-to-many-relationships/1tm_noinv_debug-2/" data-orig-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/1tM_noInv_debug-1.png?fit=478%2C171&amp;ssl=1" data-orig-size="478,171" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="1tM_noInv_debug" data-image-description="" data-image-caption="" data-large-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/1tM_noInv_debug-1.png?fit=478%2C171&amp;ssl=1" class="wp-image-2260" src="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/1tM_noInv_debug-1.png?resize=468%2C167&#038;ssl=1" alt="" width="468" height="167" srcset="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/1tM_noInv_debug-1.png?resize=300%2C107&amp;ssl=1 300w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/1tM_noInv_debug-1.png?w=478&amp;ssl=1 478w" sizes="auto, (max-width: 468px) 100vw, 468px" /></a><figcaption id="caption-attachment-2260" class="wp-caption-text">One-to-many with no inversion</figcaption></figure>
<p>As you can see, <span style="color: #ff6600;">GetWithChildren</span> method returned object of type <span style="color: #ff6600;">Employee</span> with its <span style="color: #ff6600;">Duties</span> collection properly retrieved (containing two duties assigned to the employee before). Moreover, each children has its foreign key (<span style="color: #ff6600;">EmployeeId</span>) automatically retrieved from the DB &#8211; there is no overhead here, this is simply foreign key field stored in the same SQLite database table (<em>Duties</em>).</p>
<h2>One-to-many with inversion (one-to-many + many-to-one)</h2>
<p>As previously, let&#8217;s first see how the class diagram changes after adding inversion:</p>
<figure id="attachment_2259" aria-describedby="caption-attachment-2259" style="width: 504px" class="wp-caption aligncenter"><a href="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/1tm_withInv_UML.jpg?ssl=1" target="_blank" rel="noopener noreferrer"><img data-recalc-dims="1" loading="lazy" decoding="async" data-attachment-id="2259" data-permalink="https://www.codejourney.net/sqlite-net-extensions-one-to-many-relationships/1tm_withinv_uml/" data-orig-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/1tm_withInv_UML.jpg?fit=790%2C156&amp;ssl=1" data-orig-size="790,156" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;Dawid Sibi\u0144ski&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;1495493850&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="1tm_withInv_UML" data-image-description="" data-image-caption="&lt;p&gt;One-to-many with inversion&lt;/p&gt;
" data-large-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/1tm_withInv_UML.jpg?fit=790%2C156&amp;ssl=1" class="wp-image-2259" src="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/1tm_withInv_UML.jpg?resize=504%2C99&#038;ssl=1" alt="" width="504" height="99" srcset="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/1tm_withInv_UML.jpg?resize=300%2C59&amp;ssl=1 300w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/1tm_withInv_UML.jpg?resize=768%2C152&amp;ssl=1 768w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/1tm_withInv_UML.jpg?resize=720%2C142&amp;ssl=1 720w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/1tm_withInv_UML.jpg?w=790&amp;ssl=1 790w" sizes="auto, (max-width: 504px) 100vw, 504px" /></a><figcaption id="caption-attachment-2259" class="wp-caption-text">One-to-many with inversion &#8211; class diagram</figcaption></figure>
<p>What changed is that now each <span style="color: #ff6600;">Duty</span> has a property of type <span style="color: #ff6600;">Employee</span>.</p>
<p>To realize the above class diagram and make each children (each <span style="color: #ff6600;">Duty</span> in our case) knowing about its parent (having a reference to responsible <span style="color: #ff6600;">Employee</span>), the only thing we need to do is to add the following property to <span style="color: #ff6600;">Duty</span> model class:</p>
<pre><pre class="brush: csharp; title: ; notranslate">&#x5B;ManyToOne]
public Employee Employee { get; set; }</pre>
<p>so the model class finally looks as follows:</p>
<p><style>.gist table { margin-bottom: 0; }</style>
<div style="tab-size: 8" id="gist47945603" class="gist">
<div class="gist-file" translate="no" data-color-mode="light" data-light-theme="light">
<div class="gist-data">
<div class="js-gist-file-update-container js-task-list-container">
<div id="file-employee_withinv-cs" class="file my-2">
<div itemprop="text"
      class="Box-body p-0 blob-wrapper data type-c  "
      style="overflow: auto" tabindex="0" role="region"
      aria-label="Employee_withInv.cs content, created by dsibinski on 09:34PM on May 22, 2017."
    ></p>
<div class="js-check-hidden-unicode js-blob-code-container blob-code-content">
<p>  <template class="js-file-alert-template"></p>
<div data-view-component="true" class="flash flash-warn flash-full d-flex flex-items-center">
  <svg aria-hidden="true" data-component="Octicon" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-alert">
    <path d="M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"></path>
</svg><br />
    <span><br />
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.<br />
      <a class="Link--inTextBlock" href="https://github.co/hiddenchars" target="_blank">Learn more about bidirectional Unicode characters</a><br />
    </span></p>
<div data-view-component="true" class="flash-action">        <a href="{{ revealButtonHref }}" data-view-component="true" class="btn-sm btn">    Show hidden characters<br />
</a>
</div>
</div>
<p></template><br />
<template class="js-line-alert-template"><br />
  <span aria-label="This line has hidden Unicode characters" data-view-component="true" class="line-alert tooltipped tooltipped-e"><br />
    <svg aria-hidden="true" data-component="Octicon" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-alert">
    <path d="M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"></path>
</svg><br />
</span></template></p>
<table data-hpc class="highlight tab-size js-file-line-container" data-tab-size="4" data-paste-markdown-skip data-tagsearch-path="Employee_withInv.cs">
<tr>
<td id="file-employee_withinv-cs-L1" class="blob-num js-line-number js-blob-rnum" data-line-number="1"></td>
<td id="file-employee_withinv-cs-LC1" class="blob-code blob-code-inner js-file-line">  [Table(&quot;Duties&quot;)]</td>
</tr>
<tr>
<td id="file-employee_withinv-cs-L2" class="blob-num js-line-number js-blob-rnum" data-line-number="2"></td>
<td id="file-employee_withinv-cs-LC2" class="blob-code blob-code-inner js-file-line">  public class Duty</td>
</tr>
<tr>
<td id="file-employee_withinv-cs-L3" class="blob-num js-line-number js-blob-rnum" data-line-number="3"></td>
<td id="file-employee_withinv-cs-LC3" class="blob-code blob-code-inner js-file-line">  {</td>
</tr>
<tr>
<td id="file-employee_withinv-cs-L4" class="blob-num js-line-number js-blob-rnum" data-line-number="4"></td>
<td id="file-employee_withinv-cs-LC4" class="blob-code blob-code-inner js-file-line">      [PrimaryKey, AutoIncrement]</td>
</tr>
<tr>
<td id="file-employee_withinv-cs-L5" class="blob-num js-line-number js-blob-rnum" data-line-number="5"></td>
<td id="file-employee_withinv-cs-LC5" class="blob-code blob-code-inner js-file-line">      public int Id { get; set; }</td>
</tr>
<tr>
<td id="file-employee_withinv-cs-L6" class="blob-num js-line-number js-blob-rnum" data-line-number="6"></td>
<td id="file-employee_withinv-cs-LC6" class="blob-code blob-code-inner js-file-line">
</td>
</tr>
<tr>
<td id="file-employee_withinv-cs-L7" class="blob-num js-line-number js-blob-rnum" data-line-number="7"></td>
<td id="file-employee_withinv-cs-LC7" class="blob-code blob-code-inner js-file-line">      public string Description { get; set; }</td>
</tr>
<tr>
<td id="file-employee_withinv-cs-L8" class="blob-num js-line-number js-blob-rnum" data-line-number="8"></td>
<td id="file-employee_withinv-cs-LC8" class="blob-code blob-code-inner js-file-line">
</td>
</tr>
<tr>
<td id="file-employee_withinv-cs-L9" class="blob-num js-line-number js-blob-rnum" data-line-number="9"></td>
<td id="file-employee_withinv-cs-LC9" class="blob-code blob-code-inner js-file-line">      public DateTime Deadline { get; set; }</td>
</tr>
<tr>
<td id="file-employee_withinv-cs-L10" class="blob-num js-line-number js-blob-rnum" data-line-number="10"></td>
<td id="file-employee_withinv-cs-LC10" class="blob-code blob-code-inner js-file-line">
</td>
</tr>
<tr>
<td id="file-employee_withinv-cs-L11" class="blob-num js-line-number js-blob-rnum" data-line-number="11"></td>
<td id="file-employee_withinv-cs-LC11" class="blob-code blob-code-inner js-file-line">      [ForeignKey(typeof(Employee))]</td>
</tr>
<tr>
<td id="file-employee_withinv-cs-L12" class="blob-num js-line-number js-blob-rnum" data-line-number="12"></td>
<td id="file-employee_withinv-cs-LC12" class="blob-code blob-code-inner js-file-line">      public int EmployeeId { get; set; }</td>
</tr>
<tr>
<td id="file-employee_withinv-cs-L13" class="blob-num js-line-number js-blob-rnum" data-line-number="13"></td>
<td id="file-employee_withinv-cs-LC13" class="blob-code blob-code-inner js-file-line">
</td>
</tr>
<tr>
<td id="file-employee_withinv-cs-L14" class="blob-num js-line-number js-blob-rnum" data-line-number="14"></td>
<td id="file-employee_withinv-cs-LC14" class="blob-code blob-code-inner js-file-line">      [ManyToOne]</td>
</tr>
<tr>
<td id="file-employee_withinv-cs-L15" class="blob-num js-line-number js-blob-rnum" data-line-number="15"></td>
<td id="file-employee_withinv-cs-LC15" class="blob-code blob-code-inner js-file-line">      public Employee Employee { get; set; }</td>
</tr>
<tr>
<td id="file-employee_withinv-cs-L16" class="blob-num js-line-number js-blob-rnum" data-line-number="16"></td>
<td id="file-employee_withinv-cs-LC16" class="blob-code blob-code-inner js-file-line">  }</td>
</tr>
</table>
</div></div>
</p></div>
</div></div>
<div class="gist-meta">
        <a href="https://gist.github.com/dsibinski/270d672a47715a6f0e76ce4747048b3d/raw/fdc1e5a1af839cc859d2b706018f45af64335501/Employee_withInv.cs" style="float:right" class="Link--inTextBlock">view raw</a><br />
        <a href="https://gist.github.com/dsibinski/270d672a47715a6f0e76ce4747048b3d#file-employee_withinv-cs" class="Link--inTextBlock"><br />
          Employee_withInv.cs<br />
        </a><br />
        hosted with &#10084; by <a class="Link--inTextBlock" href="https://github.com">GitHub</a>
      </div>
</p></div>
</div>
<p>As you can see, we have just created many-to-one relationship by using <span style="color: #ff6600;">ManyToOneAttribute</span>. So currently we have the hybrid of both types of relationships within out two models.</p>
<p>The usage in our code doesn&#8217;t need to be changed at all. Now, <span style="color: #ff6600;">employeeStored</span> entity after being initialized by the same <span style="color: #ff6600;">GetWithChildren</span> method as previously, for each <span style="color: #ff6600;">Duty</span> in addition to <span style="color: #ff6600;">EmployeeId</span> field also contains <span style="color: #ff6600;">Employee</span> property properly retrieved by SQLite-Net Extensions:</p>
<figure id="attachment_2261" aria-describedby="caption-attachment-2261" style="width: 469px" class="wp-caption aligncenter"><a href="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/1tM_withInv_debug.png?ssl=1" target="_blank" rel="noopener noreferrer"><img data-recalc-dims="1" loading="lazy" decoding="async" data-attachment-id="2261" data-permalink="https://www.codejourney.net/sqlite-net-extensions-one-to-many-relationships/1tm_withinv_debug/" data-orig-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/1tM_withInv_debug.png?fit=475%2C160&amp;ssl=1" data-orig-size="475,160" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="1tM_withInv_debug" data-image-description="" data-image-caption="&lt;p&gt;One-to-many with inversion&lt;/p&gt;
" data-large-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/1tM_withInv_debug.png?fit=475%2C160&amp;ssl=1" class="wp-image-2261" src="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/1tM_withInv_debug.png?resize=469%2C158&#038;ssl=1" alt="" width="469" height="158" srcset="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/1tM_withInv_debug.png?resize=300%2C101&amp;ssl=1 300w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/1tM_withInv_debug.png?w=475&amp;ssl=1 475w" sizes="auto, (max-width: 469px) 100vw, 469px" /></a><figcaption id="caption-attachment-2261" class="wp-caption-text">One-to-many with inversion</figcaption></figure>
<p>Again, there is no db overhead here, because when retrieving <span style="color: #ff6600;">Employee</span> entity from the database we already have it, so the operation of initializing the <span style="color: #ff6600;">Employee</span> entity in each <span style="color: #ff6600;">Duty</span> contained within <span style="color: #ff6600;">Duties</span> collection doesn&#8217;t require any more database querying.</p>
<h2>Summary</h2>
<p>Today we&#8217;ve seen how to model and use one-to-many (with and without inversion) relationships in SQLite database with the usage of SQLite-Net Extensions. The automatic initialization of one-end or many-end entities by the ORM is extremely helpful when dealing with such kind of objects in our app. The amount of code to be written is also minimal.</p>
<p>We&#8217;ve covered one-to-many and a hybrid of one-to-many + many-to-one relationships, but of course you can also define just many-to-one relationship &#8211; the models would then look <a href="https://gist.github.com/dsibinski/9d4f47a85d4944fb55a888aff57a84a3" target="_blank" rel="noopener noreferrer">as in this Gist</a>. For me, it makes very limited sense, but maybe can be useful in some specific situations.</p>
<p>I invite you to read <a href="https://www.codejourney.net/tag/sqlite-net-extensions/" target="_blank" rel="noopener noreferrer">my other posts about SQLite-Net Extensions ORM</a>, where we also covered the other types of relationships that can be modeled using this library.</p>
<p>As this is already the third post from this series, I&#8217;d like to ask you: <span style="text-decoration: underline;"><strong>what do you think about SQLite-Net Extensions ORM? Do you find it useful? Do you use it in your apps? Can you can recommend some other libraries/ORMs to use with SQLite database that allow to model different kind of relationships?</strong></span></p>
<p>The post <a href="https://www.codejourney.net/sqlite-net-extensions-one-to-many-relationships/">SQLite-Net Extensions – one-to-many relationships</a> appeared first on <a href="https://www.codejourney.net">CodeJourney.net</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.codejourney.net/sqlite-net-extensions-one-to-many-relationships/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">2251</post-id>	</item>
		<item>
		<title>SQLite-Net Extensions – one-to-one relationships</title>
		<link>https://www.codejourney.net/sqlite-net-extensions-one-to-one-relationships/</link>
					<comments>https://www.codejourney.net/sqlite-net-extensions-one-to-one-relationships/#comments</comments>
		
		<dc:creator><![CDATA[Dawid Sibiński]]></dc:creator>
		<pubDate>Sun, 21 May 2017 10:18:15 +0000</pubDate>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[android]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[dajsiepoznac2017]]></category>
		<category><![CDATA[sqlite-net-extensions]]></category>
		<category><![CDATA[xamarin]]></category>
		<guid isPermaLink="false">http://www.dsibinski.pl/?p=2238</guid>

					<description><![CDATA[<p>In this second short post from SQLite-Net Extensions series, we&#8217;re going to see how to create one-to-one relationships using this tiny ORM. One-To-One This is the simplest type of database relationship. An example could be vehicle and registration certificate &#8211; each vehicle has one and only one registration certificate, and one registration certificate is associated&#8230;</p>
<p>The post <a href="https://www.codejourney.net/sqlite-net-extensions-one-to-one-relationships/">SQLite-Net Extensions – one-to-one relationships</a> appeared first on <a href="https://www.codejourney.net">CodeJourney.net</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>In this second short post from <a href="https://www.codejourney.net/tag/sqlite-net-extensions/" target="_blank" rel="noopener noreferrer">SQLite-Net Extensions</a> series, we&#8217;re going to see how to create one-to-one relationships using this tiny ORM.<br />
<span id="more-2238"></span></p>
<h2>One-To-One</h2>
<p>This is the simplest type of database relationship. An example could be <strong>vehicle</strong> and <strong>registration certificate</strong> &#8211; each vehicle has <em>one and only one</em> registration certificate, and one registration certificate is associated with <em>one and only one</em> vehicle (excluding some extraordinary law rules in other countries that I don&#8217;t know <img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f642.png" alt="🙂" class="wp-smiley" style="height: 1em; max-height: 1em;" /> ).</p>
<p>We can model it in two ways:</p>
<ul>
<li>as a <strong>one-way</strong> relationship &#8211; in this case only one of the relationship&#8217;s ends knows about the other one</li>
<li>as a <strong>both-ways</strong> (with inversion) relationship &#8211; both relationship&#8217;s ends know about each other.</li>
</ul>
<h4>One-To-One with no inversion (one-way)</h4>
<p>This kind of relationship looks as follows:</p>
<figure id="attachment_2240" aria-describedby="caption-attachment-2240" style="width: 490px" class="wp-caption aligncenter"><a href="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/1t1_noRec.jpg?ssl=1" target="_blank" rel="noopener noreferrer"><img data-recalc-dims="1" loading="lazy" decoding="async" data-attachment-id="2240" data-permalink="https://www.codejourney.net/sqlite-net-extensions-one-to-one-relationships/1t1_norec/" data-orig-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/1t1_noRec.jpg?fit=550%2C135&amp;ssl=1" data-orig-size="550,135" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;Dawid Sibi\u0144ski&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;1495366304&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="1t1_noRec" data-image-description="" data-image-caption="&lt;p&gt;One-To-One &amp;#8211; no &lt;/p&gt;
" data-large-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/1t1_noRec.jpg?fit=550%2C135&amp;ssl=1" class="wp-image-2240" src="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/1t1_noRec.jpg?resize=490%2C121&#038;ssl=1" alt="" width="490" height="121" srcset="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/1t1_noRec.jpg?resize=300%2C74&amp;ssl=1 300w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/1t1_noRec.jpg?w=550&amp;ssl=1 550w" sizes="auto, (max-width: 490px) 100vw, 490px" /></a><figcaption id="caption-attachment-2240" class="wp-caption-text">One-To-One &#8211; one-way &#8211; class diagram</figcaption></figure>
<p>We use it when we assume it&#8217;s enough that <span style="color: #ff9900;">Vehicle</span> knows about <span style="color: #ff9900;">RegistrationCertificate</span>, but the document doesn&#8217;t necessarily need to know which car/motor it&#8217;s associated with (at least directly).</p>
<p>In the code, we then create two model classes using SQLite-Net Extensions:</p>
<p><style>.gist table { margin-bottom: 0; }</style>
<div style="tab-size: 8" id="gist47893553" class="gist">
<div class="gist-file" translate="no" data-color-mode="light" data-light-theme="light">
<div class="gist-data">
<div class="js-gist-file-update-container js-task-list-container">
<div id="file-registrationcertificate-cs" class="file my-2">
<div itemprop="text"
      class="Box-body p-0 blob-wrapper data type-c  "
      style="overflow: auto" tabindex="0" role="region"
      aria-label="RegistrationCertificate.cs content, created by dsibinski on 09:36AM on May 21, 2017."
    ></p>
<div class="js-check-hidden-unicode js-blob-code-container blob-code-content">
<p>  <template class="js-file-alert-template"></p>
<div data-view-component="true" class="flash flash-warn flash-full d-flex flex-items-center">
  <svg aria-hidden="true" data-component="Octicon" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-alert">
    <path d="M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"></path>
</svg><br />
    <span><br />
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.<br />
      <a class="Link--inTextBlock" href="https://github.co/hiddenchars" target="_blank">Learn more about bidirectional Unicode characters</a><br />
    </span></p>
<div data-view-component="true" class="flash-action">        <a href="{{ revealButtonHref }}" data-view-component="true" class="btn-sm btn">    Show hidden characters<br />
</a>
</div>
</div>
<p></template><br />
<template class="js-line-alert-template"><br />
  <span aria-label="This line has hidden Unicode characters" data-view-component="true" class="line-alert tooltipped tooltipped-e"><br />
    <svg aria-hidden="true" data-component="Octicon" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-alert">
    <path d="M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"></path>
</svg><br />
</span></template></p>
<table data-hpc class="highlight tab-size js-file-line-container" data-tab-size="4" data-paste-markdown-skip data-tagsearch-path="RegistrationCertificate.cs">
<tr>
<td id="file-registrationcertificate-cs-L1" class="blob-num js-line-number js-blob-rnum" data-line-number="1"></td>
<td id="file-registrationcertificate-cs-LC1" class="blob-code blob-code-inner js-file-line">    [Table(&quot;RegistrationCertificates&quot;)]</td>
</tr>
<tr>
<td id="file-registrationcertificate-cs-L2" class="blob-num js-line-number js-blob-rnum" data-line-number="2"></td>
<td id="file-registrationcertificate-cs-LC2" class="blob-code blob-code-inner js-file-line">    public class RegistrationCertificate</td>
</tr>
<tr>
<td id="file-registrationcertificate-cs-L3" class="blob-num js-line-number js-blob-rnum" data-line-number="3"></td>
<td id="file-registrationcertificate-cs-LC3" class="blob-code blob-code-inner js-file-line">    {</td>
</tr>
<tr>
<td id="file-registrationcertificate-cs-L4" class="blob-num js-line-number js-blob-rnum" data-line-number="4"></td>
<td id="file-registrationcertificate-cs-LC4" class="blob-code blob-code-inner js-file-line">        [PrimaryKey, AutoIncrement]</td>
</tr>
<tr>
<td id="file-registrationcertificate-cs-L5" class="blob-num js-line-number js-blob-rnum" data-line-number="5"></td>
<td id="file-registrationcertificate-cs-LC5" class="blob-code blob-code-inner js-file-line">        public int Id { get; set; }</td>
</tr>
<tr>
<td id="file-registrationcertificate-cs-L6" class="blob-num js-line-number js-blob-rnum" data-line-number="6"></td>
<td id="file-registrationcertificate-cs-LC6" class="blob-code blob-code-inner js-file-line">
</td>
</tr>
<tr>
<td id="file-registrationcertificate-cs-L7" class="blob-num js-line-number js-blob-rnum" data-line-number="7"></td>
<td id="file-registrationcertificate-cs-LC7" class="blob-code blob-code-inner js-file-line">        public string RegistrationNumber { get; set; }</td>
</tr>
<tr>
<td id="file-registrationcertificate-cs-L8" class="blob-num js-line-number js-blob-rnum" data-line-number="8"></td>
<td id="file-registrationcertificate-cs-LC8" class="blob-code blob-code-inner js-file-line">
</td>
</tr>
<tr>
<td id="file-registrationcertificate-cs-L9" class="blob-num js-line-number js-blob-rnum" data-line-number="9"></td>
<td id="file-registrationcertificate-cs-LC9" class="blob-code blob-code-inner js-file-line">        public string VIN { get; set; }</td>
</tr>
<tr>
<td id="file-registrationcertificate-cs-L10" class="blob-num js-line-number js-blob-rnum" data-line-number="10"></td>
<td id="file-registrationcertificate-cs-LC10" class="blob-code blob-code-inner js-file-line">
</td>
</tr>
<tr>
<td id="file-registrationcertificate-cs-L11" class="blob-num js-line-number js-blob-rnum" data-line-number="11"></td>
<td id="file-registrationcertificate-cs-LC11" class="blob-code blob-code-inner js-file-line">        public string OwnerData { get; set; }</td>
</tr>
<tr>
<td id="file-registrationcertificate-cs-L12" class="blob-num js-line-number js-blob-rnum" data-line-number="12"></td>
<td id="file-registrationcertificate-cs-LC12" class="blob-code blob-code-inner js-file-line">    }</td>
</tr>
</table>
</div></div>
</p></div>
</div></div>
<div class="gist-meta">
        <a href="https://gist.github.com/dsibinski/4970ea35805b27453dc55aa0d5688e5f/raw/f344b75b2d1e98f63d6190c90a8e3221bd5bcb51/RegistrationCertificate.cs" style="float:right" class="Link--inTextBlock">view raw</a><br />
        <a href="https://gist.github.com/dsibinski/4970ea35805b27453dc55aa0d5688e5f#file-registrationcertificate-cs" class="Link--inTextBlock"><br />
          RegistrationCertificate.cs<br />
        </a><br />
        hosted with &#10084; by <a class="Link--inTextBlock" href="https://github.com">GitHub</a>
      </div>
</p></div>
</div>
<p><style>.gist table { margin-bottom: 0; }</style>
<div style="tab-size: 8" id="gist47893558" class="gist">
<div class="gist-file" translate="no" data-color-mode="light" data-light-theme="light">
<div class="gist-data">
<div class="js-gist-file-update-container js-task-list-container">
<div id="file-vehicle-cs" class="file my-2">
<div itemprop="text"
      class="Box-body p-0 blob-wrapper data type-c  "
      style="overflow: auto" tabindex="0" role="region"
      aria-label="Vehicle.cs content, created by dsibinski on 09:37AM on May 21, 2017."
    ></p>
<div class="js-check-hidden-unicode js-blob-code-container blob-code-content">
<p>  <template class="js-file-alert-template"></p>
<div data-view-component="true" class="flash flash-warn flash-full d-flex flex-items-center">
  <svg aria-hidden="true" data-component="Octicon" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-alert">
    <path d="M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"></path>
</svg><br />
    <span><br />
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.<br />
      <a class="Link--inTextBlock" href="https://github.co/hiddenchars" target="_blank">Learn more about bidirectional Unicode characters</a><br />
    </span></p>
<div data-view-component="true" class="flash-action">        <a href="{{ revealButtonHref }}" data-view-component="true" class="btn-sm btn">    Show hidden characters<br />
</a>
</div>
</div>
<p></template><br />
<template class="js-line-alert-template"><br />
  <span aria-label="This line has hidden Unicode characters" data-view-component="true" class="line-alert tooltipped tooltipped-e"><br />
    <svg aria-hidden="true" data-component="Octicon" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-alert">
    <path d="M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"></path>
</svg><br />
</span></template></p>
<table data-hpc class="highlight tab-size js-file-line-container" data-tab-size="4" data-paste-markdown-skip data-tagsearch-path="Vehicle.cs">
<tr>
<td id="file-vehicle-cs-L1" class="blob-num js-line-number js-blob-rnum" data-line-number="1"></td>
<td id="file-vehicle-cs-LC1" class="blob-code blob-code-inner js-file-line">    [Table(&quot;Vehicles&quot;)]</td>
</tr>
<tr>
<td id="file-vehicle-cs-L2" class="blob-num js-line-number js-blob-rnum" data-line-number="2"></td>
<td id="file-vehicle-cs-LC2" class="blob-code blob-code-inner js-file-line">    public class Vehicle</td>
</tr>
<tr>
<td id="file-vehicle-cs-L3" class="blob-num js-line-number js-blob-rnum" data-line-number="3"></td>
<td id="file-vehicle-cs-LC3" class="blob-code blob-code-inner js-file-line">    {</td>
</tr>
<tr>
<td id="file-vehicle-cs-L4" class="blob-num js-line-number js-blob-rnum" data-line-number="4"></td>
<td id="file-vehicle-cs-LC4" class="blob-code blob-code-inner js-file-line">        [PrimaryKey, AutoIncrement]</td>
</tr>
<tr>
<td id="file-vehicle-cs-L5" class="blob-num js-line-number js-blob-rnum" data-line-number="5"></td>
<td id="file-vehicle-cs-LC5" class="blob-code blob-code-inner js-file-line">        public int Id { get; set; }</td>
</tr>
<tr>
<td id="file-vehicle-cs-L6" class="blob-num js-line-number js-blob-rnum" data-line-number="6"></td>
<td id="file-vehicle-cs-LC6" class="blob-code blob-code-inner js-file-line">
</td>
</tr>
<tr>
<td id="file-vehicle-cs-L7" class="blob-num js-line-number js-blob-rnum" data-line-number="7"></td>
<td id="file-vehicle-cs-LC7" class="blob-code blob-code-inner js-file-line">        public string Brand { get; set; }</td>
</tr>
<tr>
<td id="file-vehicle-cs-L8" class="blob-num js-line-number js-blob-rnum" data-line-number="8"></td>
<td id="file-vehicle-cs-LC8" class="blob-code blob-code-inner js-file-line">
</td>
</tr>
<tr>
<td id="file-vehicle-cs-L9" class="blob-num js-line-number js-blob-rnum" data-line-number="9"></td>
<td id="file-vehicle-cs-LC9" class="blob-code blob-code-inner js-file-line">        public DateTime ProductionDate { get; set; }</td>
</tr>
<tr>
<td id="file-vehicle-cs-L10" class="blob-num js-line-number js-blob-rnum" data-line-number="10"></td>
<td id="file-vehicle-cs-LC10" class="blob-code blob-code-inner js-file-line">
</td>
</tr>
<tr>
<td id="file-vehicle-cs-L11" class="blob-num js-line-number js-blob-rnum" data-line-number="11"></td>
<td id="file-vehicle-cs-LC11" class="blob-code blob-code-inner js-file-line">        public decimal EngineCapacity { get; set; }</td>
</tr>
<tr>
<td id="file-vehicle-cs-L12" class="blob-num js-line-number js-blob-rnum" data-line-number="12"></td>
<td id="file-vehicle-cs-LC12" class="blob-code blob-code-inner js-file-line">
</td>
</tr>
<tr>
<td id="file-vehicle-cs-L13" class="blob-num js-line-number js-blob-rnum" data-line-number="13"></td>
<td id="file-vehicle-cs-LC13" class="blob-code blob-code-inner js-file-line">        [ForeignKey(typeof(RegistrationCertificate))]</td>
</tr>
<tr>
<td id="file-vehicle-cs-L14" class="blob-num js-line-number js-blob-rnum" data-line-number="14"></td>
<td id="file-vehicle-cs-LC14" class="blob-code blob-code-inner js-file-line">        public int RegistrationCertificateId { get; set; }</td>
</tr>
<tr>
<td id="file-vehicle-cs-L15" class="blob-num js-line-number js-blob-rnum" data-line-number="15"></td>
<td id="file-vehicle-cs-LC15" class="blob-code blob-code-inner js-file-line">
</td>
</tr>
<tr>
<td id="file-vehicle-cs-L16" class="blob-num js-line-number js-blob-rnum" data-line-number="16"></td>
<td id="file-vehicle-cs-LC16" class="blob-code blob-code-inner js-file-line">        [OneToOne]</td>
</tr>
<tr>
<td id="file-vehicle-cs-L17" class="blob-num js-line-number js-blob-rnum" data-line-number="17"></td>
<td id="file-vehicle-cs-LC17" class="blob-code blob-code-inner js-file-line">        public RegistrationCertificate RegistrationCertificate { get; set; }</td>
</tr>
<tr>
<td id="file-vehicle-cs-L18" class="blob-num js-line-number js-blob-rnum" data-line-number="18"></td>
<td id="file-vehicle-cs-LC18" class="blob-code blob-code-inner js-file-line">    }</td>
</tr>
</table>
</div></div>
</p></div>
</div></div>
<div class="gist-meta">
        <a href="https://gist.github.com/dsibinski/7ad52df0e33b6a871c1c46f3e0e2dad0/raw/910a48a372f861e3779abb783c966690ad9e020f/Vehicle.cs" style="float:right" class="Link--inTextBlock">view raw</a><br />
        <a href="https://gist.github.com/dsibinski/7ad52df0e33b6a871c1c46f3e0e2dad0#file-vehicle-cs" class="Link--inTextBlock"><br />
          Vehicle.cs<br />
        </a><br />
        hosted with &#10084; by <a class="Link--inTextBlock" href="https://github.com">GitHub</a>
      </div>
</p></div>
</div>
<p>What&#8217;s interesting here is the <span style="color: #ff9900;">ForeignKeyAttribute</span> defined on <span style="color: #ff9900;">RegistrationCertificateId</span> property. It is &#8211; as its name says &#8211; the foreign key to the primary key of related entity (of type <span style="color: #ff9900;">RegistrationCertificate</span>).</p>
<p>The related entity property itself is decorated with <span style="color: #ff9900;">OneToOneAttribute</span>.</p>
<p>There&#8217;s nothing more we need to do to have this relationship modeled. We can already use it:</p>
<p><style>.gist table { margin-bottom: 0; }</style>
<div style="tab-size: 8" id="gist47893732" class="gist">
<div class="gist-file" translate="no" data-color-mode="light" data-light-theme="light">
<div class="gist-data">
<div class="js-gist-file-update-container js-task-list-container">
<div id="file-onetoone_noinv-cs" class="file my-2">
<div itemprop="text"
      class="Box-body p-0 blob-wrapper data type-c  "
      style="overflow: auto" tabindex="0" role="region"
      aria-label="OneToOne_noInv.cs content, created by dsibinski on 09:49AM on May 21, 2017."
    ></p>
<div class="js-check-hidden-unicode js-blob-code-container blob-code-content">
<p>  <template class="js-file-alert-template"></p>
<div data-view-component="true" class="flash flash-warn flash-full d-flex flex-items-center">
  <svg aria-hidden="true" data-component="Octicon" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-alert">
    <path d="M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"></path>
</svg><br />
    <span><br />
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.<br />
      <a class="Link--inTextBlock" href="https://github.co/hiddenchars" target="_blank">Learn more about bidirectional Unicode characters</a><br />
    </span></p>
<div data-view-component="true" class="flash-action">        <a href="{{ revealButtonHref }}" data-view-component="true" class="btn-sm btn">    Show hidden characters<br />
</a>
</div>
</div>
<p></template><br />
<template class="js-line-alert-template"><br />
  <span aria-label="This line has hidden Unicode characters" data-view-component="true" class="line-alert tooltipped tooltipped-e"><br />
    <svg aria-hidden="true" data-component="Octicon" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-alert">
    <path d="M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"></path>
</svg><br />
</span></template></p>
<table data-hpc class="highlight tab-size js-file-line-container" data-tab-size="4" data-paste-markdown-skip data-tagsearch-path="OneToOne_noInv.cs">
<tr>
<td id="file-onetoone_noinv-cs-L1" class="blob-num js-line-number js-blob-rnum" data-line-number="1"></td>
<td id="file-onetoone_noinv-cs-LC1" class="blob-code blob-code-inner js-file-line">    var db = new SQLiteConnection(new SQLitePlatformAndroid(), Constants.DbFilePath);</td>
</tr>
<tr>
<td id="file-onetoone_noinv-cs-L2" class="blob-num js-line-number js-blob-rnum" data-line-number="2"></td>
<td id="file-onetoone_noinv-cs-LC2" class="blob-code blob-code-inner js-file-line">    db.CreateTable&lt;Vehicle&gt;();</td>
</tr>
<tr>
<td id="file-onetoone_noinv-cs-L3" class="blob-num js-line-number js-blob-rnum" data-line-number="3"></td>
<td id="file-onetoone_noinv-cs-LC3" class="blob-code blob-code-inner js-file-line">    db.CreateTable&lt;RegistrationCertificate&gt;();</td>
</tr>
<tr>
<td id="file-onetoone_noinv-cs-L4" class="blob-num js-line-number js-blob-rnum" data-line-number="4"></td>
<td id="file-onetoone_noinv-cs-LC4" class="blob-code blob-code-inner js-file-line">
</td>
</tr>
<tr>
<td id="file-onetoone_noinv-cs-L5" class="blob-num js-line-number js-blob-rnum" data-line-number="5"></td>
<td id="file-onetoone_noinv-cs-LC5" class="blob-code blob-code-inner js-file-line">    var vehicle = new Vehicle</td>
</tr>
<tr>
<td id="file-onetoone_noinv-cs-L6" class="blob-num js-line-number js-blob-rnum" data-line-number="6"></td>
<td id="file-onetoone_noinv-cs-LC6" class="blob-code blob-code-inner js-file-line">    {</td>
</tr>
<tr>
<td id="file-onetoone_noinv-cs-L7" class="blob-num js-line-number js-blob-rnum" data-line-number="7"></td>
<td id="file-onetoone_noinv-cs-LC7" class="blob-code blob-code-inner js-file-line">        Brand = &quot;Renault&quot;,</td>
</tr>
<tr>
<td id="file-onetoone_noinv-cs-L8" class="blob-num js-line-number js-blob-rnum" data-line-number="8"></td>
<td id="file-onetoone_noinv-cs-LC8" class="blob-code blob-code-inner js-file-line">        EngineCapacity = 1.9m,</td>
</tr>
<tr>
<td id="file-onetoone_noinv-cs-L9" class="blob-num js-line-number js-blob-rnum" data-line-number="9"></td>
<td id="file-onetoone_noinv-cs-LC9" class="blob-code blob-code-inner js-file-line">        ProductionDate = new DateTime(2001, 01, 01)</td>
</tr>
<tr>
<td id="file-onetoone_noinv-cs-L10" class="blob-num js-line-number js-blob-rnum" data-line-number="10"></td>
<td id="file-onetoone_noinv-cs-LC10" class="blob-code blob-code-inner js-file-line">    };</td>
</tr>
<tr>
<td id="file-onetoone_noinv-cs-L11" class="blob-num js-line-number js-blob-rnum" data-line-number="11"></td>
<td id="file-onetoone_noinv-cs-LC11" class="blob-code blob-code-inner js-file-line">
</td>
</tr>
<tr>
<td id="file-onetoone_noinv-cs-L12" class="blob-num js-line-number js-blob-rnum" data-line-number="12"></td>
<td id="file-onetoone_noinv-cs-LC12" class="blob-code blob-code-inner js-file-line">    var certificate = new RegistrationCertificate</td>
</tr>
<tr>
<td id="file-onetoone_noinv-cs-L13" class="blob-num js-line-number js-blob-rnum" data-line-number="13"></td>
<td id="file-onetoone_noinv-cs-LC13" class="blob-code blob-code-inner js-file-line">    {</td>
</tr>
<tr>
<td id="file-onetoone_noinv-cs-L14" class="blob-num js-line-number js-blob-rnum" data-line-number="14"></td>
<td id="file-onetoone_noinv-cs-LC14" class="blob-code blob-code-inner js-file-line">        RegistrationNumber = &quot;AB 12345&quot;,</td>
</tr>
<tr>
<td id="file-onetoone_noinv-cs-L15" class="blob-num js-line-number js-blob-rnum" data-line-number="15"></td>
<td id="file-onetoone_noinv-cs-LC15" class="blob-code blob-code-inner js-file-line">        OwnerData = &quot;Dawid Sibiński&quot;,</td>
</tr>
<tr>
<td id="file-onetoone_noinv-cs-L16" class="blob-num js-line-number js-blob-rnum" data-line-number="16"></td>
<td id="file-onetoone_noinv-cs-LC16" class="blob-code blob-code-inner js-file-line">        VIN = &quot;1312BS1312ASDSSVVW&quot;</td>
</tr>
<tr>
<td id="file-onetoone_noinv-cs-L17" class="blob-num js-line-number js-blob-rnum" data-line-number="17"></td>
<td id="file-onetoone_noinv-cs-LC17" class="blob-code blob-code-inner js-file-line">    };</td>
</tr>
<tr>
<td id="file-onetoone_noinv-cs-L18" class="blob-num js-line-number js-blob-rnum" data-line-number="18"></td>
<td id="file-onetoone_noinv-cs-LC18" class="blob-code blob-code-inner js-file-line">
</td>
</tr>
<tr>
<td id="file-onetoone_noinv-cs-L19" class="blob-num js-line-number js-blob-rnum" data-line-number="19"></td>
<td id="file-onetoone_noinv-cs-LC19" class="blob-code blob-code-inner js-file-line">    db.Insert(vehicle);</td>
</tr>
<tr>
<td id="file-onetoone_noinv-cs-L20" class="blob-num js-line-number js-blob-rnum" data-line-number="20"></td>
<td id="file-onetoone_noinv-cs-LC20" class="blob-code blob-code-inner js-file-line">    db.Insert(certificate);</td>
</tr>
<tr>
<td id="file-onetoone_noinv-cs-L21" class="blob-num js-line-number js-blob-rnum" data-line-number="21"></td>
<td id="file-onetoone_noinv-cs-LC21" class="blob-code blob-code-inner js-file-line">
</td>
</tr>
<tr>
<td id="file-onetoone_noinv-cs-L22" class="blob-num js-line-number js-blob-rnum" data-line-number="22"></td>
<td id="file-onetoone_noinv-cs-LC22" class="blob-code blob-code-inner js-file-line">    vehicle.RegistrationCertificate = certificate;</td>
</tr>
<tr>
<td id="file-onetoone_noinv-cs-L23" class="blob-num js-line-number js-blob-rnum" data-line-number="23"></td>
<td id="file-onetoone_noinv-cs-LC23" class="blob-code blob-code-inner js-file-line">    db.UpdateWithChildren(vehicle);</td>
</tr>
<tr>
<td id="file-onetoone_noinv-cs-L24" class="blob-num js-line-number js-blob-rnum" data-line-number="24"></td>
<td id="file-onetoone_noinv-cs-LC24" class="blob-code blob-code-inner js-file-line">
</td>
</tr>
<tr>
<td id="file-onetoone_noinv-cs-L25" class="blob-num js-line-number js-blob-rnum" data-line-number="25"></td>
<td id="file-onetoone_noinv-cs-LC25" class="blob-code blob-code-inner js-file-line">    var vehicleStored = db.GetWithChildren&lt;Vehicle&gt;(vehicle.Id);</td>
</tr>
</table>
</div></div>
</p></div>
</div></div>
<div class="gist-meta">
        <a href="https://gist.github.com/dsibinski/c04bd7030750a87ab3898621612eca03/raw/0430326856944469a47713ff2f61393fa349914e/OneToOne_noInv.cs" style="float:right" class="Link--inTextBlock">view raw</a><br />
        <a href="https://gist.github.com/dsibinski/c04bd7030750a87ab3898621612eca03#file-onetoone_noinv-cs" class="Link--inTextBlock"><br />
          OneToOne_noInv.cs<br />
        </a><br />
        hosted with &#10084; by <a class="Link--inTextBlock" href="https://github.com">GitHub</a>
      </div>
</p></div>
</div>
<p>Nothing special here, right? It looks very similar to what we&#8217;ve seen in the <a href="https://www.codejourney.net/2017/05/sqlite-net-extensions-many-to-many-relationships/" target="_blank" rel="noopener noreferrer">previous post about many-to-many relationships</a>. What&#8217;s interesting for us it that in the end, when <span style="color: #ff9900;">Vehicle</span> object is retrieved from the database using <span style="color: #ff9900;">GetWithChildren</span> method, its <span style="color: #ff9900;">RegistrationCertificate</span> property is filled as well:</p>
<figure id="attachment_2242" aria-describedby="caption-attachment-2242" style="width: 521px" class="wp-caption aligncenter"><a href="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/1t1_noRev_debug.png?ssl=1" target="_blank" rel="noopener noreferrer"><img data-recalc-dims="1" loading="lazy" decoding="async" data-attachment-id="2242" data-permalink="https://www.codejourney.net/sqlite-net-extensions-one-to-one-relationships/1t1_norev_debug/" data-orig-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/1t1_noRev_debug.png?fit=809%2C334&amp;ssl=1" data-orig-size="809,334" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="1t1_noRev_debug" data-image-description="" data-image-caption="&lt;p&gt;One-To-One &amp;#8211; filled related entity&lt;/p&gt;
" data-large-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/1t1_noRev_debug.png?fit=809%2C334&amp;ssl=1" class="wp-image-2242" src="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/1t1_noRev_debug.png?resize=521%2C215&#038;ssl=1" alt="" width="521" height="215" srcset="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/1t1_noRev_debug.png?resize=300%2C124&amp;ssl=1 300w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/1t1_noRev_debug.png?resize=768%2C317&amp;ssl=1 768w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/1t1_noRev_debug.png?resize=720%2C297&amp;ssl=1 720w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/1t1_noRev_debug.png?w=809&amp;ssl=1 809w" sizes="auto, (max-width: 521px) 100vw, 521px" /></a><figcaption id="caption-attachment-2242" class="wp-caption-text">One-To-One &#8211; filled related entity</figcaption></figure>
<h4>One-To-One with inversion (both-ways)</h4>
<p>This kind of relationship models itself as below:</p>
<figure id="attachment_2241" aria-describedby="caption-attachment-2241" style="width: 560px" class="wp-caption aligncenter"><a href="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/1t1_withRec.jpg?ssl=1" target="_blank" rel="noopener noreferrer"><img data-recalc-dims="1" loading="lazy" decoding="async" data-attachment-id="2241" data-permalink="https://www.codejourney.net/sqlite-net-extensions-one-to-one-relationships/1t1_withrec/" data-orig-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/1t1_withRec.jpg?fit=549%2C135&amp;ssl=1" data-orig-size="549,135" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;Dawid Sibi\u0144ski&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;1495366361&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="1t1_withRec" data-image-description="" data-image-caption="&lt;p&gt;One-To-One &amp;#8211; with reversion&lt;/p&gt;
" data-large-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/1t1_withRec.jpg?fit=549%2C135&amp;ssl=1" class="wp-image-2241" src="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/1t1_withRec.jpg?resize=560%2C138&#038;ssl=1" alt="" width="560" height="138" srcset="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/1t1_withRec.jpg?resize=300%2C74&amp;ssl=1 300w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/1t1_withRec.jpg?w=549&amp;ssl=1 549w" sizes="auto, (max-width: 560px) 100vw, 560px" /></a><figcaption id="caption-attachment-2241" class="wp-caption-text">One-To-One &#8211; with inversion &#8211; class diagram</figcaption></figure>
<p>What actually changed on the diagram compared to the relationship with no inversion is that now <span style="color: #ff9900;">RegistrationCertificate</span> has a property of type <span style="color: #ff9900;">Vehicle</span> (in the code &#8211; a reference to <span style="color: #ff9900;">Vehicle</span> related object and a foreign key).</p>
<p>In our case, this is even more &#8220;real&#8221; &#8211; it would be nice if a <span style="color: #ff9900;">Vehicle</span> knows about its <span style="color: #ff9900;">RegistrationCertificate</span>, but also when we look at the certificate we&#8217;d like to see to which car it belongs.</p>
<p>We can now model it in the code. The only thing that changes in the model classes is addition of a reference and foreign key to <span style="color: #ff9900;">Vehicle</span> in <span style="color: #ff9900;">RegistrationCertificate</span> model, so I&#8217;m presenting only this class&#8217;s updated code:</p>
<p><style>.gist table { margin-bottom: 0; }</style>
<div style="tab-size: 8" id="gist47893923" class="gist">
<div class="gist-file" translate="no" data-color-mode="light" data-light-theme="light">
<div class="gist-data">
<div class="js-gist-file-update-container js-task-list-container">
<div id="file-registrationcertificate_withinv-cs" class="file my-2">
<div itemprop="text"
      class="Box-body p-0 blob-wrapper data type-c  "
      style="overflow: auto" tabindex="0" role="region"
      aria-label="RegistrationCertificate_withInv.cs content, created by dsibinski on 09:59AM on May 21, 2017."
    ></p>
<div class="js-check-hidden-unicode js-blob-code-container blob-code-content">
<p>  <template class="js-file-alert-template"></p>
<div data-view-component="true" class="flash flash-warn flash-full d-flex flex-items-center">
  <svg aria-hidden="true" data-component="Octicon" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-alert">
    <path d="M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"></path>
</svg><br />
    <span><br />
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.<br />
      <a class="Link--inTextBlock" href="https://github.co/hiddenchars" target="_blank">Learn more about bidirectional Unicode characters</a><br />
    </span></p>
<div data-view-component="true" class="flash-action">        <a href="{{ revealButtonHref }}" data-view-component="true" class="btn-sm btn">    Show hidden characters<br />
</a>
</div>
</div>
<p></template><br />
<template class="js-line-alert-template"><br />
  <span aria-label="This line has hidden Unicode characters" data-view-component="true" class="line-alert tooltipped tooltipped-e"><br />
    <svg aria-hidden="true" data-component="Octicon" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-alert">
    <path d="M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"></path>
</svg><br />
</span></template></p>
<table data-hpc class="highlight tab-size js-file-line-container" data-tab-size="4" data-paste-markdown-skip data-tagsearch-path="RegistrationCertificate_withInv.cs">
<tr>
<td id="file-registrationcertificate_withinv-cs-L1" class="blob-num js-line-number js-blob-rnum" data-line-number="1"></td>
<td id="file-registrationcertificate_withinv-cs-LC1" class="blob-code blob-code-inner js-file-line">    [Table(&quot;RegistrationCertificates&quot;)]</td>
</tr>
<tr>
<td id="file-registrationcertificate_withinv-cs-L2" class="blob-num js-line-number js-blob-rnum" data-line-number="2"></td>
<td id="file-registrationcertificate_withinv-cs-LC2" class="blob-code blob-code-inner js-file-line">    public class RegistrationCertificate</td>
</tr>
<tr>
<td id="file-registrationcertificate_withinv-cs-L3" class="blob-num js-line-number js-blob-rnum" data-line-number="3"></td>
<td id="file-registrationcertificate_withinv-cs-LC3" class="blob-code blob-code-inner js-file-line">    {</td>
</tr>
<tr>
<td id="file-registrationcertificate_withinv-cs-L4" class="blob-num js-line-number js-blob-rnum" data-line-number="4"></td>
<td id="file-registrationcertificate_withinv-cs-LC4" class="blob-code blob-code-inner js-file-line">        [PrimaryKey, AutoIncrement]</td>
</tr>
<tr>
<td id="file-registrationcertificate_withinv-cs-L5" class="blob-num js-line-number js-blob-rnum" data-line-number="5"></td>
<td id="file-registrationcertificate_withinv-cs-LC5" class="blob-code blob-code-inner js-file-line">        public int Id { get; set; }</td>
</tr>
<tr>
<td id="file-registrationcertificate_withinv-cs-L6" class="blob-num js-line-number js-blob-rnum" data-line-number="6"></td>
<td id="file-registrationcertificate_withinv-cs-LC6" class="blob-code blob-code-inner js-file-line">
</td>
</tr>
<tr>
<td id="file-registrationcertificate_withinv-cs-L7" class="blob-num js-line-number js-blob-rnum" data-line-number="7"></td>
<td id="file-registrationcertificate_withinv-cs-LC7" class="blob-code blob-code-inner js-file-line">        public string RegistrationNumber { get; set; }</td>
</tr>
<tr>
<td id="file-registrationcertificate_withinv-cs-L8" class="blob-num js-line-number js-blob-rnum" data-line-number="8"></td>
<td id="file-registrationcertificate_withinv-cs-LC8" class="blob-code blob-code-inner js-file-line">
</td>
</tr>
<tr>
<td id="file-registrationcertificate_withinv-cs-L9" class="blob-num js-line-number js-blob-rnum" data-line-number="9"></td>
<td id="file-registrationcertificate_withinv-cs-LC9" class="blob-code blob-code-inner js-file-line">        public string VIN { get; set; }</td>
</tr>
<tr>
<td id="file-registrationcertificate_withinv-cs-L10" class="blob-num js-line-number js-blob-rnum" data-line-number="10"></td>
<td id="file-registrationcertificate_withinv-cs-LC10" class="blob-code blob-code-inner js-file-line">
</td>
</tr>
<tr>
<td id="file-registrationcertificate_withinv-cs-L11" class="blob-num js-line-number js-blob-rnum" data-line-number="11"></td>
<td id="file-registrationcertificate_withinv-cs-LC11" class="blob-code blob-code-inner js-file-line">        public string OwnerData { get; set; }</td>
</tr>
<tr>
<td id="file-registrationcertificate_withinv-cs-L12" class="blob-num js-line-number js-blob-rnum" data-line-number="12"></td>
<td id="file-registrationcertificate_withinv-cs-LC12" class="blob-code blob-code-inner js-file-line">
</td>
</tr>
<tr>
<td id="file-registrationcertificate_withinv-cs-L13" class="blob-num js-line-number js-blob-rnum" data-line-number="13"></td>
<td id="file-registrationcertificate_withinv-cs-LC13" class="blob-code blob-code-inner js-file-line">        // added to have Inversion relationship</td>
</tr>
<tr>
<td id="file-registrationcertificate_withinv-cs-L14" class="blob-num js-line-number js-blob-rnum" data-line-number="14"></td>
<td id="file-registrationcertificate_withinv-cs-LC14" class="blob-code blob-code-inner js-file-line">        [ForeignKey(typeof(Vehicle))]</td>
</tr>
<tr>
<td id="file-registrationcertificate_withinv-cs-L15" class="blob-num js-line-number js-blob-rnum" data-line-number="15"></td>
<td id="file-registrationcertificate_withinv-cs-LC15" class="blob-code blob-code-inner js-file-line">        public int VehicleId { get; set; }</td>
</tr>
<tr>
<td id="file-registrationcertificate_withinv-cs-L16" class="blob-num js-line-number js-blob-rnum" data-line-number="16"></td>
<td id="file-registrationcertificate_withinv-cs-LC16" class="blob-code blob-code-inner js-file-line">
</td>
</tr>
<tr>
<td id="file-registrationcertificate_withinv-cs-L17" class="blob-num js-line-number js-blob-rnum" data-line-number="17"></td>
<td id="file-registrationcertificate_withinv-cs-LC17" class="blob-code blob-code-inner js-file-line">        [OneToOne]</td>
</tr>
<tr>
<td id="file-registrationcertificate_withinv-cs-L18" class="blob-num js-line-number js-blob-rnum" data-line-number="18"></td>
<td id="file-registrationcertificate_withinv-cs-LC18" class="blob-code blob-code-inner js-file-line">        public Vehicle Vehicle { get; set; }</td>
</tr>
<tr>
<td id="file-registrationcertificate_withinv-cs-L19" class="blob-num js-line-number js-blob-rnum" data-line-number="19"></td>
<td id="file-registrationcertificate_withinv-cs-LC19" class="blob-code blob-code-inner js-file-line">    }</td>
</tr>
</table>
</div></div>
</p></div>
</div></div>
<div class="gist-meta">
        <a href="https://gist.github.com/dsibinski/6b5c7250deff7193c3e127dde2c2a947/raw/1b3f383df9c626044d01225b64bcd94c3004ec9c/RegistrationCertificate_withInv.cs" style="float:right" class="Link--inTextBlock">view raw</a><br />
        <a href="https://gist.github.com/dsibinski/6b5c7250deff7193c3e127dde2c2a947#file-registrationcertificate_withinv-cs" class="Link--inTextBlock"><br />
          RegistrationCertificate_withInv.cs<br />
        </a><br />
        hosted with &#10084; by <a class="Link--inTextBlock" href="https://github.com">GitHub</a>
      </div>
</p></div>
</div>
<p>What&#8217;s cool here is that we don&#8217;t need to modify our code for saving entities with relationships into SQLite database. We can simply add the following line at the end:</p>
<pre><pre class="brush: csharp; title: ; notranslate">var certificateStored = db.GetWithChildren&amp;lt;RegistrationCertificate&amp;gt;(certificate.Id);</pre>
<p>and notice that <span style="color: #ff9900;">certificateStored</span> already contains its associated <span style="color: #ff9900;">Vehicle</span> object:</p>
<figure id="attachment_2243" aria-describedby="caption-attachment-2243" style="width: 604px" class="wp-caption aligncenter"><a href="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/1t1_withRev_debug.png?ssl=1"><img data-recalc-dims="1" loading="lazy" decoding="async" data-attachment-id="2243" data-permalink="https://www.codejourney.net/sqlite-net-extensions-one-to-one-relationships/1t1_withrev_debug/" data-orig-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/1t1_withRev_debug.png?fit=939%2C362&amp;ssl=1" data-orig-size="939,362" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="1t1_withRev_debug" data-image-description="" data-image-caption="&lt;p&gt;One-To-One &amp;#8211; Vehicle initialized&lt;/p&gt;
" data-large-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/1t1_withRev_debug.png?fit=939%2C362&amp;ssl=1" class=" wp-image-2243" src="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/1t1_withRev_debug.png?resize=604%2C234&#038;ssl=1" alt="" width="604" height="234" srcset="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/1t1_withRev_debug.png?resize=300%2C116&amp;ssl=1 300w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/1t1_withRev_debug.png?resize=768%2C296&amp;ssl=1 768w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/1t1_withRev_debug.png?resize=720%2C278&amp;ssl=1 720w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/1t1_withRev_debug.png?w=939&amp;ssl=1 939w" sizes="auto, (max-width: 604px) 100vw, 604px" /></a><figcaption id="caption-attachment-2243" class="wp-caption-text">One-To-One &#8211; Vehicle initialized</figcaption></figure>
<h2>Summary</h2>
<p>In today&#8217;s short post we&#8217;ve seen how to create one-to-one relationship between two entities in SQLite database, using SQLite-Net Extensions ORM. It&#8217;s very easy and doesn&#8217;t require using Entity Framework <img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f642.png" alt="🙂" class="wp-smiley" style="height: 1em; max-height: 1em;" /> or writing SQL queries directly in our code.</p>
<p>We&#8217;ve covered two types of one-to-one relationships: one-way and both-ways. The choice between those two depends on the usage and purpose of the relationship we model.</p>
<p>I hope you&#8217;ll find it useful one day <img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f609.png" alt="😉" class="wp-smiley" style="height: 1em; max-height: 1em;" /></p>
<p>The post <a href="https://www.codejourney.net/sqlite-net-extensions-one-to-one-relationships/">SQLite-Net Extensions – one-to-one relationships</a> appeared first on <a href="https://www.codejourney.net">CodeJourney.net</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.codejourney.net/sqlite-net-extensions-one-to-one-relationships/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">2238</post-id>	</item>
		<item>
		<title>SQLite-Net Extensions &#8211; many-to-many relationships</title>
		<link>https://www.codejourney.net/sqlite-net-extensions-many-to-many-relationships/</link>
					<comments>https://www.codejourney.net/sqlite-net-extensions-many-to-many-relationships/#comments</comments>
		
		<dc:creator><![CDATA[Dawid Sibiński]]></dc:creator>
		<pubDate>Thu, 18 May 2017 21:23:31 +0000</pubDate>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[android]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[dajsiepoznac2017]]></category>
		<category><![CDATA[sqlite-net-extensions]]></category>
		<category><![CDATA[xamarin]]></category>
		<guid isPermaLink="false">http://www.dsibinski.pl/?p=2218</guid>

					<description><![CDATA[<p>In today&#8217;s post we&#8217;re going to see what is SQLite-Net Extensions ORM and how to use it to create many-to-many relationship in SQLite database. The other types of relationships will be described in separate posts. What is SQLite-Net Extensions ? As you develop any mobile app, sooner than later you need to keep your app&#8217;s data&#8230;</p>
<p>The post <a href="https://www.codejourney.net/sqlite-net-extensions-many-to-many-relationships/">SQLite-Net Extensions &#8211; many-to-many relationships</a> appeared first on <a href="https://www.codejourney.net">CodeJourney.net</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>In today&#8217;s post we&#8217;re going to see what is SQLite-Net Extensions ORM and how to use it to create many-to-many relationship in SQLite database. The other types of relationships will be described <a href="https://www.codejourney.net/tag/sqlite-net-extensions/" target="_blank" rel="noopener noreferrer">in separate posts</a>.<br />
<span id="more-2218"></span></p>
<h2>What is SQLite-Net Extensions ?</h2>
<p>As you develop any mobile app, sooner than later you need to keep your app&#8217;s data in some persistent storage. In my <em>MoneyBack </em>project I&#8217;ve chosen<em> </em><a href="https://www.codejourney.net/2017/03/using-sqlite-database-in-xamarin-android/" target="_blank" rel="noopener noreferrer">SQLite database using SQLite.NET library for performing operations on it</a>. This is actually very simple and easy-to-use database framework, but I recently realized I need to model some <strong><a href="https://en.wikipedia.org/wiki/Relation_(database)" target="_blank" rel="noopener noreferrer">relations</a> </strong>in my database.  <a href="https://www.nuget.org/packages/sqlite-net/" target="_blank" rel="noopener noreferrer">SQLite.NET</a> doesn&#8217;t offer any nice utilities to model such relations.</p>
<p>However, if you need to model any relations in your SQLite database, there is a wrapper on SQLite.NET which allows to do that &#8211; it is <strong>SQLite-Net Extensions</strong>. It basically extends the core functionalities of SQLite.NET by adding elements that allow to easily handle relationships, including one-to-one, one-to-many, many-to-one and many-to-many.</p>
<p>In this post we are going to see how to create many-to-many relationship using this library. I needed this kind of relationship to model the connection between Person and Event entities in my app.</p>
<h2>Many-to-many relationship</h2>
<p>Let&#8217;s see many-to-many relationship on an example of two entities: <strong>Person</strong> and <strong>Event</strong>. An event (entity of type <span style="color: #ff9900;">Event</span>) may contain zero or more participants (entities of type <span style="color: #ff9900;">Person</span>) whilst a person may be assigned to zero or more events. This is a typical many-to-many relationship which we are going to set up in our database now.</p>
<h2>Install SQLite-Net Extensions</h2>
<p>If you&#8217;ve previously been using <a href="https://www.nuget.org/packages/sqlite-net/" target="_blank" rel="noopener noreferrer">SQLite.NET</a> in your project &#8211; uninstall it first. I didn&#8217;t do it before starting to use SQLite-Net Extensions and I have many troubles with Visual Studio resolving my references incorrectly. SQLite-Net Extensions is a wrapper for SQLite.NET, so it already contains this library and additionally extends it by adding some extra functionalities for handling relationships.</p>
<p>SQLite-Net Extensions can be installed as a Nuget package into your solution. According to the version you&#8217;d like to use, execute appropriate command in Package Manager Console in Visual Studio:</p>
<ul>
<li>synchronous:
<pre><pre class="brush: csharp; title: ; notranslate">Install-Package SQLiteNetExtensions -Version 1.3.0</pre>
</li>
<li>asynchronous:
<pre><pre class="brush: csharp; title: ; notranslate">Install-Package SQLiteNetExtensions.Async -Version 1.3.0</pre>
</li>
</ul>
<h2>Define model classes</h2>
<p>Next we need to define our <span style="color: #ff9900;">Person</span> and <span style="color: #ff9900;">Event</span> model classes and establish the relationships between them. Below, you can find the code of both classes:</p>
<p><style>.gist table { margin-bottom: 0; }</style>
<div style="tab-size: 8" id="gist47815728" class="gist">
<div class="gist-file" translate="no" data-color-mode="light" data-light-theme="light">
<div class="gist-data">
<div class="js-gist-file-update-container js-task-list-container">
<div id="file-person_event-cs" class="file my-2">
<div itemprop="text"
      class="Box-body p-0 blob-wrapper data type-c  "
      style="overflow: auto" tabindex="0" role="region"
      aria-label="Person_Event.cs content, created by dsibinski on 08:27PM on May 18, 2017."
    ></p>
<div class="js-check-hidden-unicode js-blob-code-container blob-code-content">
<p>  <template class="js-file-alert-template"></p>
<div data-view-component="true" class="flash flash-warn flash-full d-flex flex-items-center">
  <svg aria-hidden="true" data-component="Octicon" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-alert">
    <path d="M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"></path>
</svg><br />
    <span><br />
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.<br />
      <a class="Link--inTextBlock" href="https://github.co/hiddenchars" target="_blank">Learn more about bidirectional Unicode characters</a><br />
    </span></p>
<div data-view-component="true" class="flash-action">        <a href="{{ revealButtonHref }}" data-view-component="true" class="btn-sm btn">    Show hidden characters<br />
</a>
</div>
</div>
<p></template><br />
<template class="js-line-alert-template"><br />
  <span aria-label="This line has hidden Unicode characters" data-view-component="true" class="line-alert tooltipped tooltipped-e"><br />
    <svg aria-hidden="true" data-component="Octicon" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-alert">
    <path d="M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"></path>
</svg><br />
</span></template></p>
<table data-hpc class="highlight tab-size js-file-line-container" data-tab-size="4" data-paste-markdown-skip data-tagsearch-path="Person_Event.cs">
<tr>
<td id="file-person_event-cs-L1" class="blob-num js-line-number js-blob-rnum" data-line-number="1"></td>
<td id="file-person_event-cs-LC1" class="blob-code blob-code-inner js-file-line">// Person class modelling People table</td>
</tr>
<tr>
<td id="file-person_event-cs-L2" class="blob-num js-line-number js-blob-rnum" data-line-number="2"></td>
<td id="file-person_event-cs-LC2" class="blob-code blob-code-inner js-file-line">[Table(&quot;People&quot;)]</td>
</tr>
<tr>
<td id="file-person_event-cs-L3" class="blob-num js-line-number js-blob-rnum" data-line-number="3"></td>
<td id="file-person_event-cs-LC3" class="blob-code blob-code-inner js-file-line">public class Person</td>
</tr>
<tr>
<td id="file-person_event-cs-L4" class="blob-num js-line-number js-blob-rnum" data-line-number="4"></td>
<td id="file-person_event-cs-LC4" class="blob-code blob-code-inner js-file-line">{</td>
</tr>
<tr>
<td id="file-person_event-cs-L5" class="blob-num js-line-number js-blob-rnum" data-line-number="5"></td>
<td id="file-person_event-cs-LC5" class="blob-code blob-code-inner js-file-line">    [PrimaryKey, AutoIncrement]</td>
</tr>
<tr>
<td id="file-person_event-cs-L6" class="blob-num js-line-number js-blob-rnum" data-line-number="6"></td>
<td id="file-person_event-cs-LC6" class="blob-code blob-code-inner js-file-line">    public int Id { get; set; }</td>
</tr>
<tr>
<td id="file-person_event-cs-L7" class="blob-num js-line-number js-blob-rnum" data-line-number="7"></td>
<td id="file-person_event-cs-LC7" class="blob-code blob-code-inner js-file-line">
</td>
</tr>
<tr>
<td id="file-person_event-cs-L8" class="blob-num js-line-number js-blob-rnum" data-line-number="8"></td>
<td id="file-person_event-cs-LC8" class="blob-code blob-code-inner js-file-line">    public string Name { get; set; }</td>
</tr>
<tr>
<td id="file-person_event-cs-L9" class="blob-num js-line-number js-blob-rnum" data-line-number="9"></td>
<td id="file-person_event-cs-LC9" class="blob-code blob-code-inner js-file-line">
</td>
</tr>
<tr>
<td id="file-person_event-cs-L10" class="blob-num js-line-number js-blob-rnum" data-line-number="10"></td>
<td id="file-person_event-cs-LC10" class="blob-code blob-code-inner js-file-line">    public string LastName { get; set; }</td>
</tr>
<tr>
<td id="file-person_event-cs-L11" class="blob-num js-line-number js-blob-rnum" data-line-number="11"></td>
<td id="file-person_event-cs-LC11" class="blob-code blob-code-inner js-file-line">
</td>
</tr>
<tr>
<td id="file-person_event-cs-L12" class="blob-num js-line-number js-blob-rnum" data-line-number="12"></td>
<td id="file-person_event-cs-LC12" class="blob-code blob-code-inner js-file-line">    public string PhoneNumber { get; set; }</td>
</tr>
<tr>
<td id="file-person_event-cs-L13" class="blob-num js-line-number js-blob-rnum" data-line-number="13"></td>
<td id="file-person_event-cs-LC13" class="blob-code blob-code-inner js-file-line">
</td>
</tr>
<tr>
<td id="file-person_event-cs-L14" class="blob-num js-line-number js-blob-rnum" data-line-number="14"></td>
<td id="file-person_event-cs-LC14" class="blob-code blob-code-inner js-file-line">    public string Email { get; set; }</td>
</tr>
<tr>
<td id="file-person_event-cs-L15" class="blob-num js-line-number js-blob-rnum" data-line-number="15"></td>
<td id="file-person_event-cs-LC15" class="blob-code blob-code-inner js-file-line">
</td>
</tr>
<tr>
<td id="file-person_event-cs-L16" class="blob-num js-line-number js-blob-rnum" data-line-number="16"></td>
<td id="file-person_event-cs-LC16" class="blob-code blob-code-inner js-file-line">    [ManyToMany(typeof(PersonEvent))]</td>
</tr>
<tr>
<td id="file-person_event-cs-L17" class="blob-num js-line-number js-blob-rnum" data-line-number="17"></td>
<td id="file-person_event-cs-LC17" class="blob-code blob-code-inner js-file-line">    public List&lt;Event&gt; Events { get; set; }</td>
</tr>
<tr>
<td id="file-person_event-cs-L18" class="blob-num js-line-number js-blob-rnum" data-line-number="18"></td>
<td id="file-person_event-cs-LC18" class="blob-code blob-code-inner js-file-line">}</td>
</tr>
<tr>
<td id="file-person_event-cs-L19" class="blob-num js-line-number js-blob-rnum" data-line-number="19"></td>
<td id="file-person_event-cs-LC19" class="blob-code blob-code-inner js-file-line">
</td>
</tr>
<tr>
<td id="file-person_event-cs-L20" class="blob-num js-line-number js-blob-rnum" data-line-number="20"></td>
<td id="file-person_event-cs-LC20" class="blob-code blob-code-inner js-file-line">
</td>
</tr>
<tr>
<td id="file-person_event-cs-L21" class="blob-num js-line-number js-blob-rnum" data-line-number="21"></td>
<td id="file-person_event-cs-LC21" class="blob-code blob-code-inner js-file-line">// Event class modelling Events table</td>
</tr>
<tr>
<td id="file-person_event-cs-L22" class="blob-num js-line-number js-blob-rnum" data-line-number="22"></td>
<td id="file-person_event-cs-LC22" class="blob-code blob-code-inner js-file-line">[Table(&quot;Events&quot;)]</td>
</tr>
<tr>
<td id="file-person_event-cs-L23" class="blob-num js-line-number js-blob-rnum" data-line-number="23"></td>
<td id="file-person_event-cs-LC23" class="blob-code blob-code-inner js-file-line">public class Event</td>
</tr>
<tr>
<td id="file-person_event-cs-L24" class="blob-num js-line-number js-blob-rnum" data-line-number="24"></td>
<td id="file-person_event-cs-LC24" class="blob-code blob-code-inner js-file-line">{</td>
</tr>
<tr>
<td id="file-person_event-cs-L25" class="blob-num js-line-number js-blob-rnum" data-line-number="25"></td>
<td id="file-person_event-cs-LC25" class="blob-code blob-code-inner js-file-line">    [PrimaryKey, AutoIncrement]</td>
</tr>
<tr>
<td id="file-person_event-cs-L26" class="blob-num js-line-number js-blob-rnum" data-line-number="26"></td>
<td id="file-person_event-cs-LC26" class="blob-code blob-code-inner js-file-line">    public int Id { get; set; }</td>
</tr>
<tr>
<td id="file-person_event-cs-L27" class="blob-num js-line-number js-blob-rnum" data-line-number="27"></td>
<td id="file-person_event-cs-LC27" class="blob-code blob-code-inner js-file-line">
</td>
</tr>
<tr>
<td id="file-person_event-cs-L28" class="blob-num js-line-number js-blob-rnum" data-line-number="28"></td>
<td id="file-person_event-cs-LC28" class="blob-code blob-code-inner js-file-line">    public string Name { get; set; }</td>
</tr>
<tr>
<td id="file-person_event-cs-L29" class="blob-num js-line-number js-blob-rnum" data-line-number="29"></td>
<td id="file-person_event-cs-LC29" class="blob-code blob-code-inner js-file-line">    public DateTime Date { get; set; }</td>
</tr>
<tr>
<td id="file-person_event-cs-L30" class="blob-num js-line-number js-blob-rnum" data-line-number="30"></td>
<td id="file-person_event-cs-LC30" class="blob-code blob-code-inner js-file-line">    public string Place { get; set; }</td>
</tr>
<tr>
<td id="file-person_event-cs-L31" class="blob-num js-line-number js-blob-rnum" data-line-number="31"></td>
<td id="file-person_event-cs-LC31" class="blob-code blob-code-inner js-file-line">
</td>
</tr>
<tr>
<td id="file-person_event-cs-L32" class="blob-num js-line-number js-blob-rnum" data-line-number="32"></td>
<td id="file-person_event-cs-LC32" class="blob-code blob-code-inner js-file-line">    [ManyToMany(typeof(PersonEvent))]</td>
</tr>
<tr>
<td id="file-person_event-cs-L33" class="blob-num js-line-number js-blob-rnum" data-line-number="33"></td>
<td id="file-person_event-cs-LC33" class="blob-code blob-code-inner js-file-line">    public List&lt;Person&gt; Participants { get; set; }</td>
</tr>
<tr>
<td id="file-person_event-cs-L34" class="blob-num js-line-number js-blob-rnum" data-line-number="34"></td>
<td id="file-person_event-cs-LC34" class="blob-code blob-code-inner js-file-line">}</td>
</tr>
</table>
</div></div>
</p></div>
</div></div>
<div class="gist-meta">
        <a href="https://gist.github.com/dsibinski/1b0f1411d6478c7bebc55a451fbda068/raw/70311b99cece5a78262021d3e63a6034ded89ae2/Person_Event.cs" style="float:right" class="Link--inTextBlock">view raw</a><br />
        <a href="https://gist.github.com/dsibinski/1b0f1411d6478c7bebc55a451fbda068#file-person_event-cs" class="Link--inTextBlock"><br />
          Person_Event.cs<br />
        </a><br />
        hosted with &#10084; by <a class="Link--inTextBlock" href="https://github.com">GitHub</a>
      </div>
</p></div>
</div>
<p>As you can see, the models look almost the same as SQLite.NET db entities, with the following exceptions:</p>
<ul>
<li><span style="color: #ff9900;">ManyToManyAttribute<span style="color: #000000;"> &#8211; o</span></span>n both entities you can notice this attribute defined. On <span style="color: #ff9900;">Person</span> model class I decorate <span style="color: #ff9900;">Events</span> collection with it whereas on <span style="color: #ff9900;">Event</span> model class I decorate <span style="color: #ff9900;">Participants</span> collection with it. Simple as that.</li>
<li><span style="color: #ff9900;">PersonEvent <span style="color: #000000;">&#8211; y</span></span>ou may have noticed that as an argument to <span style="color: #ff9900;">ManyToManyAttribute</span> on both models I passed <span style="color: #ff9900;">PersonEvent</span> type. As you may know, in modelling many-to-many relationships we need an intermediate entity in order to store such kind of relationship in the database tables. The classic example is Student-Course relationship:<br />
<figure id="attachment_2221" aria-describedby="caption-attachment-2221" style="width: 337px" class="wp-caption aligncenter"><a href="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/erd-many-to-many-1.jpg?ssl=1"><img data-recalc-dims="1" loading="lazy" decoding="async" data-attachment-id="2221" data-permalink="https://www.codejourney.net/sqlite-net-extensions-many-to-many-relationships/erd-many-to-many-1/" data-orig-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/erd-many-to-many-1.jpg?fit=469%2C367&amp;ssl=1" data-orig-size="469,367" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="erd-many-to-many-1" data-image-description="" data-image-caption="&lt;p&gt;Source: smehrozalam&lt;/p&gt;
" data-large-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/erd-many-to-many-1.jpg?fit=469%2C367&amp;ssl=1" class=" wp-image-2221" src="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/erd-many-to-many-1.jpg?resize=337%2C264&#038;ssl=1" alt="" width="337" height="264" srcset="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/erd-many-to-many-1.jpg?resize=300%2C235&amp;ssl=1 300w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/erd-many-to-many-1.jpg?w=469&amp;ssl=1 469w" sizes="auto, (max-width: 337px) 100vw, 337px" /></a><figcaption id="caption-attachment-2221" class="wp-caption-text">Source: <a href="https://smehrozalam.wordpress.com/2010/06/29/entity-framework-queries-involving-many-to-many-relationship-tables/" target="_blank" rel="noopener noreferrer">smehrozalam</a></figcaption></figure></p>
<p>We also need to define such intermediate entity in our code.</p>
</li>
</ul>
<p>The implementation of <span style="color: #ff9900;">PersonEvent</span> intermediate model class looks as follows:</p>
<p><style>.gist table { margin-bottom: 0; }</style>
<div style="tab-size: 8" id="gist47816049" class="gist">
<div class="gist-file" translate="no" data-color-mode="light" data-light-theme="light">
<div class="gist-data">
<div class="js-gist-file-update-container js-task-list-container">
<div id="file-personevent-cs" class="file my-2">
<div itemprop="text"
      class="Box-body p-0 blob-wrapper data type-c  "
      style="overflow: auto" tabindex="0" role="region"
      aria-label="PersonEvent.cs content, created by dsibinski on 08:38PM on May 18, 2017."
    ></p>
<div class="js-check-hidden-unicode js-blob-code-container blob-code-content">
<p>  <template class="js-file-alert-template"></p>
<div data-view-component="true" class="flash flash-warn flash-full d-flex flex-items-center">
  <svg aria-hidden="true" data-component="Octicon" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-alert">
    <path d="M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"></path>
</svg><br />
    <span><br />
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.<br />
      <a class="Link--inTextBlock" href="https://github.co/hiddenchars" target="_blank">Learn more about bidirectional Unicode characters</a><br />
    </span></p>
<div data-view-component="true" class="flash-action">        <a href="{{ revealButtonHref }}" data-view-component="true" class="btn-sm btn">    Show hidden characters<br />
</a>
</div>
</div>
<p></template><br />
<template class="js-line-alert-template"><br />
  <span aria-label="This line has hidden Unicode characters" data-view-component="true" class="line-alert tooltipped tooltipped-e"><br />
    <svg aria-hidden="true" data-component="Octicon" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-alert">
    <path d="M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"></path>
</svg><br />
</span></template></p>
<table data-hpc class="highlight tab-size js-file-line-container" data-tab-size="4" data-paste-markdown-skip data-tagsearch-path="PersonEvent.cs">
<tr>
<td id="file-personevent-cs-L1" class="blob-num js-line-number js-blob-rnum" data-line-number="1"></td>
<td id="file-personevent-cs-LC1" class="blob-code blob-code-inner js-file-line">public class PersonEvent</td>
</tr>
<tr>
<td id="file-personevent-cs-L2" class="blob-num js-line-number js-blob-rnum" data-line-number="2"></td>
<td id="file-personevent-cs-LC2" class="blob-code blob-code-inner js-file-line">{</td>
</tr>
<tr>
<td id="file-personevent-cs-L3" class="blob-num js-line-number js-blob-rnum" data-line-number="3"></td>
<td id="file-personevent-cs-LC3" class="blob-code blob-code-inner js-file-line">    [ForeignKey(typeof(Person))]</td>
</tr>
<tr>
<td id="file-personevent-cs-L4" class="blob-num js-line-number js-blob-rnum" data-line-number="4"></td>
<td id="file-personevent-cs-LC4" class="blob-code blob-code-inner js-file-line">    public int PersonId { get; set; }</td>
</tr>
<tr>
<td id="file-personevent-cs-L5" class="blob-num js-line-number js-blob-rnum" data-line-number="5"></td>
<td id="file-personevent-cs-LC5" class="blob-code blob-code-inner js-file-line">
</td>
</tr>
<tr>
<td id="file-personevent-cs-L6" class="blob-num js-line-number js-blob-rnum" data-line-number="6"></td>
<td id="file-personevent-cs-LC6" class="blob-code blob-code-inner js-file-line">    [ForeignKey(typeof(Event))]</td>
</tr>
<tr>
<td id="file-personevent-cs-L7" class="blob-num js-line-number js-blob-rnum" data-line-number="7"></td>
<td id="file-personevent-cs-LC7" class="blob-code blob-code-inner js-file-line">    public int EventId { get; set; }</td>
</tr>
<tr>
<td id="file-personevent-cs-L8" class="blob-num js-line-number js-blob-rnum" data-line-number="8"></td>
<td id="file-personevent-cs-LC8" class="blob-code blob-code-inner js-file-line">}</td>
</tr>
</table>
</div></div>
</p></div>
</div></div>
<div class="gist-meta">
        <a href="https://gist.github.com/dsibinski/33dc1a774b183f4706174a3a656318b9/raw/e8244edf124388dfe058b148fe5bc67d8b71bc1e/PersonEvent.cs" style="float:right" class="Link--inTextBlock">view raw</a><br />
        <a href="https://gist.github.com/dsibinski/33dc1a774b183f4706174a3a656318b9#file-personevent-cs" class="Link--inTextBlock"><br />
          PersonEvent.cs<br />
        </a><br />
        hosted with &#10084; by <a class="Link--inTextBlock" href="https://github.com">GitHub</a>
      </div>
</p></div>
</div>
<p>Thanks to <span style="color: #ff9900;">PrimaryKey</span> attributes defined on <span style="color: #ff9900;">Person</span> and <span style="color: #ff9900;">Event</span> entities the ORM will be able to determine to which primary keys the foreign keys in this intermediate table relate.</p>
<p>In the <span style="color: #ff9900;">ManyToManyAttribute</span>, except the type of intermediate entity, you can set <span style="color: #ff9900;">CascadeOperations</span>, which specifies how the cascading should be handled when working with the entities (e.g. if cascade delete operation should be performed when one of the relationship&#8217;s sides is removed).</p>
<h2>Inserting and reading data</h2>
<p>As soon as our model classes are defined, we can write and read the data with many-to-many relationships. The following code presents a simple way to create a new person and assign it to an event:</p>
<p><style>.gist table { margin-bottom: 0; }</style>
<div style="tab-size: 8" id="gist47816466" class="gist">
<div class="gist-file" translate="no" data-color-mode="light" data-light-theme="light">
<div class="gist-data">
<div class="js-gist-file-update-container js-task-list-container">
<div id="file-savingpersonevent-cs" class="file my-2">
<div itemprop="text"
      class="Box-body p-0 blob-wrapper data type-c  "
      style="overflow: auto" tabindex="0" role="region"
      aria-label="SavingPersonEvent.cs content, created by dsibinski on 08:47PM on May 18, 2017."
    ></p>
<div class="js-check-hidden-unicode js-blob-code-container blob-code-content">
<p>  <template class="js-file-alert-template"></p>
<div data-view-component="true" class="flash flash-warn flash-full d-flex flex-items-center">
  <svg aria-hidden="true" data-component="Octicon" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-alert">
    <path d="M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"></path>
</svg><br />
    <span><br />
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.<br />
      <a class="Link--inTextBlock" href="https://github.co/hiddenchars" target="_blank">Learn more about bidirectional Unicode characters</a><br />
    </span></p>
<div data-view-component="true" class="flash-action">        <a href="{{ revealButtonHref }}" data-view-component="true" class="btn-sm btn">    Show hidden characters<br />
</a>
</div>
</div>
<p></template><br />
<template class="js-line-alert-template"><br />
  <span aria-label="This line has hidden Unicode characters" data-view-component="true" class="line-alert tooltipped tooltipped-e"><br />
    <svg aria-hidden="true" data-component="Octicon" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-alert">
    <path d="M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"></path>
</svg><br />
</span></template></p>
<table data-hpc class="highlight tab-size js-file-line-container" data-tab-size="4" data-paste-markdown-skip data-tagsearch-path="SavingPersonEvent.cs">
<tr>
<td id="file-savingpersonevent-cs-L1" class="blob-num js-line-number js-blob-rnum" data-line-number="1"></td>
<td id="file-savingpersonevent-cs-LC1" class="blob-code blob-code-inner js-file-line">var db = new SQLiteConnection(new SQLitePlatformAndroid(), Constants.DbFilePath);</td>
</tr>
<tr>
<td id="file-savingpersonevent-cs-L2" class="blob-num js-line-number js-blob-rnum" data-line-number="2"></td>
<td id="file-savingpersonevent-cs-LC2" class="blob-code blob-code-inner js-file-line">db.CreateTable&lt;Person&gt;();</td>
</tr>
<tr>
<td id="file-savingpersonevent-cs-L3" class="blob-num js-line-number js-blob-rnum" data-line-number="3"></td>
<td id="file-savingpersonevent-cs-LC3" class="blob-code blob-code-inner js-file-line">db.CreateTable&lt;Event&gt;();</td>
</tr>
<tr>
<td id="file-savingpersonevent-cs-L4" class="blob-num js-line-number js-blob-rnum" data-line-number="4"></td>
<td id="file-savingpersonevent-cs-LC4" class="blob-code blob-code-inner js-file-line">db.CreateTable&lt;PersonEvent&gt;();</td>
</tr>
<tr>
<td id="file-savingpersonevent-cs-L5" class="blob-num js-line-number js-blob-rnum" data-line-number="5"></td>
<td id="file-savingpersonevent-cs-LC5" class="blob-code blob-code-inner js-file-line">
</td>
</tr>
<tr>
<td id="file-savingpersonevent-cs-L6" class="blob-num js-line-number js-blob-rnum" data-line-number="6"></td>
<td id="file-savingpersonevent-cs-LC6" class="blob-code blob-code-inner js-file-line">var event1 = new Event</td>
</tr>
<tr>
<td id="file-savingpersonevent-cs-L7" class="blob-num js-line-number js-blob-rnum" data-line-number="7"></td>
<td id="file-savingpersonevent-cs-LC7" class="blob-code blob-code-inner js-file-line">{</td>
</tr>
<tr>
<td id="file-savingpersonevent-cs-L8" class="blob-num js-line-number js-blob-rnum" data-line-number="8"></td>
<td id="file-savingpersonevent-cs-LC8" class="blob-code blob-code-inner js-file-line">    Name = &quot;Volleyball&quot;,</td>
</tr>
<tr>
<td id="file-savingpersonevent-cs-L9" class="blob-num js-line-number js-blob-rnum" data-line-number="9"></td>
<td id="file-savingpersonevent-cs-LC9" class="blob-code blob-code-inner js-file-line">    Date = new DateTime(2017, 06, 18),</td>
</tr>
<tr>
<td id="file-savingpersonevent-cs-L10" class="blob-num js-line-number js-blob-rnum" data-line-number="10"></td>
<td id="file-savingpersonevent-cs-LC10" class="blob-code blob-code-inner js-file-line">    Place = &quot;Sports hall&quot;</td>
</tr>
<tr>
<td id="file-savingpersonevent-cs-L11" class="blob-num js-line-number js-blob-rnum" data-line-number="11"></td>
<td id="file-savingpersonevent-cs-LC11" class="blob-code blob-code-inner js-file-line">};</td>
</tr>
<tr>
<td id="file-savingpersonevent-cs-L12" class="blob-num js-line-number js-blob-rnum" data-line-number="12"></td>
<td id="file-savingpersonevent-cs-LC12" class="blob-code blob-code-inner js-file-line">
</td>
</tr>
<tr>
<td id="file-savingpersonevent-cs-L13" class="blob-num js-line-number js-blob-rnum" data-line-number="13"></td>
<td id="file-savingpersonevent-cs-LC13" class="blob-code blob-code-inner js-file-line">var person1 = new Person</td>
</tr>
<tr>
<td id="file-savingpersonevent-cs-L14" class="blob-num js-line-number js-blob-rnum" data-line-number="14"></td>
<td id="file-savingpersonevent-cs-LC14" class="blob-code blob-code-inner js-file-line">{</td>
</tr>
<tr>
<td id="file-savingpersonevent-cs-L15" class="blob-num js-line-number js-blob-rnum" data-line-number="15"></td>
<td id="file-savingpersonevent-cs-LC15" class="blob-code blob-code-inner js-file-line">    Name = &quot;A&quot;,</td>
</tr>
<tr>
<td id="file-savingpersonevent-cs-L16" class="blob-num js-line-number js-blob-rnum" data-line-number="16"></td>
<td id="file-savingpersonevent-cs-LC16" class="blob-code blob-code-inner js-file-line">    LastName = &quot;B&quot;,</td>
</tr>
<tr>
<td id="file-savingpersonevent-cs-L17" class="blob-num js-line-number js-blob-rnum" data-line-number="17"></td>
<td id="file-savingpersonevent-cs-LC17" class="blob-code blob-code-inner js-file-line">    PhoneNumber = &quot;123456789&quot;</td>
</tr>
<tr>
<td id="file-savingpersonevent-cs-L18" class="blob-num js-line-number js-blob-rnum" data-line-number="18"></td>
<td id="file-savingpersonevent-cs-LC18" class="blob-code blob-code-inner js-file-line">};</td>
</tr>
<tr>
<td id="file-savingpersonevent-cs-L19" class="blob-num js-line-number js-blob-rnum" data-line-number="19"></td>
<td id="file-savingpersonevent-cs-LC19" class="blob-code blob-code-inner js-file-line">
</td>
</tr>
<tr>
<td id="file-savingpersonevent-cs-L20" class="blob-num js-line-number js-blob-rnum" data-line-number="20"></td>
<td id="file-savingpersonevent-cs-LC20" class="blob-code blob-code-inner js-file-line">
</td>
</tr>
<tr>
<td id="file-savingpersonevent-cs-L21" class="blob-num js-line-number js-blob-rnum" data-line-number="21"></td>
<td id="file-savingpersonevent-cs-LC21" class="blob-code blob-code-inner js-file-line">db.Insert(person1);</td>
</tr>
<tr>
<td id="file-savingpersonevent-cs-L22" class="blob-num js-line-number js-blob-rnum" data-line-number="22"></td>
<td id="file-savingpersonevent-cs-LC22" class="blob-code blob-code-inner js-file-line">db.Insert(event1);</td>
</tr>
<tr>
<td id="file-savingpersonevent-cs-L23" class="blob-num js-line-number js-blob-rnum" data-line-number="23"></td>
<td id="file-savingpersonevent-cs-LC23" class="blob-code blob-code-inner js-file-line">
</td>
</tr>
<tr>
<td id="file-savingpersonevent-cs-L24" class="blob-num js-line-number js-blob-rnum" data-line-number="24"></td>
<td id="file-savingpersonevent-cs-LC24" class="blob-code blob-code-inner js-file-line">person1.Events = new List&lt;Event&gt; { event1 };</td>
</tr>
<tr>
<td id="file-savingpersonevent-cs-L25" class="blob-num js-line-number js-blob-rnum" data-line-number="25"></td>
<td id="file-savingpersonevent-cs-LC25" class="blob-code blob-code-inner js-file-line">db.UpdateWithChildren(person1);</td>
</tr>
<tr>
<td id="file-savingpersonevent-cs-L26" class="blob-num js-line-number js-blob-rnum" data-line-number="26"></td>
<td id="file-savingpersonevent-cs-LC26" class="blob-code blob-code-inner js-file-line">
</td>
</tr>
<tr>
<td id="file-savingpersonevent-cs-L27" class="blob-num js-line-number js-blob-rnum" data-line-number="27"></td>
<td id="file-savingpersonevent-cs-LC27" class="blob-code blob-code-inner js-file-line">var personStored = db.GetWithChildren&lt;Person&gt;(person1.Id);</td>
</tr>
<tr>
<td id="file-savingpersonevent-cs-L28" class="blob-num js-line-number js-blob-rnum" data-line-number="28"></td>
<td id="file-savingpersonevent-cs-LC28" class="blob-code blob-code-inner js-file-line">var eventStored = db.GetWithChildren&lt;Event&gt;(event1.Id);</td>
</tr>
</table>
</div></div>
</p></div>
</div></div>
<div class="gist-meta">
        <a href="https://gist.github.com/dsibinski/4b8566aba0d8280aa5117de3f1ce70fc/raw/5fc7f3d27f4313031c31cb40810e76a0e895b053/SavingPersonEvent.cs" style="float:right" class="Link--inTextBlock">view raw</a><br />
        <a href="https://gist.github.com/dsibinski/4b8566aba0d8280aa5117de3f1ce70fc#file-savingpersonevent-cs" class="Link--inTextBlock"><br />
          SavingPersonEvent.cs<br />
        </a><br />
        hosted with &#10084; by <a class="Link--inTextBlock" href="https://github.com">GitHub</a>
      </div>
</p></div>
</div>
<p>Lines 1-4 contain the database initialization (<span style="color: #ff9900;">Constants.DbFilePath</span> just returns an Android path of SQLite database file) and creation of all 3 tables in the database.</p>
<p>Lines 6-18 are simply the creation of <span style="color: #ff9900;">Person</span> and <span style="color: #ff9900;">Event</span> objects, filled with most basic details.</p>
<p>In lines 21 and 22 we firstly save our <span style="color: #ff9900;">person1</span> and <span style="color: #ff9900;">event1</span> entities separately, because in order to establish the relationships we need the primary keys of those entities, that are assigned by the database while saving. This can be also simplified by using recursive operations &#8211; more details in the <a href="https://bitbucket.org/twincoders/sqlite-net-extensions/" target="_blank" rel="noopener noreferrer">official documentation of the ORM</a>.</p>
<p>After that, we assign just created person to the event (line 24) and then the most rocket-science part comes:</p>
<pre><pre class="brush: csharp; title: ; notranslate">db.UpdateWithChildren(person1);</pre>
<p>This method does the write magic &#8211; it updates the person with all its children &#8211; so in our case, the <span style="color: #ff9900;">Events</span> collection. It will make the relationship established.</p>
<p>In order to prove it, in lines 27 and 28 we can check if the relationship collections are populated with children in both entities by calling <span style="color: #ff9900;">GetWithChildren</span> extension methods:</p>
<p><figure id="attachment_2231" aria-describedby="caption-attachment-2231" style="width: 571px" class="wp-caption aligncenter"><a href="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/personContainsEvents-1.png?ssl=1"><img data-recalc-dims="1" loading="lazy" decoding="async" data-attachment-id="2231" data-permalink="https://www.codejourney.net/sqlite-net-extensions-many-to-many-relationships/personcontainsevents-2/" data-orig-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/personContainsEvents-1.png?fit=814%2C321&amp;ssl=1" data-orig-size="814,321" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="personContainsEvents" data-image-description="" data-image-caption="&lt;p&gt;Person containing Events&lt;/p&gt;
" data-large-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/personContainsEvents-1.png?fit=814%2C321&amp;ssl=1" class="wp-image-2231 " src="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/personContainsEvents-1.png?resize=571%2C225&#038;ssl=1" alt="" width="571" height="225" srcset="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/personContainsEvents-1.png?w=814&amp;ssl=1 814w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/personContainsEvents-1.png?resize=300%2C118&amp;ssl=1 300w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/personContainsEvents-1.png?resize=768%2C303&amp;ssl=1 768w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/personContainsEvents-1.png?resize=720%2C284&amp;ssl=1 720w" sizes="auto, (max-width: 571px) 100vw, 571px" /></a><figcaption id="caption-attachment-2231" class="wp-caption-text">Person containing Events</figcaption></figure> <figure id="attachment_2228" aria-describedby="caption-attachment-2228" style="width: 573px" class="wp-caption aligncenter"><a href="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/eventContainsParticipants-1.png?ssl=1"><img data-recalc-dims="1" loading="lazy" decoding="async" data-attachment-id="2228" data-permalink="https://www.codejourney.net/sqlite-net-extensions-many-to-many-relationships/eventcontainsparticipants-2/" data-orig-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/eventContainsParticipants-1.png?fit=932%2C390&amp;ssl=1" data-orig-size="932,390" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="eventContainsParticipants" data-image-description="" data-image-caption="" data-large-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/eventContainsParticipants-1.png?fit=932%2C390&amp;ssl=1" class="wp-image-2228 " src="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/eventContainsParticipants-1.png?resize=573%2C240&#038;ssl=1" alt="" width="573" height="240" srcset="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/eventContainsParticipants-1.png?w=932&amp;ssl=1 932w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/eventContainsParticipants-1.png?resize=300%2C126&amp;ssl=1 300w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/eventContainsParticipants-1.png?resize=768%2C321&amp;ssl=1 768w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/eventContainsParticipants-1.png?resize=720%2C301&amp;ssl=1 720w" sizes="auto, (max-width: 573px) 100vw, 573px" /></a><figcaption id="caption-attachment-2228" class="wp-caption-text">Event containing Participants</figcaption></figure></p>
<p>That&#8217;s how SQLite-Net Extensions ORM works. It doesn&#8217;t provide any lazy-loading of related entities &#8211; it just adds/retrieves to/from the database exactly what you tell it to. The limitation here is that if you access <span style="color: #ff9900;">Person.Events</span> collection you can see the events this person is in relation with, but if you access <span style="color: #ff9900;">Person.Events[0]</span> you will not see all people registered for this event.</p>
<h2>Summary</h2>
<p>SQLite-Net Extensions is an ORM, which is a wrapper for classic SQLite.NET library. It adds the extension methods/attributes to handle relationships in SQLite database. It doesn&#8217;t provide any lazy-loading mechanism, instead exposing methods for getting/saving entities along with their children (related entities). It&#8217;s lightweight and rather easy to implement, so for small solutions like mobile apps I totally prefer it to writing and maintaining SQL queries directly in C# in order to handle relationships.</p>
<p>In the next posts from the <a href="https://www.codejourney.net/tag/sqlite-net-extensions/" target="_blank" rel="noopener noreferrer">series about SQLite-Net Extensions ORM</a>, I will present to you the other types of relationships this ORM offers. Stay tuned <img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f642.png" alt="🙂" class="wp-smiley" style="height: 1em; max-height: 1em;" /></p>
<p>&nbsp;</p>
<p>The post <a href="https://www.codejourney.net/sqlite-net-extensions-many-to-many-relationships/">SQLite-Net Extensions &#8211; many-to-many relationships</a> appeared first on <a href="https://www.codejourney.net">CodeJourney.net</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.codejourney.net/sqlite-net-extensions-many-to-many-relationships/feed/</wfw:commentRss>
			<slash:comments>8</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">2218</post-id>	</item>
		<item>
		<title>MoneyBack &#8211; 3 weeks before the end of DSP</title>
		<link>https://www.codejourney.net/moneyback-3-weeks-before-the-end-of-dsp/</link>
					<comments>https://www.codejourney.net/moneyback-3-weeks-before-the-end-of-dsp/#respond</comments>
		
		<dc:creator><![CDATA[Dawid Sibiński]]></dc:creator>
		<pubDate>Tue, 09 May 2017 22:09:45 +0000</pubDate>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[dajsiepoznac2017]]></category>
		<category><![CDATA[moneyback]]></category>
		<category><![CDATA[xamarin]]></category>
		<guid isPermaLink="false">http://www.dsibinski.pl/?p=2192</guid>

					<description><![CDATA[<p>In today&#8217;s post I&#8217;d like to present what&#8217;s the current status of works on MoneyBack application, 3 weeks before the end of DSP competition. In general, the project hasn&#8217;t been going as well as I expected and is currently not as advanced as I&#8217;d expect it to be at this stage. There are many reasons behind that,&#8230;</p>
<p>The post <a href="https://www.codejourney.net/moneyback-3-weeks-before-the-end-of-dsp/">MoneyBack &#8211; 3 weeks before the end of DSP</a> appeared first on <a href="https://www.codejourney.net">CodeJourney.net</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>In today&#8217;s post I&#8217;d like to present what&#8217;s the current status of works on <em>MoneyBack</em> application, 3 weeks before the end of DSP competition.<br />
<span id="more-2192"></span></p>
<p>In general, the project hasn&#8217;t been going as well as I expected and is currently not as advanced as I&#8217;d expect it to be at this stage. There are many reasons behind that, including lack of time recently and many issues met during development, however, as I already wrote in my <a href="https://www.codejourney.net/2017/02/hello-dajsiepoznac2017/" target="_blank" rel="noopener noreferrer">DSP introducing post</a>, the most important is to survive with the project to the end of the competition and meet all requirements. <span style="text-decoration: underline;">The end of DSP doesn&#8217;t equal the end of <em>MoneyBack</em></span> <img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f642.png" alt="🙂" class="wp-smiley" style="height: 1em; max-height: 1em;" /></p>
<p>That&#8217;s why in this post I&#8217;d like to show you how the project looks currently and what&#8217;s still to be done. Moreover, as <a href="https://www.codejourney.net/2017/03/using-sqlite-database-in-xamarin-android/" target="_blank" rel="noopener noreferrer">I promised before</a>, <strong>I&#8217;m publishing <a href="https://trello.com/b/pD6NLfH4" target="_blank" rel="noopener noreferrer">my Trello board</a> with tasks still to be done within the project.</strong></p>
<h2>UI changes</h2>
<p>For the last days working on the project I&#8217;ve been trying to make the UI of <em>MoneyBack</em> some kind of &#8220;final&#8221; version, so I can easily extend it adding new functionalities and focus on development instead of spending time on interface design, which is not important for me at the moment. I met many issues with that, which I think came from using some deprecated UI elements I used (e.g. <a href="https://developer.xamarin.com/guides/android/user_interface/working_with_listviews_and_adapters/" target="_blank" rel="noopener noreferrer">ListView and Adapters</a>) that are not fully-supported in the newest versions of Android. Tutorials are also not really up-to-date for those components. Maybe that&#8217;s also because when I wanted to implement displaying a list of entities I looked in Google for something like &#8220;xamarin android list of elements&#8221; which lead me to this <a href="https://developer.xamarin.com/guides/android/user_interface/working_with_listviews_and_adapters/" target="_blank" rel="noopener noreferrer">ListView and Adapters</a> tutorial. Instead of firstly reading the whole User Interface tutorial, I wanted to implement displaying the list quickly, so I used those deprecated elements instead of implementing for instance newer and recommended <a href="https://developer.xamarin.com/guides/android/user_interface/recyclerview/" target="_blank" rel="noopener noreferrer">RecyclerView</a> from the beginning, which would be easier extensible now. That definitely teaches me that <strong>I should get to know a particular topic/area better and wider before deciding to use one of the possible solutions to solve a problem</strong>. Sometimes we want to implement something particular quickly, but later it produces more issues than benefits.</p>
<p>Finally I <a href="https://github.com/dsibinski/MoneyBack/commit/db3594f47d10ea543d9a9d2d4869097455590626" target="_blank" rel="noopener noreferrer">added tabs</a> (only one tab for People for now, but it will be easy to add new ones now) and <a href="https://github.com/dsibinski/MoneyBack/commit/386df7738060d8871cca65830ed5ef186ca9e62f" target="_blank" rel="noopener noreferrer">ActionBar menu</a> on the main Activity of the app:</p>
<figure id="attachment_2204" aria-describedby="caption-attachment-2204" style="width: 169px" class="wp-caption aligncenter"><a href="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/MoneyBack_MainWithTabs.png?ssl=1"><img data-recalc-dims="1" loading="lazy" decoding="async" data-attachment-id="2204" data-permalink="https://www.codejourney.net/moneyback-3-weeks-before-the-end-of-dsp/moneyback_mainwithtabs/" data-orig-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/MoneyBack_MainWithTabs.png?fit=1080%2C1920&amp;ssl=1" data-orig-size="1080,1920" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="MoneyBack_MainWithTabs" data-image-description="" data-image-caption="" data-large-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/MoneyBack_MainWithTabs.png?fit=576%2C1024&amp;ssl=1" class="wp-image-2204 size-medium" src="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/MoneyBack_MainWithTabs.png?resize=169%2C300&#038;ssl=1" alt="" width="169" height="300" srcset="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/MoneyBack_MainWithTabs.png?resize=169%2C300&amp;ssl=1 169w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/MoneyBack_MainWithTabs.png?resize=768%2C1365&amp;ssl=1 768w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/MoneyBack_MainWithTabs.png?resize=576%2C1024&amp;ssl=1 576w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/MoneyBack_MainWithTabs.png?resize=720%2C1280&amp;ssl=1 720w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/MoneyBack_MainWithTabs.png?w=1080&amp;ssl=1 1080w" sizes="auto, (max-width: 169px) 100vw, 169px" /></a><figcaption id="caption-attachment-2204" class="wp-caption-text">MoneyBack &#8211; tabs</figcaption></figure>
<p>On the screenshot above, in the right-upper corner there is &#8220;Add&#8221; button visible when clicking on ActionBar menu. It opens a new person&#8217;s adding screen, on which I made name and email fields mandatory:</p>
<figure id="attachment_2205" aria-describedby="caption-attachment-2205" style="width: 169px" class="wp-caption aligncenter"><a href="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/MoneyBack_PersonAdding.png?ssl=1"><img data-recalc-dims="1" loading="lazy" decoding="async" data-attachment-id="2205" data-permalink="https://www.codejourney.net/moneyback-3-weeks-before-the-end-of-dsp/moneyback_personadding/" data-orig-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/MoneyBack_PersonAdding.png?fit=1080%2C1920&amp;ssl=1" data-orig-size="1080,1920" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="MoneyBack_PersonAdding" data-image-description="" data-image-caption="&lt;p&gt;MoneyBack &amp;#8211; adding Person&lt;/p&gt;
" data-large-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/MoneyBack_PersonAdding.png?fit=576%2C1024&amp;ssl=1" class="size-medium wp-image-2205" src="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/MoneyBack_PersonAdding.png?resize=169%2C300&#038;ssl=1" alt="" width="169" height="300" srcset="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/MoneyBack_PersonAdding.png?resize=169%2C300&amp;ssl=1 169w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/MoneyBack_PersonAdding.png?resize=768%2C1365&amp;ssl=1 768w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/MoneyBack_PersonAdding.png?resize=576%2C1024&amp;ssl=1 576w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/MoneyBack_PersonAdding.png?resize=720%2C1280&amp;ssl=1 720w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/MoneyBack_PersonAdding.png?w=1080&amp;ssl=1 1080w" sizes="auto, (max-width: 169px) 100vw, 169px" /></a><figcaption id="caption-attachment-2205" class="wp-caption-text">MoneyBack &#8211; adding Person</figcaption></figure>
<p>People added are then displayed on the main screen of the app in &#8220;People&#8221; tab:</p>
<figure id="attachment_2206" aria-describedby="caption-attachment-2206" style="width: 169px" class="wp-caption aligncenter"><a href="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/MoneyBack_List.png?ssl=1"><img data-recalc-dims="1" loading="lazy" decoding="async" data-attachment-id="2206" data-permalink="https://www.codejourney.net/moneyback-3-weeks-before-the-end-of-dsp/moneyback_list/" data-orig-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/MoneyBack_List.png?fit=1080%2C1920&amp;ssl=1" data-orig-size="1080,1920" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="MoneyBack_List" data-image-description="" data-image-caption="&lt;p&gt;MoneyBack &amp;#8211; list of people&lt;/p&gt;
" data-large-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/MoneyBack_List.png?fit=576%2C1024&amp;ssl=1" class="size-medium wp-image-2206" src="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/MoneyBack_List.png?resize=169%2C300&#038;ssl=1" alt="" width="169" height="300" srcset="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/MoneyBack_List.png?resize=169%2C300&amp;ssl=1 169w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/MoneyBack_List.png?resize=768%2C1365&amp;ssl=1 768w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/MoneyBack_List.png?resize=576%2C1024&amp;ssl=1 576w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/MoneyBack_List.png?resize=720%2C1280&amp;ssl=1 720w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/05/MoneyBack_List.png?w=1080&amp;ssl=1 1080w" sizes="auto, (max-width: 169px) 100vw, 169px" /></a><figcaption id="caption-attachment-2206" class="wp-caption-text">MoneyBack &#8211; list of people</figcaption></figure>
<h2>Code &#8211; interesting parts</h2>
<h5>Using tabs layout in an Activity</h5>
<p>It turned out that using tabs-like layout in the Activity is pretty easy. In the AXML layout file for <span style="color: #ff9900;">MainActivity</span> I just added a <span style="color: #ff9900;">FrameLayout</span> container, within which the tabs and their contents are to be displayed:</p>
<style>.gist table { margin-bottom: 0; }</style>
<div style="tab-size: 8" id="gist47515921" class="gist">
<div class="gist-file" translate="no" data-color-mode="light" data-light-theme="light">
<div class="gist-data">
<div class="js-gist-file-update-container js-task-list-container">
<div id="file-main-axml" class="file my-2">
<div itemprop="text"
      class="Box-body p-0 blob-wrapper data type-xml  "
      style="overflow: auto" tabindex="0" role="region"
      aria-label="Main.axml content, created by dsibinski on 09:21PM on May 09, 2017."
    ></p>
<div class="js-check-hidden-unicode js-blob-code-container blob-code-content">
<p>  <template class="js-file-alert-template"></p>
<div data-view-component="true" class="flash flash-warn flash-full d-flex flex-items-center">
  <svg aria-hidden="true" data-component="Octicon" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-alert">
    <path d="M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"></path>
</svg><br />
    <span><br />
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.<br />
      <a class="Link--inTextBlock" href="https://github.co/hiddenchars" target="_blank">Learn more about bidirectional Unicode characters</a><br />
    </span></p>
<div data-view-component="true" class="flash-action">        <a href="{{ revealButtonHref }}" data-view-component="true" class="btn-sm btn">    Show hidden characters<br />
</a>
</div>
</div>
<p></template><br />
<template class="js-line-alert-template"><br />
  <span aria-label="This line has hidden Unicode characters" data-view-component="true" class="line-alert tooltipped tooltipped-e"><br />
    <svg aria-hidden="true" data-component="Octicon" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-alert">
    <path d="M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"></path>
</svg><br />
</span></template></p>
<table data-hpc class="highlight tab-size js-file-line-container" data-tab-size="4" data-paste-markdown-skip data-tagsearch-path="Main.axml">
<tr>
<td id="file-main-axml-L1" class="blob-num js-line-number js-blob-rnum" data-line-number="1"></td>
<td id="file-main-axml-LC1" class="blob-code blob-code-inner js-file-line">&lt;LinearLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;</td>
</tr>
<tr>
<td id="file-main-axml-L2" class="blob-num js-line-number js-blob-rnum" data-line-number="2"></td>
<td id="file-main-axml-LC2" class="blob-code blob-code-inner js-file-line">    android:orientation=&quot;vertical&quot;</td>
</tr>
<tr>
<td id="file-main-axml-L3" class="blob-num js-line-number js-blob-rnum" data-line-number="3"></td>
<td id="file-main-axml-LC3" class="blob-code blob-code-inner js-file-line">    android:layout_width=&quot;match_parent&quot;</td>
</tr>
<tr>
<td id="file-main-axml-L4" class="blob-num js-line-number js-blob-rnum" data-line-number="4"></td>
<td id="file-main-axml-LC4" class="blob-code blob-code-inner js-file-line">    android:layout_height=&quot;match_parent&quot;</td>
</tr>
<tr>
<td id="file-main-axml-L5" class="blob-num js-line-number js-blob-rnum" data-line-number="5"></td>
<td id="file-main-axml-LC5" class="blob-code blob-code-inner js-file-line">    android:minWidth=&quot;25px&quot;</td>
</tr>
<tr>
<td id="file-main-axml-L6" class="blob-num js-line-number js-blob-rnum" data-line-number="6"></td>
<td id="file-main-axml-LC6" class="blob-code blob-code-inner js-file-line">    android:minHeight=&quot;25px&quot;&gt;</td>
</tr>
<tr>
<td id="file-main-axml-L7" class="blob-num js-line-number js-blob-rnum" data-line-number="7"></td>
<td id="file-main-axml-LC7" class="blob-code blob-code-inner js-file-line">    &lt;FrameLayout</td>
</tr>
<tr>
<td id="file-main-axml-L8" class="blob-num js-line-number js-blob-rnum" data-line-number="8"></td>
<td id="file-main-axml-LC8" class="blob-code blob-code-inner js-file-line">        android:minWidth=&quot;25px&quot;</td>
</tr>
<tr>
<td id="file-main-axml-L9" class="blob-num js-line-number js-blob-rnum" data-line-number="9"></td>
<td id="file-main-axml-LC9" class="blob-code blob-code-inner js-file-line">        android:minHeight=&quot;25px&quot;</td>
</tr>
<tr>
<td id="file-main-axml-L10" class="blob-num js-line-number js-blob-rnum" data-line-number="10"></td>
<td id="file-main-axml-LC10" class="blob-code blob-code-inner js-file-line">        android:layout_width=&quot;match_parent&quot;</td>
</tr>
<tr>
<td id="file-main-axml-L11" class="blob-num js-line-number js-blob-rnum" data-line-number="11"></td>
<td id="file-main-axml-LC11" class="blob-code blob-code-inner js-file-line">        android:layout_height=&quot;match_parent&quot;</td>
</tr>
<tr>
<td id="file-main-axml-L12" class="blob-num js-line-number js-blob-rnum" data-line-number="12"></td>
<td id="file-main-axml-LC12" class="blob-code blob-code-inner js-file-line">        android:id=&quot;@+id/tabFragmentsContainer&quot; /&gt;</td>
</tr>
<tr>
<td id="file-main-axml-L13" class="blob-num js-line-number js-blob-rnum" data-line-number="13"></td>
<td id="file-main-axml-LC13" class="blob-code blob-code-inner js-file-line">&lt;/LinearLayout&gt;</td>
</tr>
</table>
</div></div>
</p></div>
</div></div>
<div class="gist-meta">
        <a href="https://gist.github.com/dsibinski/8871cef3404f1b82834a46b2512c9263/raw/c5d3c8472e50d3f0b4e49921613b6b9abea954e0/Main.axml" style="float:right" class="Link--inTextBlock">view raw</a><br />
        <a href="https://gist.github.com/dsibinski/8871cef3404f1b82834a46b2512c9263#file-main-axml" class="Link--inTextBlock"><br />
          Main.axml<br />
        </a><br />
        hosted with &#10084; by <a class="Link--inTextBlock" href="https://github.com">GitHub</a>
      </div>
</p></div>
</div>
<p>I called it <span style="color: #ff9900;">tabFragmentsContainer</span>, because within each tab we will display a <span style="color: #000000;"><em>Fragment</em>. <em>Fragment</em> </span>represents a part of UI and/or behavior, which is displayed within an Activity. You can think of Fragments as smaller pieces, that can be placed onto (inside) Activities.</p>
<p>Basically, I changed <span style="color: #ff9900;">PeopleListActivity</span> to <span style="color: #ff9900;">PeopleListFragment</span>, which in fact only required changing inheritance from being a child of <span style="color: #ff9900;">Activity</span> to inheriting from <span style="color: #ff9900;">ListFragment</span> (which is a special kind of <span style="color: #ff9900;">Fragment</span> used for displaying lists of elements). The complete code of <span style="color: #ff9900;">PeopleListFragment</span> can be found <a href="https://gist.github.com/dsibinski/a90e6c8d63e5226dd9c2d3bb1f94db61" target="_blank" rel="noopener noreferrer">in this public Gist</a>.</p>
<p>In the end, making <span style="color: #ff9900;">MainActivity</span> displaying tabs requires setting its ActionBar&#8217;s navigation mode to <span style="color: #ff9900;">ActionBarNavigationMode.Tabs</span>:</p>
<pre><pre class="brush: csharp; title: ; notranslate">this.ActionBar.NavigationMode = ActionBarNavigationMode.Tabs;</pre>
<p>and adding as many tabs as you wish, using for instance code similar to the following one:</p>
<style>.gist table { margin-bottom: 0; }</style>
<div style="tab-size: 8" id="gist47516212" class="gist">
<div class="gist-file" translate="no" data-color-mode="light" data-light-theme="light">
<div class="gist-data">
<div class="js-gist-file-update-container js-task-list-container">
<div id="file-mainactivity_addtab-cs" class="file my-2">
<div itemprop="text"
      class="Box-body p-0 blob-wrapper data type-c  "
      style="overflow: auto" tabindex="0" role="region"
      aria-label="MainActivity_AddTab.cs content, created by dsibinski on 09:31PM on May 09, 2017."
    ></p>
<div class="js-check-hidden-unicode js-blob-code-container blob-code-content">
<p>  <template class="js-file-alert-template"></p>
<div data-view-component="true" class="flash flash-warn flash-full d-flex flex-items-center">
  <svg aria-hidden="true" data-component="Octicon" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-alert">
    <path d="M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"></path>
</svg><br />
    <span><br />
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.<br />
      <a class="Link--inTextBlock" href="https://github.co/hiddenchars" target="_blank">Learn more about bidirectional Unicode characters</a><br />
    </span></p>
<div data-view-component="true" class="flash-action">        <a href="{{ revealButtonHref }}" data-view-component="true" class="btn-sm btn">    Show hidden characters<br />
</a>
</div>
</div>
<p></template><br />
<template class="js-line-alert-template"><br />
  <span aria-label="This line has hidden Unicode characters" data-view-component="true" class="line-alert tooltipped tooltipped-e"><br />
    <svg aria-hidden="true" data-component="Octicon" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-alert">
    <path d="M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"></path>
</svg><br />
</span></template></p>
<table data-hpc class="highlight tab-size js-file-line-container" data-tab-size="4" data-paste-markdown-skip data-tagsearch-path="MainActivity_AddTab.cs">
<tr>
<td id="file-mainactivity_addtab-cs-L1" class="blob-num js-line-number js-blob-rnum" data-line-number="1"></td>
<td id="file-mainactivity_addtab-cs-LC1" class="blob-code blob-code-inner js-file-line">void AddTab(string tabText, Fragment view)</td>
</tr>
<tr>
<td id="file-mainactivity_addtab-cs-L2" class="blob-num js-line-number js-blob-rnum" data-line-number="2"></td>
<td id="file-mainactivity_addtab-cs-LC2" class="blob-code blob-code-inner js-file-line">{</td>
</tr>
<tr>
<td id="file-mainactivity_addtab-cs-L3" class="blob-num js-line-number js-blob-rnum" data-line-number="3"></td>
<td id="file-mainactivity_addtab-cs-LC3" class="blob-code blob-code-inner js-file-line">    var tab = this.ActionBar.NewTab();</td>
</tr>
<tr>
<td id="file-mainactivity_addtab-cs-L4" class="blob-num js-line-number js-blob-rnum" data-line-number="4"></td>
<td id="file-mainactivity_addtab-cs-LC4" class="blob-code blob-code-inner js-file-line">    tab.SetText(tabText);</td>
</tr>
<tr>
<td id="file-mainactivity_addtab-cs-L5" class="blob-num js-line-number js-blob-rnum" data-line-number="5"></td>
<td id="file-mainactivity_addtab-cs-LC5" class="blob-code blob-code-inner js-file-line">
</td>
</tr>
<tr>
<td id="file-mainactivity_addtab-cs-L6" class="blob-num js-line-number js-blob-rnum" data-line-number="6"></td>
<td id="file-mainactivity_addtab-cs-LC6" class="blob-code blob-code-inner js-file-line">    tab.TabSelected += delegate (object sender, ActionBar.TabEventArgs e)</td>
</tr>
<tr>
<td id="file-mainactivity_addtab-cs-L7" class="blob-num js-line-number js-blob-rnum" data-line-number="7"></td>
<td id="file-mainactivity_addtab-cs-LC7" class="blob-code blob-code-inner js-file-line">    {</td>
</tr>
<tr>
<td id="file-mainactivity_addtab-cs-L8" class="blob-num js-line-number js-blob-rnum" data-line-number="8"></td>
<td id="file-mainactivity_addtab-cs-LC8" class="blob-code blob-code-inner js-file-line">        var fragment = this.FragmentManager.FindFragmentById(Resource.Id.tabFragmentsContainer);</td>
</tr>
<tr>
<td id="file-mainactivity_addtab-cs-L9" class="blob-num js-line-number js-blob-rnum" data-line-number="9"></td>
<td id="file-mainactivity_addtab-cs-LC9" class="blob-code blob-code-inner js-file-line">        if (fragment != null)</td>
</tr>
<tr>
<td id="file-mainactivity_addtab-cs-L10" class="blob-num js-line-number js-blob-rnum" data-line-number="10"></td>
<td id="file-mainactivity_addtab-cs-LC10" class="blob-code blob-code-inner js-file-line">            e.FragmentTransaction.Remove(fragment);</td>
</tr>
<tr>
<td id="file-mainactivity_addtab-cs-L11" class="blob-num js-line-number js-blob-rnum" data-line-number="11"></td>
<td id="file-mainactivity_addtab-cs-LC11" class="blob-code blob-code-inner js-file-line">        e.FragmentTransaction.Add(Resource.Id.tabFragmentsContainer, view);</td>
</tr>
<tr>
<td id="file-mainactivity_addtab-cs-L12" class="blob-num js-line-number js-blob-rnum" data-line-number="12"></td>
<td id="file-mainactivity_addtab-cs-LC12" class="blob-code blob-code-inner js-file-line">    };</td>
</tr>
<tr>
<td id="file-mainactivity_addtab-cs-L13" class="blob-num js-line-number js-blob-rnum" data-line-number="13"></td>
<td id="file-mainactivity_addtab-cs-LC13" class="blob-code blob-code-inner js-file-line">    tab.TabUnselected += delegate (object sender, ActionBar.TabEventArgs e) {</td>
</tr>
<tr>
<td id="file-mainactivity_addtab-cs-L14" class="blob-num js-line-number js-blob-rnum" data-line-number="14"></td>
<td id="file-mainactivity_addtab-cs-LC14" class="blob-code blob-code-inner js-file-line">        e.FragmentTransaction.Remove(view);</td>
</tr>
<tr>
<td id="file-mainactivity_addtab-cs-L15" class="blob-num js-line-number js-blob-rnum" data-line-number="15"></td>
<td id="file-mainactivity_addtab-cs-LC15" class="blob-code blob-code-inner js-file-line">    };</td>
</tr>
<tr>
<td id="file-mainactivity_addtab-cs-L16" class="blob-num js-line-number js-blob-rnum" data-line-number="16"></td>
<td id="file-mainactivity_addtab-cs-LC16" class="blob-code blob-code-inner js-file-line">
</td>
</tr>
<tr>
<td id="file-mainactivity_addtab-cs-L17" class="blob-num js-line-number js-blob-rnum" data-line-number="17"></td>
<td id="file-mainactivity_addtab-cs-LC17" class="blob-code blob-code-inner js-file-line">    this.ActionBar.AddTab(tab);</td>
</tr>
<tr>
<td id="file-mainactivity_addtab-cs-L18" class="blob-num js-line-number js-blob-rnum" data-line-number="18"></td>
<td id="file-mainactivity_addtab-cs-LC18" class="blob-code blob-code-inner js-file-line">}</td>
</tr>
</table>
</div></div>
</p></div>
</div></div>
<div class="gist-meta">
        <a href="https://gist.github.com/dsibinski/621414dcb86e331e87b0ffd12939df1b/raw/36117bd3f8c95db8bba1e8a493ef5835292afbd5/MainActivity_AddTab.cs" style="float:right" class="Link--inTextBlock">view raw</a><br />
        <a href="https://gist.github.com/dsibinski/621414dcb86e331e87b0ffd12939df1b#file-mainactivity_addtab-cs" class="Link--inTextBlock"><br />
          MainActivity_AddTab.cs<br />
        </a><br />
        hosted with &#10084; by <a class="Link--inTextBlock" href="https://github.com">GitHub</a>
      </div>
</p></div>
</div>
<p>The arguments are name of the tab and an instance of a <span style="color: #ff9900;">Fragment</span> we want to have displayed in this tab (<span style="color: #ff9900;">PeopleListFragment<span style="color: #000000;">&#8216;s</span></span> instance in our case).</p>
<p>Lines 6-12 present what happens when the tab is selected by the user &#8211; <span style="color: #ff9900;">Fragment</span>&#8216;s instance is added to previously defined <span style="color: #ff9900;">tabFragmentsContainer</span>.</p>
<p>Lines 13-15 define callback method on tab deselection &#8211; <span style="color: #ff9900;">Fragment</span> is removed from the container.</p>
<h5>Adding ActionBar with menu to the Activity</h5>
<p>Addition of ActionBar with menu button in right-upper corner of the Activity requires creating an XML view in Resources/menu folder first (with one button in our case):</p>
<style>.gist table { margin-bottom: 0; }</style>
<div style="tab-size: 8" id="gist47516362" class="gist">
<div class="gist-file" translate="no" data-color-mode="light" data-light-theme="light">
<div class="gist-data">
<div class="js-gist-file-update-container js-task-list-container">
<div id="file-actionbarmenu-xml" class="file my-2">
<div itemprop="text"
      class="Box-body p-0 blob-wrapper data type-xml  "
      style="overflow: auto" tabindex="0" role="region"
      aria-label="ActionBarMenu.xml content, created by dsibinski on 09:37PM on May 09, 2017."
    ></p>
<div class="js-check-hidden-unicode js-blob-code-container blob-code-content">
<p>  <template class="js-file-alert-template"></p>
<div data-view-component="true" class="flash flash-warn flash-full d-flex flex-items-center">
  <svg aria-hidden="true" data-component="Octicon" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-alert">
    <path d="M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"></path>
</svg><br />
    <span><br />
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.<br />
      <a class="Link--inTextBlock" href="https://github.co/hiddenchars" target="_blank">Learn more about bidirectional Unicode characters</a><br />
    </span></p>
<div data-view-component="true" class="flash-action">        <a href="{{ revealButtonHref }}" data-view-component="true" class="btn-sm btn">    Show hidden characters<br />
</a>
</div>
</div>
<p></template><br />
<template class="js-line-alert-template"><br />
  <span aria-label="This line has hidden Unicode characters" data-view-component="true" class="line-alert tooltipped tooltipped-e"><br />
    <svg aria-hidden="true" data-component="Octicon" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-alert">
    <path d="M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"></path>
</svg><br />
</span></template></p>
<table data-hpc class="highlight tab-size js-file-line-container" data-tab-size="4" data-paste-markdown-skip data-tagsearch-path="ActionBarMenu.xml">
<tr>
<td id="file-actionbarmenu-xml-L1" class="blob-num js-line-number js-blob-rnum" data-line-number="1"></td>
<td id="file-actionbarmenu-xml-LC1" class="blob-code blob-code-inner js-file-line">&lt;menu xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;&gt;</td>
</tr>
<tr>
<td id="file-actionbarmenu-xml-L2" class="blob-num js-line-number js-blob-rnum" data-line-number="2"></td>
<td id="file-actionbarmenu-xml-LC2" class="blob-code blob-code-inner js-file-line">  &lt;item android:id=&quot;@+id/menuAdd&quot;</td>
</tr>
<tr>
<td id="file-actionbarmenu-xml-L3" class="blob-num js-line-number js-blob-rnum" data-line-number="3"></td>
<td id="file-actionbarmenu-xml-LC3" class="blob-code blob-code-inner js-file-line">        android:title=&quot;@string/menuAddTitle&quot;/&gt;</td>
</tr>
<tr>
<td id="file-actionbarmenu-xml-L4" class="blob-num js-line-number js-blob-rnum" data-line-number="4"></td>
<td id="file-actionbarmenu-xml-LC4" class="blob-code blob-code-inner js-file-line">&lt;/menu&gt;</td>
</tr>
</table>
</div></div>
</p></div>
</div></div>
<div class="gist-meta">
        <a href="https://gist.github.com/dsibinski/5bf6c6753228cbe52b38e4aba429cacb/raw/3d4dafa8cc94ab3f754787097609cd81b4e30e4a/ActionBarMenu.xml" style="float:right" class="Link--inTextBlock">view raw</a><br />
        <a href="https://gist.github.com/dsibinski/5bf6c6753228cbe52b38e4aba429cacb#file-actionbarmenu-xml" class="Link--inTextBlock"><br />
          ActionBarMenu.xml<br />
        </a><br />
        hosted with &#10084; by <a class="Link--inTextBlock" href="https://github.com">GitHub</a>
      </div>
</p></div>
</div>
<p>and then in the Activity considered overriding <span style="color: #ff9900;">OnCreateOptionsMenu</span> method inflating ActionBar&#8217;s menu using created view:</p>
<style>.gist table { margin-bottom: 0; }</style>
<div style="tab-size: 8" id="gist47516393" class="gist">
<div class="gist-file" translate="no" data-color-mode="light" data-light-theme="light">
<div class="gist-data">
<div class="js-gist-file-update-container js-task-list-container">
<div id="file-mainactivity_oncreateoptionsmenu-cs" class="file my-2">
<div itemprop="text"
      class="Box-body p-0 blob-wrapper data type-c  "
      style="overflow: auto" tabindex="0" role="region"
      aria-label="MainActivity_OnCreateOptionsMenu.cs content, created by dsibinski on 09:39PM on May 09, 2017."
    ></p>
<div class="js-check-hidden-unicode js-blob-code-container blob-code-content">
<p>  <template class="js-file-alert-template"></p>
<div data-view-component="true" class="flash flash-warn flash-full d-flex flex-items-center">
  <svg aria-hidden="true" data-component="Octicon" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-alert">
    <path d="M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"></path>
</svg><br />
    <span><br />
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.<br />
      <a class="Link--inTextBlock" href="https://github.co/hiddenchars" target="_blank">Learn more about bidirectional Unicode characters</a><br />
    </span></p>
<div data-view-component="true" class="flash-action">        <a href="{{ revealButtonHref }}" data-view-component="true" class="btn-sm btn">    Show hidden characters<br />
</a>
</div>
</div>
<p></template><br />
<template class="js-line-alert-template"><br />
  <span aria-label="This line has hidden Unicode characters" data-view-component="true" class="line-alert tooltipped tooltipped-e"><br />
    <svg aria-hidden="true" data-component="Octicon" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-alert">
    <path d="M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"></path>
</svg><br />
</span></template></p>
<table data-hpc class="highlight tab-size js-file-line-container" data-tab-size="4" data-paste-markdown-skip data-tagsearch-path="MainActivity_OnCreateOptionsMenu.cs">
<tr>
<td id="file-mainactivity_oncreateoptionsmenu-cs-L1" class="blob-num js-line-number js-blob-rnum" data-line-number="1"></td>
<td id="file-mainactivity_oncreateoptionsmenu-cs-LC1" class="blob-code blob-code-inner js-file-line">public override bool OnCreateOptionsMenu(IMenu menu)</td>
</tr>
<tr>
<td id="file-mainactivity_oncreateoptionsmenu-cs-L2" class="blob-num js-line-number js-blob-rnum" data-line-number="2"></td>
<td id="file-mainactivity_oncreateoptionsmenu-cs-LC2" class="blob-code blob-code-inner js-file-line">{</td>
</tr>
<tr>
<td id="file-mainactivity_oncreateoptionsmenu-cs-L3" class="blob-num js-line-number js-blob-rnum" data-line-number="3"></td>
<td id="file-mainactivity_oncreateoptionsmenu-cs-LC3" class="blob-code blob-code-inner js-file-line">    MenuInflater.Inflate(Resource.Menu.ActionBarMenu, menu);</td>
</tr>
<tr>
<td id="file-mainactivity_oncreateoptionsmenu-cs-L4" class="blob-num js-line-number js-blob-rnum" data-line-number="4"></td>
<td id="file-mainactivity_oncreateoptionsmenu-cs-LC4" class="blob-code blob-code-inner js-file-line">    return base.OnPrepareOptionsMenu(menu);</td>
</tr>
<tr>
<td id="file-mainactivity_oncreateoptionsmenu-cs-L5" class="blob-num js-line-number js-blob-rnum" data-line-number="5"></td>
<td id="file-mainactivity_oncreateoptionsmenu-cs-LC5" class="blob-code blob-code-inner js-file-line">}</td>
</tr>
</table>
</div></div>
</p></div>
</div></div>
<div class="gist-meta">
        <a href="https://gist.github.com/dsibinski/4053bd9d9aaf8d28fbf6960b1a5855df/raw/7e6a1422dfa2eccbd8936ff28bbdf0ee4ea6ec99/MainActivity_OnCreateOptionsMenu.cs" style="float:right" class="Link--inTextBlock">view raw</a><br />
        <a href="https://gist.github.com/dsibinski/4053bd9d9aaf8d28fbf6960b1a5855df#file-mainactivity_oncreateoptionsmenu-cs" class="Link--inTextBlock"><br />
          MainActivity_OnCreateOptionsMenu.cs<br />
        </a><br />
        hosted with &#10084; by <a class="Link--inTextBlock" href="https://github.com">GitHub</a>
      </div>
</p></div>
</div>
<p>We also need to define what happens when a menu option is selected. For that purpose, override <span style="color: #ff9900;">OnOptionsItemSelected</span> method:</p>
<style>.gist table { margin-bottom: 0; }</style>
<div style="tab-size: 8" id="gist47516427" class="gist">
<div class="gist-file" translate="no" data-color-mode="light" data-light-theme="light">
<div class="gist-data">
<div class="js-gist-file-update-container js-task-list-container">
<div id="file-mainactivity_onoptionsitemselected-cs" class="file my-2">
<div itemprop="text"
      class="Box-body p-0 blob-wrapper data type-c  "
      style="overflow: auto" tabindex="0" role="region"
      aria-label="MainActivity_OnOptionsItemSelected.cs content, created by dsibinski on 09:40PM on May 09, 2017."
    ></p>
<div class="js-check-hidden-unicode js-blob-code-container blob-code-content">
<p>  <template class="js-file-alert-template"></p>
<div data-view-component="true" class="flash flash-warn flash-full d-flex flex-items-center">
  <svg aria-hidden="true" data-component="Octicon" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-alert">
    <path d="M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"></path>
</svg><br />
    <span><br />
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.<br />
      <a class="Link--inTextBlock" href="https://github.co/hiddenchars" target="_blank">Learn more about bidirectional Unicode characters</a><br />
    </span></p>
<div data-view-component="true" class="flash-action">        <a href="{{ revealButtonHref }}" data-view-component="true" class="btn-sm btn">    Show hidden characters<br />
</a>
</div>
</div>
<p></template><br />
<template class="js-line-alert-template"><br />
  <span aria-label="This line has hidden Unicode characters" data-view-component="true" class="line-alert tooltipped tooltipped-e"><br />
    <svg aria-hidden="true" data-component="Octicon" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-alert">
    <path d="M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"></path>
</svg><br />
</span></template></p>
<table data-hpc class="highlight tab-size js-file-line-container" data-tab-size="4" data-paste-markdown-skip data-tagsearch-path="MainActivity_OnOptionsItemSelected.cs">
<tr>
<td id="file-mainactivity_onoptionsitemselected-cs-L1" class="blob-num js-line-number js-blob-rnum" data-line-number="1"></td>
<td id="file-mainactivity_onoptionsitemselected-cs-LC1" class="blob-code blob-code-inner js-file-line">public override bool OnOptionsItemSelected(IMenuItem item)</td>
</tr>
<tr>
<td id="file-mainactivity_onoptionsitemselected-cs-L2" class="blob-num js-line-number js-blob-rnum" data-line-number="2"></td>
<td id="file-mainactivity_onoptionsitemselected-cs-LC2" class="blob-code blob-code-inner js-file-line">{</td>
</tr>
<tr>
<td id="file-mainactivity_onoptionsitemselected-cs-L3" class="blob-num js-line-number js-blob-rnum" data-line-number="3"></td>
<td id="file-mainactivity_onoptionsitemselected-cs-LC3" class="blob-code blob-code-inner js-file-line">    if (item.ItemId == Resource.Id.menuAdd)</td>
</tr>
<tr>
<td id="file-mainactivity_onoptionsitemselected-cs-L4" class="blob-num js-line-number js-blob-rnum" data-line-number="4"></td>
<td id="file-mainactivity_onoptionsitemselected-cs-LC4" class="blob-code blob-code-inner js-file-line">    {</td>
</tr>
<tr>
<td id="file-mainactivity_onoptionsitemselected-cs-L5" class="blob-num js-line-number js-blob-rnum" data-line-number="5"></td>
<td id="file-mainactivity_onoptionsitemselected-cs-LC5" class="blob-code blob-code-inner js-file-line">        OpenAddingNewPerson();</td>
</tr>
<tr>
<td id="file-mainactivity_onoptionsitemselected-cs-L6" class="blob-num js-line-number js-blob-rnum" data-line-number="6"></td>
<td id="file-mainactivity_onoptionsitemselected-cs-LC6" class="blob-code blob-code-inner js-file-line">        return true;</td>
</tr>
<tr>
<td id="file-mainactivity_onoptionsitemselected-cs-L7" class="blob-num js-line-number js-blob-rnum" data-line-number="7"></td>
<td id="file-mainactivity_onoptionsitemselected-cs-LC7" class="blob-code blob-code-inner js-file-line">    }</td>
</tr>
<tr>
<td id="file-mainactivity_onoptionsitemselected-cs-L8" class="blob-num js-line-number js-blob-rnum" data-line-number="8"></td>
<td id="file-mainactivity_onoptionsitemselected-cs-LC8" class="blob-code blob-code-inner js-file-line">
</td>
</tr>
<tr>
<td id="file-mainactivity_onoptionsitemselected-cs-L9" class="blob-num js-line-number js-blob-rnum" data-line-number="9"></td>
<td id="file-mainactivity_onoptionsitemselected-cs-LC9" class="blob-code blob-code-inner js-file-line">    return base.OnOptionsItemSelected(item);</td>
</tr>
<tr>
<td id="file-mainactivity_onoptionsitemselected-cs-L10" class="blob-num js-line-number js-blob-rnum" data-line-number="10"></td>
<td id="file-mainactivity_onoptionsitemselected-cs-LC10" class="blob-code blob-code-inner js-file-line">}</td>
</tr>
</table>
</div></div>
</p></div>
</div></div>
<div class="gist-meta">
        <a href="https://gist.github.com/dsibinski/80803c442ea4c4027bc5db86b7a528da/raw/9d380aa4d43cf8d20a6d47ca8323d2e147d7423a/MainActivity_OnOptionsItemSelected.cs" style="float:right" class="Link--inTextBlock">view raw</a><br />
        <a href="https://gist.github.com/dsibinski/80803c442ea4c4027bc5db86b7a528da#file-mainactivity_onoptionsitemselected-cs" class="Link--inTextBlock"><br />
          MainActivity_OnOptionsItemSelected.cs<br />
        </a><br />
        hosted with &#10084; by <a class="Link--inTextBlock" href="https://github.com">GitHub</a>
      </div>
</p></div>
</div>
<h2>Next coding tasks</h2>
<p>From now on you can watch <a href="https://trello.com/b/pD6NLfH4" target="_blank" rel="noopener noreferrer">my public Trello board</a>, where I have all tasks to be done in the nearest future in <em>MoneyBack</em> defined. I will try to define deadlines for those tasks as well.</p>
<p>At the moment of writing this post, <a href="https://github.com/dsibinski/MoneyBack/commit/d6f58805dc8f9e8c0b303cf8ecbfd3bbf4930aff" target="_blank" rel="noopener noreferrer">I&#8217;ve started adding a possibility to create Events</a>. I will need to keep many-to-many relationship between Person and Event entities and I will probably use <a href="https://bitbucket.org/twincoders/sqlite-net-extensions" target="_blank" rel="noopener noreferrer">SQLite-Net Extensions</a> library for that. You can expect a separate post about defining relationships using this library soon <img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f609.png" alt="😉" class="wp-smiley" style="height: 1em; max-height: 1em;" /></p>
<h2>Other tasks left to be done</h2>
<p>Apart from coding and developing the project, I still need to fulfill the <a href="https://www.codejourney.net/2017/02/hello-dajsiepoznac2017/" target="_blank" rel="noopener noreferrer">DSP competition&#8217;s requirements</a>. This is my 14th post within <a href="https://www.codejourney.net/category/dajsiepoznac2017/" target="_blank" rel="noopener noreferrer">DajSiePoznac2017</a>, so 6 posts still to be written. I have the ideas in my mind already and few next posts planned. There are only 3 weeks left to the end of the competition, so those days will need to be more intensive that it recently was, but that&#8217;s good, it means that you should be receiving more content here in the coming days and I will be spending more time on developing <em>MoneyBack</em>. Only positive changes, I hope <img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f642.png" alt="🙂" class="wp-smiley" style="height: 1em; max-height: 1em;" /></p>
<h2>Summary</h2>
<p>We saw the status of <em>MoneyBack</em> project today. There are still many things to be done in the app to at least fulfill the minimal requirements I assumed in the beginning of the competition. but as I mentioned, the end of DSP is not the end of <em>MoneyBack</em> <img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f642.png" alt="🙂" class="wp-smiley" style="height: 1em; max-height: 1em;" /> On the other hand, DSP is a very good motivator, so I&#8217;ll try to make coming days and weeks more intensive. The most important goal for now is to fulfill the competition&#8217;s requirements for having 20 posts written until the end of May, which shouldn&#8217;t be problematic at all <img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f642.png" alt="🙂" class="wp-smiley" style="height: 1em; max-height: 1em;" /></p>
<p>I&#8217;ve also published my Trello dashboard. You can find a link to it <a href="https://www.codejourney.net/dajsiepoznac-2017/" target="_blank" rel="noopener noreferrer">here</a>.</p>
<p>Using this opportunity, I&#8217;d like to wish all DSP&#8217;17 participants good luck in the last weeks of the competition. I&#8217;m constantly reading the others&#8217; blogs and I see a lot of very nice and decent quality stuff appearing in Polish programming community on your blogs and repositories &#8211; great job!</p>
<p>Keep your fingers crossed! <img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f642.png" alt="🙂" class="wp-smiley" style="height: 1em; max-height: 1em;" /></p>
<p>The post <a href="https://www.codejourney.net/moneyback-3-weeks-before-the-end-of-dsp/">MoneyBack &#8211; 3 weeks before the end of DSP</a> appeared first on <a href="https://www.codejourney.net">CodeJourney.net</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.codejourney.net/moneyback-3-weeks-before-the-end-of-dsp/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">2192</post-id>	</item>
		<item>
		<title>WiFi and Bluetooth interference &#8211; diagnosing and fixing</title>
		<link>https://www.codejourney.net/wifi-and-bluetooth-interference-diagnosing-and-fixing/</link>
					<comments>https://www.codejourney.net/wifi-and-bluetooth-interference-diagnosing-and-fixing/#comments</comments>
		
		<dc:creator><![CDATA[Dawid Sibiński]]></dc:creator>
		<pubDate>Tue, 25 Apr 2017 21:40:14 +0000</pubDate>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[dajsiepoznac2017]]></category>
		<guid isPermaLink="false">http://www.dsibinski.pl/?p=2015</guid>

					<description><![CDATA[<p>Have you ever had issues with weaker WiFi connection&#8217;s signal while listening to music via Bluetooth speaker ? Or maybe you noticed that your WiFi speed gets worse when you turn on your Bluetooth mouse or keyboard ? I&#8217;ve met those issues recently and would like to share a diagnosis process and a potential solution with you&#8230;</p>
<p>The post <a href="https://www.codejourney.net/wifi-and-bluetooth-interference-diagnosing-and-fixing/">WiFi and Bluetooth interference &#8211; diagnosing and fixing</a> appeared first on <a href="https://www.codejourney.net">CodeJourney.net</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Have you ever had issues with weaker WiFi connection&#8217;s signal while listening to music via Bluetooth speaker ? Or maybe you noticed that your WiFi speed gets worse when you turn on your Bluetooth mouse or keyboard ? I&#8217;ve met those issues recently and would like to share a diagnosis process and a potential solution with you today.<br />
<span id="more-2015"></span></p>
<h2>How can Bluetooth interfere with WiFi ?</h2>
<p>Both WiFi and Bluetooth may work on the same, 2.4 GHz frequency. Bluetooth is designed to work on 2.4 GHz and also most popular WiFi routers (e.g. <a href="http://www.tp-link.in/products/details/cat-9_TL-WR845N.html" target="_blank" rel="noopener noreferrer">TL-WR845N</a> which I have) are configured to broadcast their signal on the same frequency by default.</p>
<p>What makes Bluetooth and WiFi different then ? Wireless networks, like BT and WiFi, apart from the frequency, operate on different <a href="https://en.wikipedia.org/wiki/List_of_WLAN_channels" target="_blank" rel="noopener noreferrer">channels</a>. A <strong>channel </strong>can be imagined as a <strong>swimming lane</strong> &#8211; <em>the wider the lane is, the more people can swim</em> on it. On the other hand, <em>the more people use the lane, the slower they swim</em>. The same happens with WiFi channels &#8211; if there are many WiFi networks in our neighborhood working on the same WiFi channel, our network may work slower.</p>
<p>In most WiFi routers&#8217; settings channel on which the router works can be changed manually. We can also change channel&#8217;s width  &#8211; it can be either 20MHz or 40MHz. <strong>Channel&#8217;s width </strong>can be imagined as a <strong>width of swimming area used by a swimmer</strong>. To illustrate: if our router is set to work on channel 1 and the channel&#8217;s width is set to 40MHz, it behaves like a <em>swimmer who uses two swimming lanes in the same time</em> &#8211; he can either swim on lane (channel) 1 or lane 5 (when lane 1 is too crowded). Consequently, when router&#8217;s channel&#8217;s width is set to 20MHz, it behaves like <em>a swimmer using only a single swimming lane at a time </em>(lane [channel] 1, in this case)<em>.</em></p>
<p>If there are too many people at the pool, swimming becomes uncomfortable and slow. So let&#8217;s see how we can improve it <img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f642.png" alt="🙂" class="wp-smiley" style="height: 1em; max-height: 1em;" /></p>
<figure id="attachment_2064" aria-describedby="caption-attachment-2064" style="width: 285px" class="wp-caption aligncenter"><img data-recalc-dims="1" loading="lazy" decoding="async" data-attachment-id="2064" data-permalink="https://www.codejourney.net/wifi-and-bluetooth-interference-diagnosing-and-fixing/lanes_meme/" data-orig-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/lanes_meme.jpg?fit=500%2C601&amp;ssl=1" data-orig-size="500,601" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="lanes_meme" data-image-description="" data-image-caption="" data-large-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/lanes_meme.jpg?fit=500%2C601&amp;ssl=1" class=" wp-image-2064 aligncenter" src="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/lanes_meme.jpg?resize=285%2C343&#038;ssl=1" alt="lanes_meme.jpg" width="285" height="343" srcset="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/lanes_meme.jpg?w=500&amp;ssl=1 500w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/lanes_meme.jpg?resize=250%2C300&amp;ssl=1 250w" sizes="auto, (max-width: 285px) 100vw, 285px" /><figcaption id="caption-attachment-2064" class="wp-caption-text">Source: <a href="https://pinterest.com" target="_blank" rel="noopener noreferrer">https://pinterest.com</a></figcaption></figure>
<h2>Bluetooth and WiFi interference problem</h2>
<p>I recently noticed that when I&#8217;m using my <a href="https://www.codejourney.net/2017/01/asus-zenbook-ux310ua-net-programmers-review/" target="_blank" rel="noopener noreferrer">Zenbook</a> <strong>working on WiFi having Bluetooth speaker connected in the same time</strong> and listening to music, my WiFi speed decreases significantly. To show you the scale of the problem, here is the basic Internet <em>tracert</em> I performed when BT was turned off:</p>
<p><img data-recalc-dims="1" loading="lazy" decoding="async" data-attachment-id="2086" data-permalink="https://www.codejourney.net/wifi-and-bluetooth-interference-diagnosing-and-fixing/bt_disabled_tracert/" data-orig-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/BT_Disabled_Tracert.png?fit=796%2C466&amp;ssl=1" data-orig-size="796,466" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="BT_Disabled_Tracert" data-image-description="" data-image-caption="" data-large-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/BT_Disabled_Tracert.png?fit=796%2C466&amp;ssl=1" class="alignnone wp-image-2086" src="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/BT_Disabled_Tracert.png?resize=504%2C295&#038;ssl=1" alt="BT_Disabled_Tracert" width="504" height="295" srcset="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/BT_Disabled_Tracert.png?w=796&amp;ssl=1 796w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/BT_Disabled_Tracert.png?resize=300%2C176&amp;ssl=1 300w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/BT_Disabled_Tracert.png?resize=768%2C450&amp;ssl=1 768w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/BT_Disabled_Tracert.png?resize=720%2C422&amp;ssl=1 720w" sizes="auto, (max-width: 504px) 100vw, 504px" /></p>
<p>and here is the same <em>tracert</em>, but when listening to music via BT speaker:</p>
<p><img data-recalc-dims="1" loading="lazy" decoding="async" data-attachment-id="2090" data-permalink="https://www.codejourney.net/wifi-and-bluetooth-interference-diagnosing-and-fixing/bt_enabled_tracert/" data-orig-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/BT_Enabled_Tracert.png?fit=513%2C224&amp;ssl=1" data-orig-size="513,224" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="BT_Enabled_Tracert" data-image-description="" data-image-caption="" data-large-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/BT_Enabled_Tracert.png?fit=513%2C224&amp;ssl=1" class="alignnone size-full wp-image-2090" src="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/BT_Enabled_Tracert.png?resize=513%2C224&#038;ssl=1" alt="BT_Enabled_Tracert.png" width="513" height="224" srcset="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/BT_Enabled_Tracert.png?w=513&amp;ssl=1 513w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/BT_Enabled_Tracert.png?resize=300%2C131&amp;ssl=1 300w" sizes="auto, (max-width: 513px) 100vw, 513px" /></p>
<p><strong>35 ms</strong> <strong>without BT</strong> to <strong>2532 ms with BT</strong>. Nice! That&#8217;s <strong>72 times worse</strong>! Plus the request didn&#8217;t even complete with BT turned on. Something is wrong here.</p>
<p>The same happened on my Huawei P8, when I had my MiBand 2 connected via Bluetooth.</p>
<h2>Reconfiguring WiFi router to not interfere with Bluetooth</h2>
<p>As we already know that WiFi and BT may work on the same frequencies and interrupt each other, we should be able fix this issue by changing some basic router&#8217;s settings.</p>
<h4>Changing router&#8217;s WiFi channel</h4>
<p>By default, WiFi routers automatically choose channels on which they work. It might be problematic in case there are more networks in our area using the same channels. I&#8217;m using TP-LINK WiFi router and the producer <a href="http://www.tp-link.com/sa/faq-468.html" target="_blank" rel="noopener noreferrer">on their website</a> advises to switch router to work on channel 1, 6 or 11 in case of interference issues. Those channels are <strong>generally</strong> not the most occupied ones, however it&#8217;s <strong>not always</strong> the case. Imagine that all your neighbors are WiFi-issues-solving-geeks-using-Bluetooth-devices and they all set their routers to work on channel 11. According to what we&#8217;ve said in the previous paragraph, changing our router&#8217;s to work on the same channel won&#8217;t help much.</p>
<p>I prefer using apps that help detecting what is the less used WiFi channel at our place. I personally recommend using free <a href="http://www.techspot.com/downloads/5936-inssider.html" target="_blank" rel="noopener noreferrer">inSSIDer Home</a> application.  When you install it, you see the list of available WiFi networks. The one you&#8217;re connected to will be marked as your favorite (with a blue star), given Link Score (quality of your WiFi signal) and analyzed in terms of router&#8217;s configuration improvements. When I launched it, my WiFi network got Link Score 70:</p>
<p><img data-recalc-dims="1" loading="lazy" decoding="async" data-attachment-id="2105" data-permalink="https://www.codejourney.net/wifi-and-bluetooth-interference-diagnosing-and-fixing/inssider_before1/" data-orig-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/inSSIDer_before1.jpg?fit=427%2C48&amp;ssl=1" data-orig-size="427,48" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;Dawid Sibi\u0144ski&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;1493154942&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="inSSIDer_before1" data-image-description="" data-image-caption="" data-large-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/inSSIDer_before1.jpg?fit=427%2C48&amp;ssl=1" class="alignnone size-full wp-image-2105" src="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/inSSIDer_before1.jpg?resize=427%2C48&#038;ssl=1" alt="inSSIDer_before1" width="427" height="48" srcset="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/inSSIDer_before1.jpg?w=427&amp;ssl=1 427w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/inSSIDer_before1.jpg?resize=300%2C34&amp;ssl=1 300w" sizes="auto, (max-width: 427px) 100vw, 427px" /></p>
<p>After a while, I also got the recommendation:</p>
<p><img data-recalc-dims="1" loading="lazy" decoding="async" data-attachment-id="2106" data-permalink="https://www.codejourney.net/wifi-and-bluetooth-interference-diagnosing-and-fixing/inssider_before2/" data-orig-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/inSSIDer_before2.jpg?fit=356%2C30&amp;ssl=1" data-orig-size="356,30" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;Dawid Sibi\u0144ski&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;1493154973&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="inSSIDer_before2" data-image-description="" data-image-caption="" data-large-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/inSSIDer_before2.jpg?fit=356%2C30&amp;ssl=1" class="alignnone size-full wp-image-2106" src="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/inSSIDer_before2.jpg?resize=356%2C30&#038;ssl=1" alt="inSSIDer_before2" width="356" height="30" srcset="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/inSSIDer_before2.jpg?w=356&amp;ssl=1 356w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/inSSIDer_before2.jpg?resize=300%2C25&amp;ssl=1 300w" sizes="auto, (max-width: 356px) 100vw, 356px" /></p>
<p>With such recommendation, you can go for your router&#8217;s settings page (for TP-LINK routers accessible by <a href="http://tplinkwifi.net/" target="_blank" rel="noopener noreferrer">http://tplinkwifi.net/</a>) and perform the change:</p>
<p><img data-recalc-dims="1" loading="lazy" decoding="async" data-attachment-id="2112" data-permalink="https://www.codejourney.net/wifi-and-bluetooth-interference-diagnosing-and-fixing/tplink_settings_change/" data-orig-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/TPLINK_Settings_Change.png?fit=912%2C461&amp;ssl=1" data-orig-size="912,461" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="TPLINK_Settings_Change" data-image-description="" data-image-caption="" data-large-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/TPLINK_Settings_Change.png?fit=912%2C461&amp;ssl=1" class="alignnone wp-image-2112" src="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/TPLINK_Settings_Change.png?resize=609%2C308&#038;ssl=1" alt="TPLINK_Settings_Change" width="609" height="308" srcset="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/TPLINK_Settings_Change.png?w=912&amp;ssl=1 912w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/TPLINK_Settings_Change.png?resize=300%2C152&amp;ssl=1 300w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/TPLINK_Settings_Change.png?resize=768%2C388&amp;ssl=1 768w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/TPLINK_Settings_Change.png?resize=720%2C364&amp;ssl=1 720w" sizes="auto, (max-width: 609px) 100vw, 609px" /></p>
<p>After that, my Link Score improved to 80. I performed a <em>tracert</em> test again with BT speaker working:</p>
<p><a href="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/BT_Enabled_After_Trace.png?ssl=1"><img data-recalc-dims="1" loading="lazy" decoding="async" data-attachment-id="2121" data-permalink="https://www.codejourney.net/wifi-and-bluetooth-interference-diagnosing-and-fixing/bt_enabled_after_trace/" data-orig-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/BT_Enabled_After_Trace.png?fit=579%2C281&amp;ssl=1" data-orig-size="579,281" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="BT_Enabled_After_Trace" data-image-description="" data-image-caption="" data-large-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/BT_Enabled_After_Trace.png?fit=579%2C281&amp;ssl=1" class="size-full wp-image-2121 alignnone" src="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/BT_Enabled_After_Trace.png?resize=579%2C281&#038;ssl=1" alt="" width="579" height="281" srcset="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/BT_Enabled_After_Trace.png?w=579&amp;ssl=1 579w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/BT_Enabled_After_Trace.png?resize=300%2C146&amp;ssl=1 300w" sizes="auto, (max-width: 579px) 100vw, 579px" /></a></p>
<p>288 ms for step 8 &#8211; much better than initial 2532 ms, but still far away from 35 ms with Bluetooth turned off. Let&#8217;s see what&#8217;s more we can do apart from changing the channel.</p>
<h4>Changing router&#8217;s WiFi Channel Width</h4>
<p>After changing my router&#8217;s channel to 1, I noticed in inSSIDer app that it&#8217;s actually working on channels 1+5:</p>
<p><img data-recalc-dims="1" loading="lazy" decoding="async" data-attachment-id="2130" data-permalink="https://www.codejourney.net/wifi-and-bluetooth-interference-diagnosing-and-fixing/inssider_after/" data-orig-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/inSSIDer_After.png?fit=421%2C49&amp;ssl=1" data-orig-size="421,49" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="inSSIDer_After" data-image-description="" data-image-caption="" data-large-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/inSSIDer_After.png?fit=421%2C49&amp;ssl=1" class="alignnone size-full wp-image-2130" src="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/inSSIDer_After.png?resize=421%2C49&#038;ssl=1" alt="inSSIDer_After" width="421" height="49" srcset="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/inSSIDer_After.png?w=421&amp;ssl=1 421w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/inSSIDer_After.png?resize=300%2C35&amp;ssl=1 300w" sizes="auto, (max-width: 421px) 100vw, 421px" /></p>
<p>Why was that ? As I already explained, there is a setting called WiFi Channel Width. This setting may by default be set to 40MHz &#8211; which was the case in my router&#8217;s settings &#8211; making router working on 2 channels in the same time (1 and 5 in my case). This setting can fortunately also be changed manually in router&#8217;s settings:</p>
<p><img data-recalc-dims="1" loading="lazy" decoding="async" data-attachment-id="2136" data-permalink="https://www.codejourney.net/wifi-and-bluetooth-interference-diagnosing-and-fixing/tplink_settings_change_2_20mhz/" data-orig-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/TPLINK_Settings_Change_2_20MHz.png?fit=467%2C251&amp;ssl=1" data-orig-size="467,251" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="TPLINK_Settings_Change_2_20MHz" data-image-description="" data-image-caption="" data-large-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/TPLINK_Settings_Change_2_20MHz.png?fit=467%2C251&amp;ssl=1" class="alignnone size-full wp-image-2136" src="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/TPLINK_Settings_Change_2_20MHz.png?resize=467%2C251&#038;ssl=1" alt="TPLINK_Settings_Change_2_20MHz" width="467" height="251" srcset="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/TPLINK_Settings_Change_2_20MHz.png?w=467&amp;ssl=1 467w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/TPLINK_Settings_Change_2_20MHz.png?resize=300%2C161&amp;ssl=1 300w" sizes="auto, (max-width: 467px) 100vw, 467px" /></p>
<p>After that change, my router started working on channel 1 only (as recommended) and Link Score became 94:</p>
<p><img data-recalc-dims="1" loading="lazy" decoding="async" data-attachment-id="2139" data-permalink="https://www.codejourney.net/wifi-and-bluetooth-interference-diagnosing-and-fixing/inssider_after_channel6_20mhz/" data-orig-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/inSSIDer_After_Channel6_20MHz.png?fit=420%2C48&amp;ssl=1" data-orig-size="420,48" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="inSSIDer_After_Channel6_20MHz" data-image-description="" data-image-caption="" data-large-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/inSSIDer_After_Channel6_20MHz.png?fit=420%2C48&amp;ssl=1" class="alignnone size-full wp-image-2139" src="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/inSSIDer_After_Channel6_20MHz.png?resize=420%2C48&#038;ssl=1" alt="inSSIDer_After_Channel6_20MHz.png" width="420" height="48" srcset="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/inSSIDer_After_Channel6_20MHz.png?w=420&amp;ssl=1 420w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/inSSIDer_After_Channel6_20MHz.png?resize=300%2C34&amp;ssl=1 300w" sizes="auto, (max-width: 420px) 100vw, 420px" /></p>
<p><em>Tracert</em> also looks much better now with BT speaker working:</p>
<p><a href="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/BT_Enabled_Channel_6_20MHz_Tracert.png?ssl=1"><img data-recalc-dims="1" loading="lazy" decoding="async" data-attachment-id="2141" data-permalink="https://www.codejourney.net/wifi-and-bluetooth-interference-diagnosing-and-fixing/bt_enabled_channel_6_20mhz_tracert/" data-orig-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/BT_Enabled_Channel_6_20MHz_Tracert.png?fit=582%2C279&amp;ssl=1" data-orig-size="582,279" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="BT_Enabled_Channel_6_20MHz_Tracert" data-image-description="" data-image-caption="" data-large-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/BT_Enabled_Channel_6_20MHz_Tracert.png?fit=582%2C279&amp;ssl=1" class="wp-image-2141 alignnone" src="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/BT_Enabled_Channel_6_20MHz_Tracert.png?resize=542%2C260&#038;ssl=1" alt="" width="542" height="260" srcset="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/BT_Enabled_Channel_6_20MHz_Tracert.png?w=582&amp;ssl=1 582w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/BT_Enabled_Channel_6_20MHz_Tracert.png?resize=300%2C144&amp;ssl=1 300w" sizes="auto, (max-width: 542px) 100vw, 542px" /></a></p>
<p>187 ms compared to 35 ms with no BT. Apparently, Bluetooth still makes WiFi 5 times slower, but considering that the maximum speed of router&#8217;s WiFi transmission in 300MBs/s, even being 5 times reduced it remains around 60MBs/s which should be fair enough.</p>
<p>In the end of this optimization process, in inSSIDer application we can see our WiFi network placed between other networks in our area:</p>
<p><a href="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/inSSIDer_Final_NetworksList.png?ssl=1"><img data-recalc-dims="1" loading="lazy" decoding="async" data-attachment-id="2142" data-permalink="https://www.codejourney.net/wifi-and-bluetooth-interference-diagnosing-and-fixing/inssider_final_networkslist/" data-orig-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/inSSIDer_Final_NetworksList.png?fit=769%2C362&amp;ssl=1" data-orig-size="769,362" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="inSSIDer_Final_NetworksList" data-image-description="" data-image-caption="" data-large-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/inSSIDer_Final_NetworksList.png?fit=769%2C362&amp;ssl=1" class="wp-image-2142 alignnone" src="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/inSSIDer_Final_NetworksList.png?resize=650%2C306&#038;ssl=1" alt="" width="650" height="306" srcset="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/inSSIDer_Final_NetworksList.png?w=769&amp;ssl=1 769w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/inSSIDer_Final_NetworksList.png?resize=300%2C141&amp;ssl=1 300w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/inSSIDer_Final_NetworksList.png?resize=768%2C362&amp;ssl=1 768w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/inSSIDer_Final_NetworksList.png?resize=720%2C339&amp;ssl=1 720w" sizes="auto, (max-width: 650px) 100vw, 650px" /></a></p>
<h4>Changing WiFi&#8217;s frequency to 5GHz</h4>
<p>If your router supports 5GHz WiFi frequency, the obvious solution for all BT/WiFi interference issues would be changing it to work in 5GHz mode, because as we already said, Bluetooth is using 2.4GHz so they wouldn&#8217;t interrupt each other anymore at all in that case. This is however not always acceptable, because some older or simpler devices like WiFi printers may not support WiFi in 5GHz frequency. That&#8217;s the reason why I didn&#8217;t change it in my router&#8217;s settings. If you can afford that, try changing your router to work on 5GHz frequency &#8211; it may eliminate all your interference issues.</p>
<h2>Summary</h2>
<p>Today we&#8217;ve seen how to fix interference issues between WiFi network and Bluetooth devices, which may be really frustrating. Especially that Bluetooth is currently coming back in with BT speakers, smartbands and IoT devices in general.</p>
<p>I hope you&#8217;ll find those advises useful <img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f609.png" alt="😉" class="wp-smiley" style="height: 1em; max-height: 1em;" /></p>
<p>The post <a href="https://www.codejourney.net/wifi-and-bluetooth-interference-diagnosing-and-fixing/">WiFi and Bluetooth interference &#8211; diagnosing and fixing</a> appeared first on <a href="https://www.codejourney.net">CodeJourney.net</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.codejourney.net/wifi-and-bluetooth-interference-diagnosing-and-fixing/feed/</wfw:commentRss>
			<slash:comments>16</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">2015</post-id>	</item>
		<item>
		<title>Android Apps Localization</title>
		<link>https://www.codejourney.net/android-apps-localization/</link>
					<comments>https://www.codejourney.net/android-apps-localization/#comments</comments>
		
		<dc:creator><![CDATA[Dawid Sibiński]]></dc:creator>
		<pubDate>Wed, 19 Apr 2017 20:48:55 +0000</pubDate>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[android]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[dajsiepoznac2017]]></category>
		<category><![CDATA[xamarin]]></category>
		<guid isPermaLink="false">http://www.dsibinski.pl/?p=1803</guid>

					<description><![CDATA[<p>Hello everyone 🙂 As you might have noticed, I&#8217;ve recently decided to take a longer break in DSP competition. Few things to do, Easter in the meantime&#8230; but of course I didn&#8217;t give up and today I&#8217;m back 😉 In this post I&#8217;d like to show you how do we localize Android apps. Let&#8217;s see! What&#8230;</p>
<p>The post <a href="https://www.codejourney.net/android-apps-localization/">Android Apps Localization</a> appeared first on <a href="https://www.codejourney.net">CodeJourney.net</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Hello everyone 🙂</p>
<p>As you might have noticed, I&#8217;ve recently decided to take a longer break in DSP competition. Few things to do, Easter in the meantime&#8230; but of course I didn&#8217;t give up and today I&#8217;m back 😉</p>
<p>In this post I&#8217;d like to show you how do we localize Android apps. Let&#8217;s see!<br />
<span id="more-1803"></span></p>
<h2>What is localization ?</h2>
<p>Generally, <strong>localization </strong>is a <em>process of adapting the product or application to specific markets by adjusting its language and cultural resources accordingly</em>.</p>
<p>People often think that localization is only a process of translating documentation and user interface into multiple languages, but in fact it may concern many other not less important topics, e.g. formats of numeric values or dates, currencies, numbers comparison/sorting methods, symbols, national flags or even country-specific law requirements.</p>
<p>Android supports app&#8217;s resources localization in pretty easy way. We can quite conveniently provide different versions of strings, images and layouts used in our application for different languages/regions. Let&#8217;s take a look at the basics of Android app&#8217;s localization.</p>
<h2>Android localization basics</h2>
<p>In every Android application, localization is based on the language user has set on his/her device. The language can be changed in <strong>Settings -&gt; Language &amp; input</strong>. Changing the language in this place affects both user interface&#8217;s language and region-specific settings (e.g. dates formats).</p>
<p>To retrieve the current <a href="https://docs.oracle.com/javase/7/docs/api/java/util/Locale.html" target="_blank" rel="noopener">locale</a> (constant/object representing selected language) in code the following statement can be used:</p>
<pre><pre class="brush: csharp; title: ; notranslate">var currentLang = Resources.Configuration.Locale;</pre>
<p>In case user has Polish language set on his/her phone, <span style="color: #ff9900;">currentLang</span> variable would contain &#8220;pl_PL&#8221; locale symbol. For the full list of locales symbols, see <a href="http://www.oracle.com/technetwork/java/javase/locales-137662.html" target="_blank" rel="noopener">for example this list.</a></p>
<p>Basically, everything that is placed under <em>Resources</em> folder in Android solution can be localized. All of you probably have <em>values</em> folder in <em>Resources</em>, which contains <em>Strings.xml</em> file. We&#8217;ll see more details about this file in a while, but to present the ease of localization to you, it&#8217;s enough to create another folder under <em>Resources</em> called e.g. <em>values-pl</em>, which makes retrieving strings from <em>Strings.xml</em> file located in this folder on devices with language set to Polish. Simple as that. The same can be done with every type of resource. It means we can create totally different layouts of our Activities or use different images (e.g. countries&#8217; flags) depending on user&#8217;s device&#8217;s language.</p>
<h2>Strings localization</h2>
<h4>Strings.xml file</h4>
<p>To-be-localized strings (BTW, I think that we should do it straightaway with all strings we use in our app) should be put in <em>values</em>/<em>Strings.xml</em> file, which has the following structure:</p>
<p><style>.gist table { margin-bottom: 0; }</style>
<div style="tab-size: 8" id="gist46853585" class="gist">
<div class="gist-file" translate="no" data-color-mode="light" data-light-theme="light">
<div class="gist-data">
<div class="js-gist-file-update-container js-task-list-container">
<div id="file-strings-xml" class="file my-2">
<div itemprop="text"
      class="Box-body p-0 blob-wrapper data type-xml  "
      style="overflow: auto" tabindex="0" role="region"
      aria-label="Strings.xml content, created by dsibinski on 06:55PM on April 19, 2017."
    ></p>
<div class="js-check-hidden-unicode js-blob-code-container blob-code-content">
<p>  <template class="js-file-alert-template"></p>
<div data-view-component="true" class="flash flash-warn flash-full d-flex flex-items-center">
  <svg aria-hidden="true" data-component="Octicon" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-alert">
    <path d="M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"></path>
</svg><br />
    <span><br />
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.<br />
      <a class="Link--inTextBlock" href="https://github.co/hiddenchars" target="_blank">Learn more about bidirectional Unicode characters</a><br />
    </span></p>
<div data-view-component="true" class="flash-action">        <a href="{{ revealButtonHref }}" data-view-component="true" class="btn-sm btn">    Show hidden characters<br />
</a>
</div>
</div>
<p></template><br />
<template class="js-line-alert-template"><br />
  <span aria-label="This line has hidden Unicode characters" data-view-component="true" class="line-alert tooltipped tooltipped-e"><br />
    <svg aria-hidden="true" data-component="Octicon" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-alert">
    <path d="M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"></path>
</svg><br />
</span></template></p>
<table data-hpc class="highlight tab-size js-file-line-container" data-tab-size="4" data-paste-markdown-skip data-tagsearch-path="Strings.xml">
<tr>
<td id="file-strings-xml-L1" class="blob-num js-line-number js-blob-rnum" data-line-number="1"></td>
<td id="file-strings-xml-LC1" class="blob-code blob-code-inner js-file-line">&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;</td>
</tr>
<tr>
<td id="file-strings-xml-L2" class="blob-num js-line-number js-blob-rnum" data-line-number="2"></td>
<td id="file-strings-xml-LC2" class="blob-code blob-code-inner js-file-line">&lt;resources&gt;</td>
</tr>
<tr>
<td id="file-strings-xml-L3" class="blob-num js-line-number js-blob-rnum" data-line-number="3"></td>
<td id="file-strings-xml-LC3" class="blob-code blob-code-inner js-file-line">    &lt;string name=&quot;ApplicationName&quot;&gt;MoneyBack&lt;/string&gt;</td>
</tr>
<tr>
<td id="file-strings-xml-L4" class="blob-num js-line-number js-blob-rnum" data-line-number="4"></td>
<td id="file-strings-xml-LC4" class="blob-code blob-code-inner js-file-line">    &lt;string name=&quot;titleMenu&quot;&gt;Menu:&lt;/string&gt;</td>
</tr>
<tr>
<td id="file-strings-xml-L5" class="blob-num js-line-number js-blob-rnum" data-line-number="5"></td>
<td id="file-strings-xml-LC5" class="blob-code blob-code-inner js-file-line">    &lt;string name=&quot;btnPeople&quot;&gt;People management&lt;/string&gt;</td>
</tr>
<tr>
<td id="file-strings-xml-L6" class="blob-num js-line-number js-blob-rnum" data-line-number="6"></td>
<td id="file-strings-xml-LC6" class="blob-code blob-code-inner js-file-line">    &lt;string name=&quot;titleName&quot;&gt;Name&lt;/string&gt;</td>
</tr>
<tr>
<td id="file-strings-xml-L7" class="blob-num js-line-number js-blob-rnum" data-line-number="7"></td>
<td id="file-strings-xml-LC7" class="blob-code blob-code-inner js-file-line">    &lt;string name=&quot;titleLastName&quot;&gt;Last name&lt;/string&gt;</td>
</tr>
<tr>
<td id="file-strings-xml-L8" class="blob-num js-line-number js-blob-rnum" data-line-number="8"></td>
<td id="file-strings-xml-LC8" class="blob-code blob-code-inner js-file-line">    &lt;string name=&quot;titlePhoneNumber&quot;&gt;Phone number&lt;/string&gt;</td>
</tr>
<tr>
<td id="file-strings-xml-L9" class="blob-num js-line-number js-blob-rnum" data-line-number="9"></td>
<td id="file-strings-xml-LC9" class="blob-code blob-code-inner js-file-line">    &lt;string name=&quot;btnSavePerson&quot;&gt;Save person&lt;/string&gt;</td>
</tr>
<tr>
<td id="file-strings-xml-L10" class="blob-num js-line-number js-blob-rnum" data-line-number="10"></td>
<td id="file-strings-xml-LC10" class="blob-code blob-code-inner js-file-line">    &lt;string name=&quot;btnPeopleList&quot;&gt;List of people&lt;/string&gt;</td>
</tr>
<tr>
<td id="file-strings-xml-L11" class="blob-num js-line-number js-blob-rnum" data-line-number="11"></td>
<td id="file-strings-xml-LC11" class="blob-code blob-code-inner js-file-line">    &lt;string name=&quot;peopleListTitle&quot;&gt;List of people&lt;/string&gt;</td>
</tr>
<tr>
<td id="file-strings-xml-L12" class="blob-num js-line-number js-blob-rnum" data-line-number="12"></td>
<td id="file-strings-xml-LC12" class="blob-code blob-code-inner js-file-line">&lt;/resources&gt;</td>
</tr>
</table>
</div></div>
</p></div>
</div></div>
<div class="gist-meta">
        <a href="https://gist.github.com/dsibinski/a0ae912d93e038ddf4b958666413edca/raw/420e073b031ec34f5a0c6b2fe1f47a448054d065/Strings.xml" style="float:right" class="Link--inTextBlock">view raw</a><br />
        <a href="https://gist.github.com/dsibinski/a0ae912d93e038ddf4b958666413edca#file-strings-xml" class="Link--inTextBlock"><br />
          Strings.xml<br />
        </a><br />
        hosted with &#10084; by <a class="Link--inTextBlock" href="https://github.com">GitHub</a>
      </div>
</p></div>
</div>
<p>The file is built in accordance with standard XML rules. The <em>name</em> represents <strong>Android resource ID</strong> (cannot contain any spaces or dashes) to which we will refer from code and other places in order to retrieve the <strong>value</strong> of this resource, which is placed between &#8220;&gt;&#8221; and &#8220;&lt;&#8221; characters.</p>
<p>For instance, first resource from above-pasted <em>Strings.xml</em> has <em>name</em> = &#8220;ApplicationName&#8221; and <em>value</em> = &#8220;MoneyBack&#8221;.</p>
<p>As mentioned in the previous paragraph, I also created <em>Strings.xml</em> file in <em>values-pl</em> folder, containing the same resources&#8217; Polish translations. The contents of <em>values-pl/Strings.xml</em> file:</p>
<p><style>.gist table { margin-bottom: 0; }</style>
<div style="tab-size: 8" id="gist46854312" class="gist">
<div class="gist-file" translate="no" data-color-mode="light" data-light-theme="light">
<div class="gist-data">
<div class="js-gist-file-update-container js-task-list-container">
<div id="file-strings-xml" class="file my-2">
<div itemprop="text"
      class="Box-body p-0 blob-wrapper data type-xml  "
      style="overflow: auto" tabindex="0" role="region"
      aria-label="Strings.xml content, created by dsibinski on 07:18PM on April 19, 2017."
    ></p>
<div class="js-check-hidden-unicode js-blob-code-container blob-code-content">
<p>  <template class="js-file-alert-template"></p>
<div data-view-component="true" class="flash flash-warn flash-full d-flex flex-items-center">
  <svg aria-hidden="true" data-component="Octicon" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-alert">
    <path d="M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"></path>
</svg><br />
    <span><br />
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.<br />
      <a class="Link--inTextBlock" href="https://github.co/hiddenchars" target="_blank">Learn more about bidirectional Unicode characters</a><br />
    </span></p>
<div data-view-component="true" class="flash-action">        <a href="{{ revealButtonHref }}" data-view-component="true" class="btn-sm btn">    Show hidden characters<br />
</a>
</div>
</div>
<p></template><br />
<template class="js-line-alert-template"><br />
  <span aria-label="This line has hidden Unicode characters" data-view-component="true" class="line-alert tooltipped tooltipped-e"><br />
    <svg aria-hidden="true" data-component="Octicon" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-alert">
    <path d="M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"></path>
</svg><br />
</span></template></p>
<table data-hpc class="highlight tab-size js-file-line-container" data-tab-size="4" data-paste-markdown-skip data-tagsearch-path="Strings.xml">
<tr>
<td id="file-strings-xml-L1" class="blob-num js-line-number js-blob-rnum" data-line-number="1"></td>
<td id="file-strings-xml-LC1" class="blob-code blob-code-inner js-file-line">&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;</td>
</tr>
<tr>
<td id="file-strings-xml-L2" class="blob-num js-line-number js-blob-rnum" data-line-number="2"></td>
<td id="file-strings-xml-LC2" class="blob-code blob-code-inner js-file-line">&lt;resources&gt;</td>
</tr>
<tr>
<td id="file-strings-xml-L3" class="blob-num js-line-number js-blob-rnum" data-line-number="3"></td>
<td id="file-strings-xml-LC3" class="blob-code blob-code-inner js-file-line">    &lt;string name=&quot;ApplicationName&quot;&gt;MoneyBack&lt;/string&gt;</td>
</tr>
<tr>
<td id="file-strings-xml-L4" class="blob-num js-line-number js-blob-rnum" data-line-number="4"></td>
<td id="file-strings-xml-LC4" class="blob-code blob-code-inner js-file-line">    &lt;string name=&quot;titleMenu&quot;&gt;Menu:&lt;/string&gt;</td>
</tr>
<tr>
<td id="file-strings-xml-L5" class="blob-num js-line-number js-blob-rnum" data-line-number="5"></td>
<td id="file-strings-xml-LC5" class="blob-code blob-code-inner js-file-line">    &lt;string name=&quot;btnPeople&quot;&gt;Zarządzaj osobami&lt;/string&gt;</td>
</tr>
<tr>
<td id="file-strings-xml-L6" class="blob-num js-line-number js-blob-rnum" data-line-number="6"></td>
<td id="file-strings-xml-LC6" class="blob-code blob-code-inner js-file-line">    &lt;string name=&quot;titleName&quot;&gt;Imię&lt;/string&gt;</td>
</tr>
<tr>
<td id="file-strings-xml-L7" class="blob-num js-line-number js-blob-rnum" data-line-number="7"></td>
<td id="file-strings-xml-LC7" class="blob-code blob-code-inner js-file-line">    &lt;string name=&quot;titleLastName&quot;&gt;Nazwisko&lt;/string&gt;</td>
</tr>
<tr>
<td id="file-strings-xml-L8" class="blob-num js-line-number js-blob-rnum" data-line-number="8"></td>
<td id="file-strings-xml-LC8" class="blob-code blob-code-inner js-file-line">    &lt;string name=&quot;titlePhoneNumber&quot;&gt;Numer telefonu&lt;/string&gt;</td>
</tr>
<tr>
<td id="file-strings-xml-L9" class="blob-num js-line-number js-blob-rnum" data-line-number="9"></td>
<td id="file-strings-xml-LC9" class="blob-code blob-code-inner js-file-line">    &lt;string name=&quot;btnSavePerson&quot;&gt;Zapisz osobę&lt;/string&gt;</td>
</tr>
<tr>
<td id="file-strings-xml-L10" class="blob-num js-line-number js-blob-rnum" data-line-number="10"></td>
<td id="file-strings-xml-LC10" class="blob-code blob-code-inner js-file-line">    &lt;string name=&quot;btnPeopleList&quot;&gt;Lista osób&lt;/string&gt;</td>
</tr>
<tr>
<td id="file-strings-xml-L11" class="blob-num js-line-number js-blob-rnum" data-line-number="11"></td>
<td id="file-strings-xml-LC11" class="blob-code blob-code-inner js-file-line">    &lt;string name=&quot;peopleListTitle&quot;&gt;Lista osób&lt;/string&gt;</td>
</tr>
<tr>
<td id="file-strings-xml-L12" class="blob-num js-line-number js-blob-rnum" data-line-number="12"></td>
<td id="file-strings-xml-LC12" class="blob-code blob-code-inner js-file-line">&lt;/resources&gt;</td>
</tr>
</table>
</div></div>
</p></div>
</div></div>
<div class="gist-meta">
        <a href="https://gist.github.com/dsibinski/1376460c699c37b6c72a5c8d911e2c66/raw/0fad55e5233c5f3704011acbb74cb60c6231e3a2/Strings.xml" style="float:right" class="Link--inTextBlock">view raw</a><br />
        <a href="https://gist.github.com/dsibinski/1376460c699c37b6c72a5c8d911e2c66#file-strings-xml" class="Link--inTextBlock"><br />
          Strings.xml<br />
        </a><br />
        hosted with &#10084; by <a class="Link--inTextBlock" href="https://github.com">GitHub</a>
      </div>
</p></div>
</div>
<h4>Usage in layout files</h4>
<p>In our Activities&#8217; layout files (AXML) we can retrieve resources&#8217; values by using <em>@string/id</em> syntax. For example, <span style="color: #ff9900;">TextView</span>&#8216;s text can be set in the following way:</p>
<p><style>.gist table { margin-bottom: 0; }</style>
<div style="tab-size: 8" id="gist46854495" class="gist">
<div class="gist-file" translate="no" data-color-mode="light" data-light-theme="light">
<div class="gist-data">
<div class="js-gist-file-update-container js-task-list-container">
<div id="file-main-axml" class="file my-2">
<div itemprop="text"
      class="Box-body p-0 blob-wrapper data type-xml  "
      style="overflow: auto" tabindex="0" role="region"
      aria-label="Main.axml content, created by dsibinski on 07:25PM on April 19, 2017."
    ></p>
<div class="js-check-hidden-unicode js-blob-code-container blob-code-content">
<p>  <template class="js-file-alert-template"></p>
<div data-view-component="true" class="flash flash-warn flash-full d-flex flex-items-center">
  <svg aria-hidden="true" data-component="Octicon" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-alert">
    <path d="M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"></path>
</svg><br />
    <span><br />
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.<br />
      <a class="Link--inTextBlock" href="https://github.co/hiddenchars" target="_blank">Learn more about bidirectional Unicode characters</a><br />
    </span></p>
<div data-view-component="true" class="flash-action">        <a href="{{ revealButtonHref }}" data-view-component="true" class="btn-sm btn">    Show hidden characters<br />
</a>
</div>
</div>
<p></template><br />
<template class="js-line-alert-template"><br />
  <span aria-label="This line has hidden Unicode characters" data-view-component="true" class="line-alert tooltipped tooltipped-e"><br />
    <svg aria-hidden="true" data-component="Octicon" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-alert">
    <path d="M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"></path>
</svg><br />
</span></template></p>
<table data-hpc class="highlight tab-size js-file-line-container" data-tab-size="4" data-paste-markdown-skip data-tagsearch-path="Main.axml">
<tr>
<td id="file-main-axml-L1" class="blob-num js-line-number js-blob-rnum" data-line-number="1"></td>
<td id="file-main-axml-LC1" class="blob-code blob-code-inner js-file-line">    &lt;TextView</td>
</tr>
<tr>
<td id="file-main-axml-L2" class="blob-num js-line-number js-blob-rnum" data-line-number="2"></td>
<td id="file-main-axml-LC2" class="blob-code blob-code-inner js-file-line">        android:text=&quot;@string/titleMenu&quot;</td>
</tr>
<tr>
<td id="file-main-axml-L3" class="blob-num js-line-number js-blob-rnum" data-line-number="3"></td>
<td id="file-main-axml-LC3" class="blob-code blob-code-inner js-file-line">        android:id=&quot;@+id/titleMenu&quot; /&gt;</td>
</tr>
</table>
</div></div>
</p></div>
</div></div>
<div class="gist-meta">
        <a href="https://gist.github.com/dsibinski/862fadb2f8d1ef158961aa9fa7f1f009/raw/5d1b641f8b95fd886ec261b33f9381424e3a3038/Main.axml" style="float:right" class="Link--inTextBlock">view raw</a><br />
        <a href="https://gist.github.com/dsibinski/862fadb2f8d1ef158961aa9fa7f1f009#file-main-axml" class="Link--inTextBlock"><br />
          Main.axml<br />
        </a><br />
        hosted with &#10084; by <a class="Link--inTextBlock" href="https://github.com">GitHub</a>
      </div>
</p></div>
</div>
<p>It can be used exactly the same way in the UI designer in Visual Studio.</p>
<h4>Usage directly in code</h4>
<p>In the code we can retrieve values of particular resources using <span style="color: #ff9900;">Resources.GetText</span> method giving it selected resource&#8217;s id as <span style="color: #ff9900;">Resource.String</span> class&#8217;s property:</p>
<pre><pre class="brush: csharp; title: ; notranslate">string titleMenuText = Resources.GetText(Resource.String.titleMenu);</pre>
<p>With all strings translated, I can see UI of <em>MoneyBack</em> translated when my device&#8217;s language is set to Polish:</p>

<a href='https://www.codejourney.net/android-apps-localization/moneyback_pl/'><img loading="lazy" decoding="async" width="169" height="300" src="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/MoneyBack_PL.png?fit=169%2C300&amp;ssl=1" class="attachment-medium size-medium" alt="" srcset="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/MoneyBack_PL.png?w=1080&amp;ssl=1 1080w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/MoneyBack_PL.png?resize=169%2C300&amp;ssl=1 169w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/MoneyBack_PL.png?resize=768%2C1365&amp;ssl=1 768w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/MoneyBack_PL.png?resize=576%2C1024&amp;ssl=1 576w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/MoneyBack_PL.png?resize=720%2C1280&amp;ssl=1 720w" sizes="auto, (max-width: 169px) 100vw, 169px" data-attachment-id="1927" data-permalink="https://www.codejourney.net/android-apps-localization/moneyback_pl/" data-orig-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/MoneyBack_PL.png?fit=1080%2C1920&amp;ssl=1" data-orig-size="1080,1920" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="MoneyBack_PL" data-image-description="" data-image-caption="&lt;p&gt;MoneyBack &amp;#8211; PL&lt;/p&gt;
" data-large-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/MoneyBack_PL.png?fit=576%2C1024&amp;ssl=1" /></a>
<a href='https://www.codejourney.net/android-apps-localization/moneyback_en/'><img loading="lazy" decoding="async" width="169" height="300" src="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/MoneyBack_EN.png?fit=169%2C300&amp;ssl=1" class="attachment-medium size-medium" alt="" srcset="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/MoneyBack_EN.png?w=1080&amp;ssl=1 1080w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/MoneyBack_EN.png?resize=169%2C300&amp;ssl=1 169w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/MoneyBack_EN.png?resize=768%2C1365&amp;ssl=1 768w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/MoneyBack_EN.png?resize=576%2C1024&amp;ssl=1 576w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/MoneyBack_EN.png?resize=720%2C1280&amp;ssl=1 720w" sizes="auto, (max-width: 169px) 100vw, 169px" data-attachment-id="1926" data-permalink="https://www.codejourney.net/android-apps-localization/moneyback_en/" data-orig-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/MoneyBack_EN.png?fit=1080%2C1920&amp;ssl=1" data-orig-size="1080,1920" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="MoneyBack_EN" data-image-description="" data-image-caption="&lt;p&gt;MoneyBack &amp;#8211; EN&lt;/p&gt;
" data-large-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/MoneyBack_EN.png?fit=576%2C1024&amp;ssl=1" /></a>

<h4>Quantity strings</h4>
<p>Very interesting concept are so called <strong>quantity strings</strong>. It allows to define differently formatted strings depending on a number of some elements determined at runtime. For instance, on the list of people we could have the following strings displayed depending on the number of people:</p>
<p>&#8220;There is 1 person in your database.&#8221;</p>
<p>&#8220;There are 2 people in your database.&#8221;</p>
<p>To declare such kind of quantity string, we&#8217;d add to <em>Strings.xml</em> the following section:</p>
<p><style>.gist table { margin-bottom: 0; }</style>
<div style="tab-size: 8" id="gist46854777" class="gist">
<div class="gist-file" translate="no" data-color-mode="light" data-light-theme="light">
<div class="gist-data">
<div class="js-gist-file-update-container js-task-list-container">
<div id="file-strings_plurals-xml" class="file my-2">
<div itemprop="text"
      class="Box-body p-0 blob-wrapper data type-xml  "
      style="overflow: auto" tabindex="0" role="region"
      aria-label="Strings_plurals.xml content, created by dsibinski on 07:35PM on April 19, 2017."
    ></p>
<div class="js-check-hidden-unicode js-blob-code-container blob-code-content">
<p>  <template class="js-file-alert-template"></p>
<div data-view-component="true" class="flash flash-warn flash-full d-flex flex-items-center">
  <svg aria-hidden="true" data-component="Octicon" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-alert">
    <path d="M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"></path>
</svg><br />
    <span><br />
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.<br />
      <a class="Link--inTextBlock" href="https://github.co/hiddenchars" target="_blank">Learn more about bidirectional Unicode characters</a><br />
    </span></p>
<div data-view-component="true" class="flash-action">        <a href="{{ revealButtonHref }}" data-view-component="true" class="btn-sm btn">    Show hidden characters<br />
</a>
</div>
</div>
<p></template><br />
<template class="js-line-alert-template"><br />
  <span aria-label="This line has hidden Unicode characters" data-view-component="true" class="line-alert tooltipped tooltipped-e"><br />
    <svg aria-hidden="true" data-component="Octicon" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-alert">
    <path d="M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"></path>
</svg><br />
</span></template></p>
<table data-hpc class="highlight tab-size js-file-line-container" data-tab-size="4" data-paste-markdown-skip data-tagsearch-path="Strings_plurals.xml">
<tr>
<td id="file-strings_plurals-xml-L1" class="blob-num js-line-number js-blob-rnum" data-line-number="1"></td>
<td id="file-strings_plurals-xml-LC1" class="blob-code blob-code-inner js-file-line">&lt;plurals name=&quot;numberOfPeople&quot;&gt;</td>
</tr>
<tr>
<td id="file-strings_plurals-xml-L2" class="blob-num js-line-number js-blob-rnum" data-line-number="2"></td>
<td id="file-strings_plurals-xml-LC2" class="blob-code blob-code-inner js-file-line">         &lt;item quantity=&quot;one&quot;&gt;There is %d person in your database.&lt;/item&gt;</td>
</tr>
<tr>
<td id="file-strings_plurals-xml-L3" class="blob-num js-line-number js-blob-rnum" data-line-number="3"></td>
<td id="file-strings_plurals-xml-LC3" class="blob-code blob-code-inner js-file-line">         &lt;item quantity=&quot;other&quot;&gt;There are %d people in your database..&lt;/item&gt;</td>
</tr>
<tr>
<td id="file-strings_plurals-xml-L4" class="blob-num js-line-number js-blob-rnum" data-line-number="4"></td>
<td id="file-strings_plurals-xml-LC4" class="blob-code blob-code-inner js-file-line"> &lt;/plurals&gt;</td>
</tr>
</table>
</div></div>
</p></div>
</div></div>
<div class="gist-meta">
        <a href="https://gist.github.com/dsibinski/242f23517ee05b52f6ec365dd06e9ef6/raw/88b97726600cff4fc890821351ef1da81f346a72/Strings_plurals.xml" style="float:right" class="Link--inTextBlock">view raw</a><br />
        <a href="https://gist.github.com/dsibinski/242f23517ee05b52f6ec365dd06e9ef6#file-strings_plurals-xml" class="Link--inTextBlock"><br />
          Strings_plurals.xml<br />
        </a><br />
        hosted with &#10084; by <a class="Link--inTextBlock" href="https://github.com">GitHub</a>
      </div>
</p></div>
</div>
<p>To illustrate: in order to retrieve and format appropriate string depending on value stored in <span style="color: #ff9900;">numPeople</span> variable, the following code might be used:</p>
<pre><pre class="brush: csharp; title: ; notranslate">var text = Resources.GetQuantityString(Resource.Plurals.numberOfPeople, numPeople, numPeople);</pre>
<p>Second parameter passed is used to determine <strong>which</strong> string (plural) to use, and third parameter is the <strong>actual value</strong> passed to the final string (in the place of <em>%d</em> in that case).</p>
<p>The <em>quantity</em> of each plural can contain one of the following values:</p>
<ul>
<li>zero</li>
<li>one</li>
<li>two</li>
<li>few</li>
<li>many</li>
<li>other</li>
</ul>
<p>More details can be found <a href="https://developer.android.com/guide/topics/resources/string-resource.html#Plurals" target="_blank" rel="noopener">here</a>.</p>
<h4>Application&#8217;s/Activity&#8217;s name</h4>
<p>We can also localize the name of our app, by using string resource in the <span style="color: #ff9900;">ActivityAttribute</span> defined on <span style="color: #ff9900;">MainActivity</span>:</p>
<pre><pre class="brush: csharp; title: ; notranslate">&#x5B;Activity(Label = &quot;@string/ApplicationName&quot;, MainLauncher = true, Icon = &quot;@drawable/icon&quot;)]</pre>
<p>The same can be done for any of our app&#8217;s activities. However, be careful here if you are referencing your main Android project from another one (e.g. from tests project) &#8211; I&#8217;ve experienced really annoying issue with that (more details below).</p>
<h4>Other resources</h4>
<p>As we already said, not only strings can be localized. You can localize any kind of resources placed within <em>Resources</em> folder, for example images or data files.</p>
<h2>The file “obj\Debug\android\bin\packaged_resources” does not exist</h2>
<p>Two weeks ago, when I finally decided to take a break in publishing DSP posts, I wanted to work on <em>MoneyBack</em> a bit, however I encountered very frustrating issue, which I even described in <a href="http://stackoverflow.com/questions/43294345/visual-studio-2017-xamarin-the-file-obj-debug-android-bin-packaged-resource" target="_blank" rel="noopener">this StackOverflow post</a>. I&#8217;ve been fighting with that problem for few days and I still actually don&#8217;t know the real cause of the issue.</p>
<p>Basically, when I used resource string on my <span style="color: #ff9900;">PeopleListActivity</span> in order to translate its title:</p>
<pre><pre class="brush: csharp; title: ; notranslate">&#x5B;Activity(Label = &quot;@string/peopleListTitle&quot;)]</pre>
<p>I couldn&#8217;t build my <strong>MoneyBack.Android.Tests </strong>(yes, different project!) project. I was getting the following build error message:</p>
<figure id="attachment_1955" aria-describedby="caption-attachment-1955" style="width: 963px" class="wp-caption alignnone"><img data-recalc-dims="1" loading="lazy" decoding="async" data-attachment-id="1955" data-permalink="https://www.codejourney.net/android-apps-localization/resourcenotfound/" data-orig-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/ResourceNotFound.jpg?fit=963%2C163&amp;ssl=1" data-orig-size="963,163" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;Dawid Sibi\u0144ski&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;1492631799&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="ResourceNotFound" data-image-description="" data-image-caption="" data-large-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/ResourceNotFound.jpg?fit=963%2C163&amp;ssl=1" class=" size-full wp-image-1955 alignnone" src="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/ResourceNotFound.jpg?resize=963%2C163&#038;ssl=1" alt="ResourceNotFound.JPG" width="963" height="163" srcset="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/ResourceNotFound.jpg?w=963&amp;ssl=1 963w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/ResourceNotFound.jpg?resize=300%2C51&amp;ssl=1 300w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/ResourceNotFound.jpg?resize=768%2C130&amp;ssl=1 768w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/ResourceNotFound.jpg?resize=720%2C122&amp;ssl=1 720w" sizes="auto, (max-width: 963px) 100vw, 963px" /><figcaption id="caption-attachment-1955" class="wp-caption-text">Error during building Android tests project</figcaption></figure>
<p>I explored all existing forums threads on this topic and couldn&#8217;t resolve this issue. Finally, by setting build output verbosity to <code>Diagnostic</code> in <em>Tools -&gt; Options -&gt; Projects and Solutions -&gt; Build and Run </em>I was able to see the detailed error my build process is giving. It was telling me that <em>@string/peopleListTitle </em>doesn&#8217;t exist (or something similar). So when I changed the <span style="color: #ff9900;">Label</span>&#8216;s value in <span style="color: #ff9900;">ActivityAttribute</span> to use a string directly (not taken as a resource), it worked fine and the build passed.</p>
<p>Today I tried once more to use resource string, obviously getting the same error message. Then I realized that my <em>MoneyBack.Android.Tests</em> project is referencing  <em>MoneyBack</em> project in which I define those somehow missing strings:</p>
<figure id="attachment_1965" aria-describedby="caption-attachment-1965" style="width: 266px" class="wp-caption aligncenter"><img data-recalc-dims="1" loading="lazy" decoding="async" data-attachment-id="1965" data-permalink="https://www.codejourney.net/android-apps-localization/resourcenotfound_test_reference/" data-orig-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/ResourceNotFound_Test_Reference.jpg?fit=384%2C426&amp;ssl=1" data-orig-size="384,426" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;Dawid Sibi\u0144ski&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;1492631847&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="ResourceNotFound_Test_Reference" data-image-description="" data-image-caption="" data-large-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/ResourceNotFound_Test_Reference.jpg?fit=384%2C426&amp;ssl=1" class=" wp-image-1965 aligncenter" src="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/ResourceNotFound_Test_Reference.jpg?resize=266%2C295&#038;ssl=1" alt="ResourceNotFound_Test_Reference.JPG" width="266" height="295" srcset="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/ResourceNotFound_Test_Reference.jpg?w=384&amp;ssl=1 384w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/ResourceNotFound_Test_Reference.jpg?resize=270%2C300&amp;ssl=1 270w" sizes="auto, (max-width: 266px) 100vw, 266px" /><figcaption id="caption-attachment-1965" class="wp-caption-text">Tests project referencing the main one</figcaption></figure>
<p>so I removed that reference (commenting out my unit tests which use <em>MoneyBack</em>&#8216;s logic) and the build worked fine. Apparently when trying to build tests project, which references the main one, in which my strings are defined, <strong>it somehow needs those strings resources to be present in tests project&#8217;s output directory.</strong> I have no idea why, because I&#8217;m not directly using those strings resources in my tests project.</p>
<p>Then I added the reference back and in <em>MoneyBack.Android.Tests</em> project I just created <em>values</em> folder and copy-pasted <em>Strings.xml</em> file to it from the <em>MoneyBack</em> project:</p>
<figure id="attachment_1978" aria-describedby="caption-attachment-1978" style="width: 1166px" class="wp-caption aligncenter"><img data-recalc-dims="1" loading="lazy" decoding="async" data-attachment-id="1978" data-permalink="https://www.codejourney.net/android-apps-localization/resources_strings_copied/" data-orig-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/Resources_Strings_Copied.jpg?fit=1166%2C330&amp;ssl=1" data-orig-size="1166,330" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;Dawid Sibi\u0144ski&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;1492632228&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="Resources_Strings_Copied" data-image-description="" data-image-caption="" data-large-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/Resources_Strings_Copied.jpg?fit=1024%2C290&amp;ssl=1" class="aligncenter size-full wp-image-1978" src="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/Resources_Strings_Copied.jpg?resize=1140%2C323&#038;ssl=1" alt="Resources_Strings_Copied.JPG" width="1140" height="323" srcset="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/Resources_Strings_Copied.jpg?w=1166&amp;ssl=1 1166w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/Resources_Strings_Copied.jpg?resize=300%2C85&amp;ssl=1 300w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/Resources_Strings_Copied.jpg?resize=768%2C217&amp;ssl=1 768w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/Resources_Strings_Copied.jpg?resize=1024%2C290&amp;ssl=1 1024w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/Resources_Strings_Copied.jpg?resize=720%2C204&amp;ssl=1 720w" sizes="auto, (max-width: 1140px) 100vw, 1140px" /><figcaption id="caption-attachment-1978" class="wp-caption-text">Strings.xml copied into test project</figcaption></figure>
<p>and it builds OK!</p>
<p><span style="text-decoration: underline;"><strong>Does any of you have some idea why it may happen?</strong></span> <span style="text-decoration: underline;"><strong>If you have a clue, you can answer here or even <a href="http://stackoverflow.com/questions/43294345/visual-studio-2017-xamarin-the-file-obj-debug-android-bin-packaged-resource" target="_blank" rel="noopener">on SO.</a></p>
<p></strong></span></p>
<p>For me it seems like a bug in the build process. I wanted to share it with you, because I wasted so much time because of this issue and maybe some of you will also find it useful.</p>
<p>BTW, I really recommend using Diagnostic verbosity of the build output for debugging such issues.</p>
<h2>Summary</h2>
<p>We&#8217;ve seen how Android application can be easily localized. I really recommend to put all strings visible for the end user from the beginning in <em>Strings.xml</em> file. Thanks to that, in case our application needs to be <strong>localized</strong>, we can even hire/ask some foreign languages&#8217; interpreters to create country-specific <em>values</em> folder and translate strings resources conveniently. This is even very common in mobile apps communities, that people who are non-technical can contribute to the project by translating the application into their own language.</p>
<p>I hope I won&#8217;t meet any other issues like the one I described today on my further DSP way 🙂 It would allow me to write more stuff here and hopefully implement some usable app finally! Keep your fingers crossed 🙂</p>
<p>PS: If I already mentioned taking breaks in DSP competition, I will also take one more during the first week of May (1-5.05.2017). In case anyone cares 😉</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>The post <a href="https://www.codejourney.net/android-apps-localization/">Android Apps Localization</a> appeared first on <a href="https://www.codejourney.net">CodeJourney.net</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.codejourney.net/android-apps-localization/feed/</wfw:commentRss>
			<slash:comments>12</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1803</post-id>	</item>
		<item>
		<title>Android Layout Types</title>
		<link>https://www.codejourney.net/android-layout-types/</link>
					<comments>https://www.codejourney.net/android-layout-types/#comments</comments>
		
		<dc:creator><![CDATA[Dawid Sibiński]]></dc:creator>
		<pubDate>Sun, 02 Apr 2017 06:55:49 +0000</pubDate>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[android]]></category>
		<category><![CDATA[dajsiepoznac2017]]></category>
		<category><![CDATA[xamarin]]></category>
		<guid isPermaLink="false">http://www.dsibinski.pl/?p=1695</guid>

					<description><![CDATA[<p>If you&#8217;re just an Android user, you may not even know that each screen in your application has controls composed within different Layouts. Let&#8217;s see what are the main Layout Types in designing Android app. What is a Layout ? Layout defines a visual structure of an Activity (or app widget). It may be considered as&#8230;</p>
<p>The post <a href="https://www.codejourney.net/android-layout-types/">Android Layout Types</a> appeared first on <a href="https://www.codejourney.net">CodeJourney.net</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>If you&#8217;re just an Android user, you may not even know that each screen in your application has controls composed within different <em>Layouts</em>. Let&#8217;s see what are the main Layout Types in designing Android app.<br />
<span id="more-1695"></span></p>
<h2>What is a Layout ?</h2>
<p><strong>Layout defines a visual structure</strong> of an Activity (or <a href="https://developer.android.com/guide/topics/appwidgets/index.html" target="_blank" rel="noopener">app widget</a>). It may be considered as a set of rules according to which controls (buttons, text fields, input fields etc.) are placed on the <em>View</em>.</p>
<h2>Layouts structure</h2>
<p>Basically, user interface in Android apps is built using <em>Layouts</em>. Each <em>Layout</em> is a subclass of <span style="color: #ff9900;">ViewGroup</span> class, which derives from <span style="color: #ff9900;">View</span> class, which is the basic UI building block. <span style="color: #ff9900;">View</span> is the base class for buttons, text fields etc., more precisely: for <a href="https://developer.xamarin.com/api/namespace/Android.Widget/" target="_blank" rel="noopener">widgets</a> (don&#8217;t confuse it with app widgets you place on your Android screen <img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f642.png" alt="🙂" class="wp-smiley" style="height: 1em; max-height: 1em;" /> ).</p>
<p>The following diagram presents this hierarchy based on <em><span style="color: #ff9900;">RelativeLayout</span></em>:</p>
<figure id="attachment_1717" aria-describedby="caption-attachment-1717" style="width: 615px" class="wp-caption aligncenter"><img data-recalc-dims="1" loading="lazy" decoding="async" data-attachment-id="1717" data-permalink="https://www.codejourney.net/android-layout-types/android_view_hierarchy_diagram/" data-orig-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/Android_view_hierarchy_diagram.png?fit=615%2C272&amp;ssl=1" data-orig-size="615,272" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="Android_view_hierarchy_diagram" data-image-description="" data-image-caption="" data-large-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/Android_view_hierarchy_diagram.png?fit=615%2C272&amp;ssl=1" class="aligncenter size-full wp-image-1717" src="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/Android_view_hierarchy_diagram.png?resize=615%2C272&#038;ssl=1" alt="Android_view_hierarchy_diagram.png" width="615" height="272" srcset="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/Android_view_hierarchy_diagram.png?w=615&amp;ssl=1 615w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/Android_view_hierarchy_diagram.png?resize=300%2C133&amp;ssl=1 300w" sizes="auto, (max-width: 615px) 100vw, 615px" /><figcaption id="caption-attachment-1717" class="wp-caption-text">RelativeLayout hierarchy, source: <a href="http://www.techotopia.com/index.php/Understanding_Android_Views,_View_Groups_and_Layouts" target="_blank" rel="noopener">techotopia.com</a></figcaption></figure>
<p>Let&#8217;s now see what are the most important Layout Types. Below each screenshot used to present a particular Layout Type you can find its <span style="text-decoration: underline;">source</span>, which leads to a tutorial or more detailed explanation on how to work with it.</p>
<h2>Linear Layout</h2>
<p><em>LinearLayout</em> is the most basic type of <em>Layout</em>. When Android app is created in Visual Studio 2017, its <span style="color: #ff9900;">MainActivity</span> has by default <em>LinearLayout</em> set:</p>
<figure id="attachment_1725" aria-describedby="caption-attachment-1725" style="width: 569px" class="wp-caption aligncenter"><img data-recalc-dims="1" loading="lazy" decoding="async" data-attachment-id="1725" data-permalink="https://www.codejourney.net/android-layout-types/linear_moneyback/" data-orig-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/Linear_MoneyBack.jpg?fit=847%2C327&amp;ssl=1" data-orig-size="847,327" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;Dawid Sibi\u0144ski&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;1491120503&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;1&quot;}" data-image-title="Linear_MoneyBack" data-image-description="" data-image-caption="" data-large-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/Linear_MoneyBack.jpg?fit=847%2C327&amp;ssl=1" class="wp-image-1725" src="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/Linear_MoneyBack.jpg?resize=569%2C220&#038;ssl=1" alt="Linear_MoneyBack" width="569" height="220" srcset="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/Linear_MoneyBack.jpg?w=847&amp;ssl=1 847w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/Linear_MoneyBack.jpg?resize=300%2C116&amp;ssl=1 300w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/Linear_MoneyBack.jpg?resize=768%2C297&amp;ssl=1 768w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/Linear_MoneyBack.jpg?resize=720%2C278&amp;ssl=1 720w" sizes="auto, (max-width: 569px) 100vw, 569px" /><figcaption id="caption-attachment-1725" class="wp-caption-text">LinearLayout set on MoneyBack&#8217;s MainActivity</figcaption></figure>
<p>This type of <em>Layout</em> enforces you to put your controls in a linear direction, either horizontally or vertically:</p>
<figure id="attachment_1730" aria-describedby="caption-attachment-1730" style="width: 351px" class="wp-caption aligncenter"><img data-recalc-dims="1" loading="lazy" decoding="async" data-attachment-id="1730" data-permalink="https://www.codejourney.net/android-layout-types/linearlayout/" data-orig-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/LinearLayout.png?fit=788%2C517&amp;ssl=1" data-orig-size="788,517" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="LinearLayout" data-image-description="" data-image-caption="" data-large-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/LinearLayout.png?fit=788%2C517&amp;ssl=1" class=" size-full wp-image-1730 aligncenter" src="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/LinearLayout.png?resize=351%2C230&#038;ssl=1" alt="LinearLayout.png" width="351" height="230" srcset="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/LinearLayout.png?w=788&amp;ssl=1 788w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/LinearLayout.png?resize=300%2C197&amp;ssl=1 300w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/LinearLayout.png?resize=768%2C504&amp;ssl=1 768w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/LinearLayout.png?resize=720%2C472&amp;ssl=1 720w" sizes="auto, (max-width: 351px) 100vw, 351px" /><figcaption id="caption-attachment-1730" class="wp-caption-text">LinearLayout, <a href="http://android4beginners.com/2013/07/lesson-2-1-how-to-build-android-app-with-simple-but-powerful-linearlayout-plus-layout-orientation-as-well-as-size-and-weight-of-elements/" target="_blank" rel="noopener">source</a></figcaption></figure>
<h2>Relative Layout</h2>
<p><em>RelativeLayout</em> enforces to display elements in relations to each other. You can specify that, for instance, one UI element can be said to be placed on the left of another element, or on the bottom of another etc. Each UI element can also be positioned according to the layout&#8217;s borders (e.g. aligned to the right):</p>
<figure id="attachment_1739" aria-describedby="caption-attachment-1739" style="width: 521px" class="wp-caption aligncenter"><img data-recalc-dims="1" loading="lazy" decoding="async" data-attachment-id="1739" data-permalink="https://www.codejourney.net/android-layout-types/relativelayout_android/" data-orig-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/RelativeLayout_Android.png?fit=801%2C501&amp;ssl=1" data-orig-size="801,501" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="RelativeLayout_Android" data-image-description="" data-image-caption="" data-large-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/RelativeLayout_Android.png?fit=801%2C501&amp;ssl=1" class="aligncenter wp-image-1739" src="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/RelativeLayout_Android.png?resize=521%2C326&#038;ssl=1" alt="RelativeLayout_Android.png" width="521" height="326" srcset="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/RelativeLayout_Android.png?w=801&amp;ssl=1 801w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/RelativeLayout_Android.png?resize=300%2C188&amp;ssl=1 300w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/RelativeLayout_Android.png?resize=768%2C480&amp;ssl=1 768w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/RelativeLayout_Android.png?resize=720%2C450&amp;ssl=1 720w" sizes="auto, (max-width: 521px) 100vw, 521px" /><figcaption id="caption-attachment-1739" class="wp-caption-text">RelativeLayout, <a href="https://www.skynils.com/relative-layout-in-android/" target="_blank" rel="noopener">source</a></figcaption></figure>
<p><em>RelativeLayout</em> is very powerful. Consider that for building mobile apps&#8217; interfaces these can be run on multiple devices with different screens&#8217; resolutions. <em>RelativeLayout</em> allows (if properly built, of course) to adjust your set of controls easily to almost every type of screen. It&#8217;s quite specific and I personally found it difficult to understand and use initially, but it seems to be worth it.</p>
<h2>Table Layout</h2>
<p>As its name suggests, <em>TableLayout</em> allows to group elements into rows and columns:</p>
<figure id="attachment_1746" aria-describedby="caption-attachment-1746" style="width: 248px" class="wp-caption aligncenter"><img data-recalc-dims="1" loading="lazy" decoding="async" data-attachment-id="1746" data-permalink="https://www.codejourney.net/android-layout-types/tablelayout_android/" data-orig-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/TableLayout_Android.png?fit=287%2C400&amp;ssl=1" data-orig-size="287,400" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="TableLayout_Android" data-image-description="" data-image-caption="" data-large-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/TableLayout_Android.png?fit=287%2C400&amp;ssl=1" class="aligncenter wp-image-1746" src="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/TableLayout_Android.png?resize=248%2C346&#038;ssl=1" alt="TableLayout_Android.jpg" width="248" height="346" srcset="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/TableLayout_Android.png?w=287&amp;ssl=1 287w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/TableLayout_Android.png?resize=215%2C300&amp;ssl=1 215w" sizes="auto, (max-width: 248px) 100vw, 248px" /><figcaption id="caption-attachment-1746" class="wp-caption-text">TableLayout, <a href="https://www.tutorialspoint.com/android/android_table_layout.htm" target="_blank" rel="noopener">source</a></figcaption></figure>
<p>May be useful when displaying some statistics or reports.</p>
<h2>Grid View</h2>
<p><em>GridView</em> displays items in two-dimensional grid. The list can be easily scrolled. This type of <em>Layout</em> is often used on screens displaying photos or similar sets of &#8220;blocks&#8221; to click:</p>
<figure id="attachment_1753" aria-describedby="caption-attachment-1753" style="width: 436px" class="wp-caption aligncenter"><img data-recalc-dims="1" loading="lazy" decoding="async" data-attachment-id="1753" data-permalink="https://www.codejourney.net/android-layout-types/gridview_android/" data-orig-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/GridView_Android.png?fit=580%2C491&amp;ssl=1" data-orig-size="580,491" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="GridView_Android" data-image-description="" data-image-caption="" data-large-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/GridView_Android.png?fit=580%2C491&amp;ssl=1" class="aligncenter wp-image-1753" src="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/GridView_Android.png?resize=436%2C369&#038;ssl=1" alt="GridView_Android.png" width="436" height="369" srcset="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/GridView_Android.png?w=580&amp;ssl=1 580w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/GridView_Android.png?resize=300%2C254&amp;ssl=1 300w" sizes="auto, (max-width: 436px) 100vw, 436px" /><figcaption id="caption-attachment-1753" class="wp-caption-text">GridView, <a href="http://www.androidhive.info/2012/02/android-gridview-layout-tutorial/" target="_blank" rel="noopener">source</a></figcaption></figure>
<h2>Tab Layout</h2>
<p><a href="https://developer.xamarin.com/guides/android/user_interface/tab_layout/" target="_blank" rel="noopener">Tabbed layouts</a> allow to introduce tabs in our Android application. Then, a single Activity may contain several tabs and user can easily switch between them. On each tab you can use different type of Layout.</p>
<p>Consider that tabs design has changed between Android 2.X and 4.X:</p>
<figure id="attachment_1764" aria-describedby="caption-attachment-1764" style="width: 474px" class="wp-caption aligncenter"><img data-recalc-dims="1" loading="lazy" decoding="async" data-attachment-id="1764" data-permalink="https://www.codejourney.net/android-layout-types/tabs_android/" data-orig-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/Tabs_Android.png?fit=550%2C194&amp;ssl=1" data-orig-size="550,194" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="Tabs_Android" data-image-description="" data-image-caption="" data-large-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/Tabs_Android.png?fit=550%2C194&amp;ssl=1" class=" wp-image-1764 aligncenter" src="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/Tabs_Android.png?resize=474%2C167&#038;ssl=1" alt="Tabs_Android.png" width="474" height="167" srcset="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/Tabs_Android.png?w=550&amp;ssl=1 550w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/Tabs_Android.png?resize=300%2C106&amp;ssl=1 300w" sizes="auto, (max-width: 474px) 100vw, 474px" /><figcaption id="caption-attachment-1764" class="wp-caption-text">Tabs, <a href="https://developer.xamarin.com/guides/android/user_interface/tab_layout/" target="_blank" rel="noopener">source</a></figcaption></figure>
<h2>List View</h2>
<p><em>ListView</em> allows to display a list of items. It may be used in multiple places, from short lists of menu options to long list of emails or news feed. It allows to easily and quickly present a list of items:</p>
<figure id="attachment_1778" aria-describedby="caption-attachment-1778" style="width: 267px" class="wp-caption aligncenter"><img data-recalc-dims="1" loading="lazy" decoding="async" data-attachment-id="1778" data-permalink="https://www.codejourney.net/android-layout-types/listview_android/" data-orig-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/ListView_Android.png?fit=320%2C480&amp;ssl=1" data-orig-size="320,480" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="ListView_Android" data-image-description="" data-image-caption="" data-large-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/ListView_Android.png?fit=320%2C480&amp;ssl=1" class=" size-full wp-image-1778 aligncenter" src="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/ListView_Android.png?resize=267%2C401&#038;ssl=1" alt="ListView_Android.png" width="267" height="401" srcset="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/ListView_Android.png?w=320&amp;ssl=1 320w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/ListView_Android.png?resize=200%2C300&amp;ssl=1 200w" sizes="auto, (max-width: 267px) 100vw, 267px" /><figcaption id="caption-attachment-1778" class="wp-caption-text">ListView, <a href="http://windrealm.org/tutorials/android/android-listview.php" target="_blank" rel="noopener">source</a></figcaption></figure>
<p>I used it in <em>MoneyBack</em> for displaying a very simple list of people from the database. You can check how it&#8217;s done in <a href="https://gist.github.com/dsibinski/b6dcbf1dc0956b584188282c2cb832a2" target="_blank" rel="noopener">this public Gist</a> (there is even no AXML layout file for it, it&#8217;s just an Activity class).</p>
<p>However, Android and Xamarin teams recommend to use <em>RecyclerView</em> for new apps development, which is said to be more advanced and flexible version of<em> ListView</em>. I just noticed it seems to be a bit more complex to set up. You can check more details <a href="https://developer.xamarin.com/guides/android/user_interface/recyclerview/" target="_blank" rel="noopener">here.</a></p>
<h2>Summary</h2>
<p>We&#8217;ve explored some basic Layout Types that can be used for grouping UI elements in Android application. Remember that all types of layouts we&#8217;ve gone through may be nested into each other (as we&#8217;ve seen for tabs &#8211; you can use tabbed layout and then in each tab &#8220;nest&#8221; any other type of layout).</p>
<p>It may seem to be a bit strict, that we shouldn&#8217;t just put the controls whatever we&#8217;d like to (as we are used to do in <em>WinForms</em>, for example <img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f609.png" alt="😉" class="wp-smiley" style="height: 1em; max-height: 1em;" /> ), but mobile development requires such restrictions.</p>
<p>Especially building for Android &#8211; as for September 2015, there were <strong>1.5 billion</strong> registered devices running Android system. This implies thousands of different screens resolutions, which must be handled by the UI of our apps.</p>
<p><span style="text-decoration: underline;"><strong>What types of Layouts do you use the most in your Android apps? Do you have any best practices using them ? Share your knowledge! <img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f642.png" alt="🙂" class="wp-smiley" style="height: 1em; max-height: 1em;" /></strong></span></p>
<p>The post <a href="https://www.codejourney.net/android-layout-types/">Android Layout Types</a> appeared first on <a href="https://www.codejourney.net">CodeJourney.net</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.codejourney.net/android-layout-types/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1695</post-id>	</item>
		<item>
		<title>Xamarin &#8211; Android Intents</title>
		<link>https://www.codejourney.net/xamarin-android-intents/</link>
					<comments>https://www.codejourney.net/xamarin-android-intents/#respond</comments>
		
		<dc:creator><![CDATA[Dawid Sibiński]]></dc:creator>
		<pubDate>Sat, 01 Apr 2017 10:19:59 +0000</pubDate>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[android]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[dajsiepoznac2017]]></category>
		<category><![CDATA[xamarin]]></category>
		<guid isPermaLink="false">http://www.dsibinski.pl/?p=1499</guid>

					<description><![CDATA[<p>We&#8217;ve already seen what are Activities, the most basic pieces of every Android app and today&#8217;s topic is associated with it. We&#8217;re going to see how to communicate between Activities (or Application Blocks) using Intents. Android Application Blocks Android apps are composed of Application Blocks, which are special kind of Android classes consisting several elements bundled together,&#8230;</p>
<p>The post <a href="https://www.codejourney.net/xamarin-android-intents/">Xamarin &#8211; Android Intents</a> appeared first on <a href="https://www.codejourney.net">CodeJourney.net</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>We&#8217;ve already seen what are <a href="https://www.codejourney.net/2017/03/xamarin-android-activities/" target="_blank" rel="noopener">Activities</a>, the most basic pieces of every Android app and today&#8217;s topic is associated with it. We&#8217;re going to see how to communicate between Activities (or <em>Application Blocks</em>) using <em>Intents</em>.<br />
<span id="more-1499"></span></p>
<h2>Android Application Blocks</h2>
<p>Android apps are composed of <em>Application Blocks</em>, which are special kind of Android classes consisting several elements bundled together, including:</p>
<ul>
<li><a href="https://www.codejourney.net/2017/03/xamarin-android-activities/" target="_blank" rel="noopener">Activities</a></li>
<li><a href="https://developer.xamarin.com/guides/android/application_fundamentals/services/" target="_blank" rel="noopener">Services</a></li>
<li>Resources (images, themes, classes)</li>
</ul>
<p>Everything that comes in such <em>package</em> is coordinated by <em>AndroidManifest.XML</em> file. Especially, in this XML file (or by using various attributes on Activity class) it&#8217;s possible to <em>register</em> our <em>Application Block</em> to be &#8220;callable&#8221; by the others.</p>
<p>We&#8217;ll see more details in a while, but generally your app block is &#8220;callable&#8221; when it can be used by the other apps &#8211; probably you&#8217;ve already seen Application Chooser screen on your Android phone, e.g. when you wanted to open downloaded movie and the system asked you which video player you want to use. The same can be done with your own app &#8211; if you&#8217;re developing a dialer app, you can register it to be callable for <em><a href="https://developer.android.com/reference/android/content/Intent.html#ACTION_DIAL" target="_blank" rel="noopener">ACTION_DIAL</a> </em>Activity Action. Then, as soon as any other app uses <em>Intent</em> to make a phone call (which we&#8217;ll see in this post), Application Chooser appears and your app will be one of the possible ones to use for making this phone call.</p>
<h2>What is an Intent ?</h2>
<p>Android system is designed to be <em>loosely-coupled</em>. Moreover, there is a <em>principle of least privilege</em> introduced in system&#8217;s architecture. It means that each app has access only to <em>Blocks</em> which it requires to work. Different <em>Blocks</em> don&#8217;t know much about each other (even if defined within the same application). Here&#8217;s where an<em> </em><em>Intent</em> comes into play. <em><strong>Application Blocks</strong></em><strong> use </strong><strong><em>Intents</em></strong><strong> to asynchronously communicate with each other.</p>
<p></strong></p>
<p>In general, you can think of an <em>Intent </em>literally &#8211; <strong>it&#8217;s the <em>intent</em> (or a <em>will</em>) to do something</strong>. By sending <em>Intents</em> between different components, we can coordinate complex actions such as launching email app to send a message, using Location for obtaining user&#8217;s coordinates or navigating between application&#8217;s screens.</p>
<p>For me, we can think of <em>Intents</em> and their usage from two perspectives:</p>
<ol>
<li><strong><em>Intent</em> as an</strong> <span style="text-decoration: underline;"><strong>intent</strong></span><strong> </strong>&#8211; a will to do something. In this case, you use <em>Intent</em> to execute <em>some</em> action. When creating a new <em>Intent</em> you need to tell it <em>what</em> you want to do and give it necessary <em>parameters</em> for such operation (e.g. for <em>send email</em> action, you need to provide <em>email address </em>parameter)</li>
<li><strong><em>Intent</em> as a</strong> <span style="text-decoration: underline;"><strong>message </strong></span>&#8211; bidirectional information having <em>sender</em>, <em>recipient </em>and potentially some <em>content</em>. This can be for instance navigating to a new screen (Activity), where sender is the original Activity, recipient is the destination Activity to be opened and the content may consist some parameters to pass between two screens.</li>
</ol>
<p>We&#8217;ll now see those two approaches in details.</p>
<h2>Intent as an intent</h2>
<p>In order to trigger another (external) action, e.g. camera recording or email sending, we can create an <em>Intent</em> and start a new Activity. Let&#8217;s see it by the example I implemented in <em>MoneyBack</em> &#8211; I added an additional <em>ListActivity</em> (<span style="color: #ff9900;">PeopleListActivity</span> class) which is the list of people added to app&#8217;s database. When a person on the list is clicked, I create an <em>Intent</em> in order to call his/her phone number as the following code presents:</p>
<p><style>.gist table { margin-bottom: 0; }</style>
<div style="tab-size: 8" id="gist46270777" class="gist">
<div class="gist-file" translate="no" data-color-mode="light" data-light-theme="light">
<div class="gist-data">
<div class="js-gist-file-update-container js-task-list-container">
<div id="file-peoplelistactivity_clicking-cs" class="file my-2">
<div itemprop="text"
      class="Box-body p-0 blob-wrapper data type-c  "
      style="overflow: auto" tabindex="0" role="region"
      aria-label="PeopleListActivity_clicking.cs content, created by dsibinski on 09:03AM on April 01, 2017."
    ></p>
<div class="js-check-hidden-unicode js-blob-code-container blob-code-content">
<p>  <template class="js-file-alert-template"></p>
<div data-view-component="true" class="flash flash-warn flash-full d-flex flex-items-center">
  <svg aria-hidden="true" data-component="Octicon" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-alert">
    <path d="M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"></path>
</svg><br />
    <span><br />
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.<br />
      <a class="Link--inTextBlock" href="https://github.co/hiddenchars" target="_blank">Learn more about bidirectional Unicode characters</a><br />
    </span></p>
<div data-view-component="true" class="flash-action">        <a href="{{ revealButtonHref }}" data-view-component="true" class="btn-sm btn">    Show hidden characters<br />
</a>
</div>
</div>
<p></template><br />
<template class="js-line-alert-template"><br />
  <span aria-label="This line has hidden Unicode characters" data-view-component="true" class="line-alert tooltipped tooltipped-e"><br />
    <svg aria-hidden="true" data-component="Octicon" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-alert">
    <path d="M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"></path>
</svg><br />
</span></template></p>
<table data-hpc class="highlight tab-size js-file-line-container" data-tab-size="4" data-paste-markdown-skip data-tagsearch-path="PeopleListActivity_clicking.cs">
<tr>
<td id="file-peoplelistactivity_clicking-cs-L1" class="blob-num js-line-number js-blob-rnum" data-line-number="1"></td>
<td id="file-peoplelistactivity_clicking-cs-LC1" class="blob-code blob-code-inner js-file-line">  private void ListView_ItemClick(object sender, AdapterView.ItemClickEventArgs e)</td>
</tr>
<tr>
<td id="file-peoplelistactivity_clicking-cs-L2" class="blob-num js-line-number js-blob-rnum" data-line-number="2"></td>
<td id="file-peoplelistactivity_clicking-cs-LC2" class="blob-code blob-code-inner js-file-line">  {</td>
</tr>
<tr>
<td id="file-peoplelistactivity_clicking-cs-L3" class="blob-num js-line-number js-blob-rnum" data-line-number="3"></td>
<td id="file-peoplelistactivity_clicking-cs-LC3" class="blob-code blob-code-inner js-file-line">      var person = _peopleList[e.Position];</td>
</tr>
<tr>
<td id="file-peoplelistactivity_clicking-cs-L4" class="blob-num js-line-number js-blob-rnum" data-line-number="4"></td>
<td id="file-peoplelistactivity_clicking-cs-LC4" class="blob-code blob-code-inner js-file-line">
</td>
</tr>
<tr>
<td id="file-peoplelistactivity_clicking-cs-L5" class="blob-num js-line-number js-blob-rnum" data-line-number="5"></td>
<td id="file-peoplelistactivity_clicking-cs-LC5" class="blob-code blob-code-inner js-file-line">      var uri = Android.Net.Uri.Parse(&quot;tel:&quot; + person.PhoneNumber);</td>
</tr>
<tr>
<td id="file-peoplelistactivity_clicking-cs-L6" class="blob-num js-line-number js-blob-rnum" data-line-number="6"></td>
<td id="file-peoplelistactivity_clicking-cs-LC6" class="blob-code blob-code-inner js-file-line">
</td>
</tr>
<tr>
<td id="file-peoplelistactivity_clicking-cs-L7" class="blob-num js-line-number js-blob-rnum" data-line-number="7"></td>
<td id="file-peoplelistactivity_clicking-cs-LC7" class="blob-code blob-code-inner js-file-line">      var intent = new Intent(Intent.ActionDial, uri);</td>
</tr>
<tr>
<td id="file-peoplelistactivity_clicking-cs-L8" class="blob-num js-line-number js-blob-rnum" data-line-number="8"></td>
<td id="file-peoplelistactivity_clicking-cs-LC8" class="blob-code blob-code-inner js-file-line">
</td>
</tr>
<tr>
<td id="file-peoplelistactivity_clicking-cs-L9" class="blob-num js-line-number js-blob-rnum" data-line-number="9"></td>
<td id="file-peoplelistactivity_clicking-cs-LC9" class="blob-code blob-code-inner js-file-line">      StartActivity(intent);</td>
</tr>
<tr>
<td id="file-peoplelistactivity_clicking-cs-L10" class="blob-num js-line-number js-blob-rnum" data-line-number="10"></td>
<td id="file-peoplelistactivity_clicking-cs-LC10" class="blob-code blob-code-inner js-file-line">  }</td>
</tr>
</table>
</div></div>
</p></div>
</div></div>
<div class="gist-meta">
        <a href="https://gist.github.com/dsibinski/c5e4309e60888a66284df0dede98d877/raw/b0078b3ff7fe9656c97da6127f3e4e8310e552e7/PeopleListActivity_clicking.cs" style="float:right" class="Link--inTextBlock">view raw</a><br />
        <a href="https://gist.github.com/dsibinski/c5e4309e60888a66284df0dede98d877#file-peoplelistactivity_clicking-cs" class="Link--inTextBlock"><br />
          PeopleListActivity_clicking.cs<br />
        </a><br />
        hosted with &#10084; by <a class="Link--inTextBlock" href="https://github.com">GitHub</a>
      </div>
</p></div>
</div>
<p>What those 4 lines of code do, is when tapping an entry from the list:</p>
<figure id="attachment_1589" aria-describedby="caption-attachment-1589" style="width: 240px" class="wp-caption aligncenter"><img data-recalc-dims="1" loading="lazy" decoding="async" data-attachment-id="1589" data-permalink="https://www.codejourney.net/xamarin-android-intents/monayback_listofpeople/" data-orig-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/MonayBack_ListOfPeople.png?fit=768%2C1280&amp;ssl=1" data-orig-size="768,1280" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="MonayBack_ListOfPeople" data-image-description="" data-image-caption="" data-large-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/MonayBack_ListOfPeople.png?fit=614%2C1024&amp;ssl=1" class=" wp-image-1589 aligncenter" src="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/MonayBack_ListOfPeople.png?resize=240%2C400&#038;ssl=1" alt="MonayBack_ListOfPeople" width="240" height="400" srcset="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/MonayBack_ListOfPeople.png?w=768&amp;ssl=1 768w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/MonayBack_ListOfPeople.png?resize=180%2C300&amp;ssl=1 180w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/MonayBack_ListOfPeople.png?resize=614%2C1024&amp;ssl=1 614w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/MonayBack_ListOfPeople.png?resize=720%2C1200&amp;ssl=1 720w" sizes="auto, (max-width: 240px) 100vw, 240px" /><figcaption id="caption-attachment-1589" class="wp-caption-text">MoneyBack &#8211; people list Activity</figcaption></figure>
<p>it opens the phone dialer app with selected person&#8217;s phone number to call:</p>
<figure id="attachment_1594" aria-describedby="caption-attachment-1594" style="width: 242px" class="wp-caption aligncenter"><img data-recalc-dims="1" loading="lazy" decoding="async" data-attachment-id="1594" data-permalink="https://www.codejourney.net/xamarin-android-intents/moneyback_phonedialercall/" data-orig-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/MoneyBack_phoneDialerCall.png?fit=768%2C1280&amp;ssl=1" data-orig-size="768,1280" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="MoneyBack_phoneDialerCall" data-image-description="" data-image-caption="" data-large-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/MoneyBack_phoneDialerCall.png?fit=614%2C1024&amp;ssl=1" class=" wp-image-1594 aligncenter" src="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/MoneyBack_phoneDialerCall.png?resize=242%2C403&#038;ssl=1" alt="MoneyBack_phoneDialerCall.png" width="242" height="403" srcset="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/MoneyBack_phoneDialerCall.png?w=768&amp;ssl=1 768w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/MoneyBack_phoneDialerCall.png?resize=180%2C300&amp;ssl=1 180w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/MoneyBack_phoneDialerCall.png?resize=614%2C1024&amp;ssl=1 614w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/MoneyBack_phoneDialerCall.png?resize=720%2C1200&amp;ssl=1 720w" sizes="auto, (max-width: 242px) 100vw, 242px" /><figcaption id="caption-attachment-1594" class="wp-caption-text">Phone Dialer opened</figcaption></figure>
<p><span style="font-size: 10pt;">NOTE: If I had more than one dialer app installed (if the other dialer app has itself registered as receiver for <em>ACTION_DIAL, </em>of course) Android would ask me to choose which app I want to use.</p>
<p></span></p>
<p>How did that happen? First actually interesting line of code is the following one:</p>
<pre><pre class="brush: csharp; title: ; notranslate">var intent = new Intent(Intent.ActionDial, uri);</pre>
<p>It creates a new <em>Intent</em>, giving to it &#8211; as we said in the previous paragraph &#8211; two things:</p>
<ul>
<li><em>what</em> we want to do &#8211; it this case, we set <em>action </em>to <span style="color: #ff9900;">Intent.ActionDial</span>, which corresponds to <a href="https://developer.android.com/reference/android/content/Intent.html#ACTION_DIAL" target="_blank" rel="noopener">ACTION_DIAL</a> Activity Action</li>
<li>operation&#8217;s <em>parameters</em> &#8211; in our case there is just one parameter, which is the phone number in <a href="https://developer.xamarin.com/api/type/Android.Net.Uri/" target="_blank" rel="noopener">URI</a> format</li>
</ul>
<p>For each type of Activity Action you want to trigger, you can find what parameters it needs in <a href="https://developer.android.com/reference/android/content/Intent.html" target="_blank" rel="noopener">official Android Documentation</a>.</p>
<p>In the end, we just need to finally start a new Activity with the <em>Intent</em> we just created:</p>
<pre><pre class="brush: csharp; title: ; notranslate">StartActivity(intent);</pre>
<p>and we&#8217;re all done.</p>
<h2>Intent as a message</h2>
<p>Now, let&#8217;s think about our app as a set of Activities, which are <em>loosly-coopled</em>. We have <span style="color: #ff9900;">MainActivity</span> class, which represents the main screen of our app. We&#8217;ve also built another Activity, which we want to open from the main one. In that case, we already see everything which fits into intent-as-a-message template &#8211; two Activities want to &#8220;talk&#8221; with each other.</p>
<p>In <em>MoneyBack</em> I changed the <span style="color: #ff9900;">MainActivity</span> to look as follows:</p>
<figure id="attachment_1624" aria-describedby="caption-attachment-1624" style="width: 223px" class="wp-caption aligncenter"><img data-recalc-dims="1" loading="lazy" decoding="async" data-attachment-id="1624" data-permalink="https://www.codejourney.net/xamarin-android-intents/moneyback_mainactivity/" data-orig-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/MoneyBack_MainActivity.png?fit=768%2C1280&amp;ssl=1" data-orig-size="768,1280" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="MoneyBack_MainActivity" data-image-description="" data-image-caption="" data-large-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/MoneyBack_MainActivity.png?fit=614%2C1024&amp;ssl=1" class=" wp-image-1624 aligncenter" src="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/MoneyBack_MainActivity.png?resize=223%2C371&#038;ssl=1" alt="MoneyBack_MainActivity.png" width="223" height="371" srcset="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/MoneyBack_MainActivity.png?w=768&amp;ssl=1 768w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/MoneyBack_MainActivity.png?resize=180%2C300&amp;ssl=1 180w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/MoneyBack_MainActivity.png?resize=614%2C1024&amp;ssl=1 614w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/MoneyBack_MainActivity.png?resize=720%2C1200&amp;ssl=1 720w" sizes="auto, (max-width: 223px) 100vw, 223px" /><figcaption id="caption-attachment-1624" class="wp-caption-text">MoneyBack &#8211; <em>MainActivity</em></figcaption></figure>
<p>When clicking on &#8220;People Management&#8221; button, I&#8217;d like another Activity (represented by <span style="color: #ff9900;">PeopleActivity</span> class) to open.</p>
<p>In order to achieve that, <em>MoneyBack</em> executes the following code when clicking on the button:</p>
<p><style>.gist table { margin-bottom: 0; }</style>
<div style="tab-size: 8" id="gist46271232" class="gist">
<div class="gist-file" translate="no" data-color-mode="light" data-light-theme="light">
<div class="gist-data">
<div class="js-gist-file-update-container js-task-list-container">
<div id="file-mainactivity_peoplemanagementclick-cs" class="file my-2">
<div itemprop="text"
      class="Box-body p-0 blob-wrapper data type-c  "
      style="overflow: auto" tabindex="0" role="region"
      aria-label="MainActivity_peopleManagementClick.cs content, created by dsibinski on 09:28AM on April 01, 2017."
    ></p>
<div class="js-check-hidden-unicode js-blob-code-container blob-code-content">
<p>  <template class="js-file-alert-template"></p>
<div data-view-component="true" class="flash flash-warn flash-full d-flex flex-items-center">
  <svg aria-hidden="true" data-component="Octicon" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-alert">
    <path d="M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"></path>
</svg><br />
    <span><br />
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.<br />
      <a class="Link--inTextBlock" href="https://github.co/hiddenchars" target="_blank">Learn more about bidirectional Unicode characters</a><br />
    </span></p>
<div data-view-component="true" class="flash-action">        <a href="{{ revealButtonHref }}" data-view-component="true" class="btn-sm btn">    Show hidden characters<br />
</a>
</div>
</div>
<p></template><br />
<template class="js-line-alert-template"><br />
  <span aria-label="This line has hidden Unicode characters" data-view-component="true" class="line-alert tooltipped tooltipped-e"><br />
    <svg aria-hidden="true" data-component="Octicon" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-alert">
    <path d="M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"></path>
</svg><br />
</span></template></p>
<table data-hpc class="highlight tab-size js-file-line-container" data-tab-size="4" data-paste-markdown-skip data-tagsearch-path="MainActivity_peopleManagementClick.cs">
<tr>
<td id="file-mainactivity_peoplemanagementclick-cs-L1" class="blob-num js-line-number js-blob-rnum" data-line-number="1"></td>
<td id="file-mainactivity_peoplemanagementclick-cs-LC1" class="blob-code blob-code-inner js-file-line">  private void _btnPeople_Click(object sender, EventArgs e)</td>
</tr>
<tr>
<td id="file-mainactivity_peoplemanagementclick-cs-L2" class="blob-num js-line-number js-blob-rnum" data-line-number="2"></td>
<td id="file-mainactivity_peoplemanagementclick-cs-LC2" class="blob-code blob-code-inner js-file-line">  {</td>
</tr>
<tr>
<td id="file-mainactivity_peoplemanagementclick-cs-L3" class="blob-num js-line-number js-blob-rnum" data-line-number="3"></td>
<td id="file-mainactivity_peoplemanagementclick-cs-LC3" class="blob-code blob-code-inner js-file-line">      var intent = new Intent(this, typeof(PeopleActivity));</td>
</tr>
<tr>
<td id="file-mainactivity_peoplemanagementclick-cs-L4" class="blob-num js-line-number js-blob-rnum" data-line-number="4"></td>
<td id="file-mainactivity_peoplemanagementclick-cs-LC4" class="blob-code blob-code-inner js-file-line">      StartActivity(intent);</td>
</tr>
<tr>
<td id="file-mainactivity_peoplemanagementclick-cs-L5" class="blob-num js-line-number js-blob-rnum" data-line-number="5"></td>
<td id="file-mainactivity_peoplemanagementclick-cs-LC5" class="blob-code blob-code-inner js-file-line">  }</td>
</tr>
</table>
</div></div>
</p></div>
</div></div>
<div class="gist-meta">
        <a href="https://gist.github.com/dsibinski/87ace30937c460184ccb36d59919727c/raw/ce3100662ce3e8a8746a713fed52ca9b7940fc46/MainActivity_peopleManagementClick.cs" style="float:right" class="Link--inTextBlock">view raw</a><br />
        <a href="https://gist.github.com/dsibinski/87ace30937c460184ccb36d59919727c#file-mainactivity_peoplemanagementclick-cs" class="Link--inTextBlock"><br />
          MainActivity_peopleManagementClick.cs<br />
        </a><br />
        hosted with &#10084; by <a class="Link--inTextBlock" href="https://github.com">GitHub</a>
      </div>
</p></div>
</div>
<p>What you can see here, is that we create a new <em>Intent</em> that takes two parameters:</p>
<ul>
<li><em>Context </em>&#8211; being the class storing information about current application&#8217;s/Activity&#8217;s state, from the place where the <em>Intent</em> is created; in our case, we set it to <span style="color: #ff9900;">this</span>, which is the calling Activity class reference. Context is our message&#8217;s <strong>sender</strong></li>
<li><em>Type</em> &#8211; this is our message&#8217;s <strong>recipient</strong>; in our case it&#8217;s the <span style="color: #ff9900;">Type</span> of destination Activity we want to start (<span style="color: #ff9900;">PeopleActivity</span>)</li>
</ul>
<p><span style="font-size: 10pt;">NOTE: Notice that we have no <em>content</em> provided in that case.</p>
<p></span></p>
<p>Then we just start the Activity as in the previous example and another screen appears:</p>
<figure id="attachment_1645" aria-describedby="caption-attachment-1645" style="width: 217px" class="wp-caption aligncenter"><img data-recalc-dims="1" loading="lazy" decoding="async" data-attachment-id="1645" data-permalink="https://www.codejourney.net/xamarin-android-intents/moneyback_peopleactivity/" data-orig-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/MoneyBack_PeopleActivity.png?fit=768%2C1280&amp;ssl=1" data-orig-size="768,1280" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="MoneyBack_PeopleActivity" data-image-description="" data-image-caption="" data-large-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/MoneyBack_PeopleActivity.png?fit=614%2C1024&amp;ssl=1" class=" wp-image-1645 aligncenter" src="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/MoneyBack_PeopleActivity.png?resize=217%2C362&#038;ssl=1" alt="MoneyBack_PeopleActivity.png" width="217" height="362" srcset="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/MoneyBack_PeopleActivity.png?w=768&amp;ssl=1 768w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/MoneyBack_PeopleActivity.png?resize=180%2C300&amp;ssl=1 180w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/MoneyBack_PeopleActivity.png?resize=614%2C1024&amp;ssl=1 614w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/MoneyBack_PeopleActivity.png?resize=720%2C1200&amp;ssl=1 720w" sizes="auto, (max-width: 217px) 100vw, 217px" /><figcaption id="caption-attachment-1645" class="wp-caption-text">MoneyBack &#8211; PeopleActivity</figcaption></figure>
<p>If the back button is now pressed, it goes back to previous (calling) Activity. That&#8217;s how the Activities stack is built, by the way <img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f609.png" alt="😉" class="wp-smiley" style="height: 1em; max-height: 1em;" /></p>
<h4>Passing additional content using Intent as a message</h4>
<p>I mentioned we can also pass some additional data (message&#8217;s <strong>content</strong>) within an <em>Intent</em>. In the above example we didn&#8217;t do it, because there is no sense to pass anything from <span style="color: #ff9900;">MainActivity</span> to <span style="color: #ff9900;">PeopleActivity</span> for now. However, if we&#8217;d like to do that, we can add a simple modification to button&#8217;s pressing code in <span style="color: #ff9900;">MainActivity</span>:</p>
<p><style>.gist table { margin-bottom: 0; }</style>
<div style="tab-size: 8" id="gist46271394" class="gist">
<div class="gist-file" translate="no" data-color-mode="light" data-light-theme="light">
<div class="gist-data">
<div class="js-gist-file-update-container js-task-list-container">
<div id="file-mainactivity_peoplemanagementclick_msg-cs" class="file my-2">
<div itemprop="text"
      class="Box-body p-0 blob-wrapper data type-c  "
      style="overflow: auto" tabindex="0" role="region"
      aria-label="MainActivity_peopleManagementClick_msg.cs content, created by dsibinski on 09:39AM on April 01, 2017."
    ></p>
<div class="js-check-hidden-unicode js-blob-code-container blob-code-content">
<p>  <template class="js-file-alert-template"></p>
<div data-view-component="true" class="flash flash-warn flash-full d-flex flex-items-center">
  <svg aria-hidden="true" data-component="Octicon" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-alert">
    <path d="M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"></path>
</svg><br />
    <span><br />
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.<br />
      <a class="Link--inTextBlock" href="https://github.co/hiddenchars" target="_blank">Learn more about bidirectional Unicode characters</a><br />
    </span></p>
<div data-view-component="true" class="flash-action">        <a href="{{ revealButtonHref }}" data-view-component="true" class="btn-sm btn">    Show hidden characters<br />
</a>
</div>
</div>
<p></template><br />
<template class="js-line-alert-template"><br />
  <span aria-label="This line has hidden Unicode characters" data-view-component="true" class="line-alert tooltipped tooltipped-e"><br />
    <svg aria-hidden="true" data-component="Octicon" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-alert">
    <path d="M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"></path>
</svg><br />
</span></template></p>
<table data-hpc class="highlight tab-size js-file-line-container" data-tab-size="4" data-paste-markdown-skip data-tagsearch-path="MainActivity_peopleManagementClick_msg.cs">
<tr>
<td id="file-mainactivity_peoplemanagementclick_msg-cs-L1" class="blob-num js-line-number js-blob-rnum" data-line-number="1"></td>
<td id="file-mainactivity_peoplemanagementclick_msg-cs-LC1" class="blob-code blob-code-inner js-file-line">  private void _btnPeople_Click(object sender, EventArgs e)</td>
</tr>
<tr>
<td id="file-mainactivity_peoplemanagementclick_msg-cs-L2" class="blob-num js-line-number js-blob-rnum" data-line-number="2"></td>
<td id="file-mainactivity_peoplemanagementclick_msg-cs-LC2" class="blob-code blob-code-inner js-file-line">  {</td>
</tr>
<tr>
<td id="file-mainactivity_peoplemanagementclick_msg-cs-L3" class="blob-num js-line-number js-blob-rnum" data-line-number="3"></td>
<td id="file-mainactivity_peoplemanagementclick_msg-cs-LC3" class="blob-code blob-code-inner js-file-line">      var intent = new Intent(this, typeof(PeopleActivity));</td>
</tr>
<tr>
<td id="file-mainactivity_peoplemanagementclick_msg-cs-L4" class="blob-num js-line-number js-blob-rnum" data-line-number="4"></td>
<td id="file-mainactivity_peoplemanagementclick_msg-cs-LC4" class="blob-code blob-code-inner js-file-line">
</td>
</tr>
<tr>
<td id="file-mainactivity_peoplemanagementclick_msg-cs-L5" class="blob-num js-line-number js-blob-rnum" data-line-number="5"></td>
<td id="file-mainactivity_peoplemanagementclick_msg-cs-LC5" class="blob-code blob-code-inner js-file-line">      var msgContent = &quot;Hello! This is a secret sent from MainActivity! Don&#39;t tell anyone!&quot;;</td>
</tr>
<tr>
<td id="file-mainactivity_peoplemanagementclick_msg-cs-L6" class="blob-num js-line-number js-blob-rnum" data-line-number="6"></td>
<td id="file-mainactivity_peoplemanagementclick_msg-cs-LC6" class="blob-code blob-code-inner js-file-line">      intent.PutExtra(&quot;secret_message&quot;, msgContent);</td>
</tr>
<tr>
<td id="file-mainactivity_peoplemanagementclick_msg-cs-L7" class="blob-num js-line-number js-blob-rnum" data-line-number="7"></td>
<td id="file-mainactivity_peoplemanagementclick_msg-cs-LC7" class="blob-code blob-code-inner js-file-line">
</td>
</tr>
<tr>
<td id="file-mainactivity_peoplemanagementclick_msg-cs-L8" class="blob-num js-line-number js-blob-rnum" data-line-number="8"></td>
<td id="file-mainactivity_peoplemanagementclick_msg-cs-LC8" class="blob-code blob-code-inner js-file-line">      StartActivity(intent);</td>
</tr>
<tr>
<td id="file-mainactivity_peoplemanagementclick_msg-cs-L9" class="blob-num js-line-number js-blob-rnum" data-line-number="9"></td>
<td id="file-mainactivity_peoplemanagementclick_msg-cs-LC9" class="blob-code blob-code-inner js-file-line">  }</td>
</tr>
</table>
</div></div>
</p></div>
</div></div>
<div class="gist-meta">
        <a href="https://gist.github.com/dsibinski/c41976d7f7873ab870f1a41fc0b9540c/raw/e3cbbe0505a984c152a7646452e374cd15ccb451/MainActivity_peopleManagementClick_msg.cs" style="float:right" class="Link--inTextBlock">view raw</a><br />
        <a href="https://gist.github.com/dsibinski/c41976d7f7873ab870f1a41fc0b9540c#file-mainactivity_peoplemanagementclick_msg-cs" class="Link--inTextBlock"><br />
          MainActivity_peopleManagementClick_msg.cs<br />
        </a><br />
        hosted with &#10084; by <a class="Link--inTextBlock" href="https://github.com">GitHub</a>
      </div>
</p></div>
</div>
<p>As you see, I used <span style="color: #ff9900;">PutExtra</span> method of the <span style="color: #ff9900;">Intent </span>class to insert <span style="color: #ff9900;"><em>msgContent</em></span> into Intent&#8217;s simple key-value Bundle Dictionary called <em>Extras, </em>using &#8220;secret_message&#8221; string as a key. Then, in the destination Activity&#8217;s <span style="color: #ff9900;">OnCreate</span> method we can retrieve such value back using <span style="color: #ff9900;">Intent.Extras.GetString</span> (for <span style="color: #ff9900;">String</span> data type) method:</p>
<p><img data-recalc-dims="1" loading="lazy" decoding="async" data-attachment-id="1670" data-permalink="https://www.codejourney.net/xamarin-android-intents/moneyback_intentextrasretrieve/" data-orig-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/MoneyBack_IntentExtrasRetrieve.png?fit=975%2C504&amp;ssl=1" data-orig-size="975,504" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="MoneyBack_IntentExtrasRetrieve" data-image-description="" data-image-caption="" data-large-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/MoneyBack_IntentExtrasRetrieve.png?fit=975%2C504&amp;ssl=1" class=" wp-image-1670 aligncenter" src="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/MoneyBack_IntentExtrasRetrieve.png?resize=584%2C302&#038;ssl=1" alt="MoneyBack_IntentExtrasRetrieve.PNG" width="584" height="302" srcset="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/MoneyBack_IntentExtrasRetrieve.png?w=975&amp;ssl=1 975w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/MoneyBack_IntentExtrasRetrieve.png?resize=300%2C155&amp;ssl=1 300w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/MoneyBack_IntentExtrasRetrieve.png?resize=768%2C397&amp;ssl=1 768w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/04/MoneyBack_IntentExtrasRetrieve.png?resize=720%2C372&amp;ssl=1 720w" sizes="auto, (max-width: 584px) 100vw, 584px" /></p>
<p>This kind of data-passing between Activities using <span style="color: #ff9900;">Intent.Extras</span> should be used only for simple, mostly key-value data transferring. There are other methods for passing/storing more complex data in an app or between different applications.</p>
<h2>Summary</h2>
<p>Today we&#8217;ve seen what is an <em>Intent</em>, how to use it to trigger external actions such as calling a phone number, sending email etc., but also how to use it to handle navigation between Activities. We&#8217;ve also passed key-value data between two Activities using <span style="color: #ff9900;">Intent.Extras</span>.</p>
<p><em>Intent</em>, as well as <a href="https://www.codejourney.net/2017/03/xamarin-android-activities/" target="_blank" rel="noopener">Activity</a>, is one of the fundamental concepts of Android. It&#8217;s essential to know how <em>Intents</em> work, how they relate to <em>Activities</em>, <em>Services</em> (which we&#8217;ll also cover one day) and <em>Application Blocks.  </em>I hope you&#8217;ll find it useful <img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f609.png" alt="😉" class="wp-smiley" style="height: 1em; max-height: 1em;" /></p>
<p>The post <a href="https://www.codejourney.net/xamarin-android-intents/">Xamarin &#8211; Android Intents</a> appeared first on <a href="https://www.codejourney.net">CodeJourney.net</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.codejourney.net/xamarin-android-intents/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1499</post-id>	</item>
		<item>
		<title>My list of must-have apps</title>
		<link>https://www.codejourney.net/my-list-of-must-have-apps/</link>
					<comments>https://www.codejourney.net/my-list-of-must-have-apps/#comments</comments>
		
		<dc:creator><![CDATA[Dawid Sibiński]]></dc:creator>
		<pubDate>Sun, 26 Mar 2017 17:33:52 +0000</pubDate>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[dajsiepoznac2017]]></category>
		<guid isPermaLink="false">http://www.dsibinski.pl/?p=1364</guid>

					<description><![CDATA[<p>In this post I&#8217;d like to share with you a few applications I use (both mobile and PC ones) that are must-haves for me. Maybe you&#8217;ll find some of them useful (if you&#8217;re not using them yet). You can click on each application&#8217;s logo to go to its homepage. Windows PC apps Evernote Evernote allows to&#8230;</p>
<p>The post <a href="https://www.codejourney.net/my-list-of-must-have-apps/">My list of must-have apps</a> appeared first on <a href="https://www.codejourney.net">CodeJourney.net</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>In this post I&#8217;d like to share with you a few applications I use (both mobile and PC ones) that are must-haves for me. Maybe you&#8217;ll find some of them useful (if you&#8217;re not using them yet). You can click on each application&#8217;s logo to go to its homepage.<br />
<span id="more-1364"></span></p>
<h2><span style="text-decoration: underline;">Windows PC apps</span></h2>
<h3>Evernote</h3>
<h3><a href="https://evernote.com" target="_blank" rel="noopener"><img data-recalc-dims="1" loading="lazy" decoding="async" data-attachment-id="1375" data-permalink="https://www.codejourney.net/my-list-of-must-have-apps/evernote-logo-vector/" data-orig-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/evernote-logo-vector.png?fit=400%2C400&amp;ssl=1" data-orig-size="400,400" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="evernote-logo-vector" data-image-description="" data-image-caption="" data-large-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/evernote-logo-vector.png?fit=400%2C400&amp;ssl=1" class="alignnone wp-image-1375" src="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/evernote-logo-vector.png?resize=123%2C123&#038;ssl=1" alt="evernote-logo-vector" width="123" height="123" srcset="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/evernote-logo-vector.png?w=400&amp;ssl=1 400w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/evernote-logo-vector.png?resize=150%2C150&amp;ssl=1 150w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/evernote-logo-vector.png?resize=300%2C300&amp;ssl=1 300w" sizes="auto, (max-width: 123px) 100vw, 123px" /></a></h3>
<p>Evernote allows to store notes and synchronize them across multiple devices. I&#8217;d say it&#8217;s a very good alternative to <em>OneNote</em> used by many people. I prefer it to <em>OneNote</em>, because it&#8217;s simpler.</p>
<p>Saved notes can contain photos, files and be quite rich-formatted. Free basic plan allows to synchronize two devices, which is enough for me. I don&#8217;t use Evernote on my mobile, I only use it for longer notes, e.g. meeting minutes, blog posts drafts/ideas etc. <a href="https://www.codejourney.net/2017/03/simple-habits-for-better-productivity/" target="_blank" rel="noopener">As you may know</a>, I use <em>GoogleKeep</em> for storing short notes or something I need to write down quickly on my mobile phone.</p>
<h3>SublimeText3</h3>
<p><a href="https://www.sublimetext.com/" target="_blank" rel="noopener"><img data-recalc-dims="1" loading="lazy" decoding="async" data-attachment-id="1391" data-permalink="https://www.codejourney.net/my-list-of-must-have-apps/sublime_text_logo/" data-orig-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/Sublime_Text_Logo.png?fit=256%2C256&amp;ssl=1" data-orig-size="256,256" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="Sublime_Text_Logo" data-image-description="" data-image-caption="" data-large-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/Sublime_Text_Logo.png?fit=256%2C256&amp;ssl=1" class="alignnone wp-image-1391" src="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/Sublime_Text_Logo.png?resize=170%2C170&#038;ssl=1" alt="Sublime_Text_Logo.png" width="170" height="170" srcset="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/Sublime_Text_Logo.png?w=256&amp;ssl=1 256w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/Sublime_Text_Logo.png?resize=150%2C150&amp;ssl=1 150w" sizes="auto, (max-width: 170px) 100vw, 170px" /></a></p>
<p>The best and the only right text editor ever. I started using Sublime around 2 years ago and today I can&#8217;t imagine my life without it. Even though I almost don&#8217;t write code in Sublime, I just love it. It&#8217;s very fast and intuitive. Syntax highlighting, text selection and finding text/regex features are fabulous. Nothing to add. Just install and use it.</p>
<h3>Total Commander</h3>
<p><a href="https://www.ghisler.com/" target="_blank" rel="noopener"><img data-recalc-dims="1" loading="lazy" decoding="async" data-attachment-id="1401" data-permalink="https://www.codejourney.net/my-list-of-must-have-apps/512px-total_commander_logo-svg/" data-orig-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/512px-Total_Commander_logo.svg_.png?fit=512%2C512&amp;ssl=1" data-orig-size="512,512" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="512px-Total_Commander_logo.svg" data-image-description="" data-image-caption="" data-large-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/512px-Total_Commander_logo.svg_.png?fit=512%2C512&amp;ssl=1" class="alignnone wp-image-1401" src="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/512px-Total_Commander_logo.svg_.png?resize=145%2C145&#038;ssl=1" alt="512px-Total_Commander_logo.svg.png" width="145" height="145" srcset="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/512px-Total_Commander_logo.svg_.png?w=512&amp;ssl=1 512w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/512px-Total_Commander_logo.svg_.png?resize=150%2C150&amp;ssl=1 150w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/512px-Total_Commander_logo.svg_.png?resize=300%2C300&amp;ssl=1 300w" sizes="auto, (max-width: 145px) 100vw, 145px" /></a></p>
<p>Actually, I should&#8217;ve started from TC. This is absolutely essential part of any files exploring I do on Windows. I&#8217;ve already been using it for around 1.5 years, couldn&#8217;t get used to it for a long time, but believe me &#8211; it&#8217;s definitely worth it. It really increases productivity when working with files copying, changing extensions, transferring files between FTP servers, basically anything that requires operations on files or folders. It may take you some time to learn it, but you&#8217;ll be pleased after <img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f642.png" alt="🙂" class="wp-smiley" style="height: 1em; max-height: 1em;" /> and never willing to use Windows Explorer again.</p>
<h3>Greenshot</h3>
<p><a href="http://getgreenshot.org/" target="_blank" rel="noopener"><img data-recalc-dims="1" loading="lazy" decoding="async" data-attachment-id="1412" data-permalink="https://www.codejourney.net/my-list-of-must-have-apps/greenshot_logo/" data-orig-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/greenshot_logo.png?fit=127%2C127&amp;ssl=1" data-orig-size="127,127" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="greenshot_logo" data-image-description="" data-image-caption="" data-large-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/greenshot_logo.png?fit=127%2C127&amp;ssl=1" class="alignnone size-full wp-image-1412" src="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/greenshot_logo.png?resize=127%2C127&#038;ssl=1" alt="greenshot_logo.png" width="127" height="127" /></a></p>
<p>Greenshot is a screenshot-making application. If you need to make a screenshot more than once per week, than it&#8217;s really helpful. It can be integrated into your Print Screen button, allowing to quickly open the screenshot made in image editor in which you can highlight some parts of the screenshot or easily put consecutive numbers (e.g. to present the orders of actions performed):</p>
<figure id="attachment_media-10" aria-describedby="caption-attachment-media-10" style="width: 714px" class="wp-caption alignnone"><img data-recalc-dims="1" loading="lazy" decoding="async" data-attachment-id="1416" data-permalink="https://www.codejourney.net/my-list-of-must-have-apps/greenshot_example/" data-orig-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/greenshot_example.jpg?fit=714%2C521&amp;ssl=1" data-orig-size="714,521" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;Dawid Sibi\u0144ski&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;1490553234&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="greenshot_example" data-image-description="" data-image-caption="" data-large-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/greenshot_example.jpg?fit=714%2C521&amp;ssl=1" class="alignnone size-full wp-image-1416" src="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/greenshot_example.jpg?resize=714%2C521&#038;ssl=1" alt="greenshot_example.JPG" width="714" height="521" srcset="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/greenshot_example.jpg?w=714&amp;ssl=1 714w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/greenshot_example.jpg?resize=300%2C219&amp;ssl=1 300w" sizes="auto, (max-width: 714px) 100vw, 714px" /><figcaption id="caption-attachment-media-10" class="wp-caption-text">Greenshot&#8217;s screenshot editor</figcaption></figure>
<h3>Nozbe</h3>
<p><a href="https://nozbe.com/" target="_blank" rel="noopener"><img data-recalc-dims="1" loading="lazy" decoding="async" data-attachment-id="1423" data-permalink="https://www.codejourney.net/my-list-of-must-have-apps/nozbe/" data-orig-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/Nozbe.png?fit=256%2C256&amp;ssl=1" data-orig-size="256,256" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="Nozbe" data-image-description="" data-image-caption="" data-large-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/Nozbe.png?fit=256%2C256&amp;ssl=1" class="alignnone wp-image-1423" src="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/Nozbe.png?resize=142%2C142&#038;ssl=1" alt="Nozbe.png" width="142" height="142" srcset="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/Nozbe.png?w=256&amp;ssl=1 256w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/Nozbe.png?resize=150%2C150&amp;ssl=1 150w" sizes="auto, (max-width: 142px) 100vw, 142px" /></a></p>
<p>Nozbe allows to store tasks, group them into projects, set their deadlines etc. You can read more about it in <a href="https://www.codejourney.net/2017/03/simple-habits-for-better-productivity/" target="_blank" rel="noopener">my recent post about productivity</a>. Its desktop client is very useful, especially providing keyboard shortcut (<em>Ctrl+Shift+Space</em> by default) for quick tasks adding.</p>
<h3>F.lux</h3>
<p><a href="https://justgetflux.com/" target="_blank" rel="noopener"><img data-recalc-dims="1" loading="lazy" decoding="async" data-attachment-id="1483" data-permalink="https://www.codejourney.net/my-list-of-must-have-apps/flux-logo-lg/" data-orig-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/flux-logo-lg.png?fit=291%2C128&amp;ssl=1" data-orig-size="291,128" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="flux-logo-lg" data-image-description="" data-image-caption="" data-large-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/flux-logo-lg.png?fit=291%2C128&amp;ssl=1" class="alignnone size-full wp-image-1483" src="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/flux-logo-lg.png?resize=221%2C97&#038;ssl=1" alt="flux-logo-lg.png" width="221" height="97" /></a></p>
<p>F.lux adjusts the temperature of your screen&#8217;s (or screens&#8217;) colors with the sky colors changes. Incredibly useful when working with few monitors for many hours, especially at night when it gets darker. For me, it lets my eyes rest and prevent headaches I often used to have before installing F.lux.</p>
<h2><span style="text-decoration: underline;">Android apps</span></h2>
<h3>CamScanner</h3>
<p><a href="https://www.camscanner.com/" target="_blank" rel="noopener"><img data-recalc-dims="1" loading="lazy" decoding="async" data-attachment-id="1428" data-permalink="https://www.codejourney.net/my-list-of-must-have-apps/camscanner-logo/" data-orig-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/CamScanner-Logo.png?fit=1024%2C1024&amp;ssl=1" data-orig-size="1024,1024" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="CamScanner-Logo" data-image-description="" data-image-caption="" data-large-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/CamScanner-Logo.png?fit=1024%2C1024&amp;ssl=1" class="alignnone wp-image-1428" src="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/CamScanner-Logo.png?resize=155%2C155&#038;ssl=1" alt="CamScanner-Logo.png" width="155" height="155" srcset="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/CamScanner-Logo.png?w=1024&amp;ssl=1 1024w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/CamScanner-Logo.png?resize=150%2C150&amp;ssl=1 150w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/CamScanner-Logo.png?resize=300%2C300&amp;ssl=1 300w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/CamScanner-Logo.png?resize=768%2C768&amp;ssl=1 768w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/CamScanner-Logo.png?resize=720%2C720&amp;ssl=1 720w" sizes="auto, (max-width: 155px) 100vw, 155px" /></a></p>
<p>This one I also described in <a href="https://www.codejourney.net/2017/03/simple-habits-for-better-productivity/" target="_blank" rel="noopener">my last post, in which I proposed few simple habits you can introduce into your everyday life to make your productivity better</a>. CamScanner is a must-have for me, it allows to make a photo of a document using mobile phone&#8217;s camera, then it automatically detects the document&#8217;s edges, cuts the image (you can adjust it if needed) and transforms it into scanned-looking JPEG/PDF. Since I started using CamScanner, I don&#8217;t remember using my printer&#8217;s scanner anymore. Scans produced using the app look good even if the picture is done in low-light conditions.</p>
<h3>AirDroid</h3>
<p><a href="https://www.airdroid.com/" target="_blank" rel="noopener"><img data-recalc-dims="1" loading="lazy" decoding="async" data-attachment-id="1438" data-permalink="https://www.codejourney.net/my-list-of-must-have-apps/airdroid/" data-orig-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/airdroid.jpg?fit=391%2C373&amp;ssl=1" data-orig-size="391,373" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="airdroid" data-image-description="" data-image-caption="" data-large-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/airdroid.jpg?fit=391%2C373&amp;ssl=1" class="alignnone wp-image-1438" src="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/airdroid.jpg?resize=178%2C170&#038;ssl=1" alt="airdroid.jpg" width="178" height="170" srcset="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/airdroid.jpg?w=391&amp;ssl=1 391w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/airdroid.jpg?resize=300%2C286&amp;ssl=1 300w" sizes="auto, (max-width: 178px) 100vw, 178px" /></a></p>
<p>AirDroid allows you to wirelessly connect your smartphone to any PC being in the same WiFi network. You open <a href="http://web.airdroid.com/" target="_blank" rel="noopener">the web app</a> on your PC, open mobile app, scan QR code and you&#8217;re all set. Using web interface you can copy files to/from your phone, as well as send SMS messages, explore photos etc. Very handy.</p>
<h3>Listonic</h3>
<p><a href="http://listonic.com" target="_blank" rel="noopener"><img data-recalc-dims="1" loading="lazy" decoding="async" data-attachment-id="1447" data-permalink="https://www.codejourney.net/my-list-of-must-have-apps/listonic_logo/" data-orig-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/listonic_logo.png?fit=300%2C275&amp;ssl=1" data-orig-size="300,275" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="listonic_logo" data-image-description="" data-image-caption="" data-large-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/listonic_logo.png?fit=300%2C275&amp;ssl=1" class="alignnone wp-image-1447" src="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/listonic_logo.png?resize=165%2C151&#038;ssl=1" alt="listonic_logo.png" width="165" height="151" /></a></p>
<p>Listonic is a shopping list app. I use it only for that purpose. I share the shopping lists with my girlfriend, so we always know what to buy or what has already been bought by one of us. The only drawback I noticed recently in its Android version is that the app launches a bit long (3-4 seconds) which may be annoying sometimes. Apart from that, I can recommend it as shopping helper.</p>
<h3><strong>Podcast Addict</strong></h3>
<p><a href="https://play.google.com/store/apps/details?id=com.bambuna.podcastaddict&amp;hl=en" target="_blank" rel="noopener"><img data-recalc-dims="1" loading="lazy" decoding="async" data-attachment-id="1454" data-permalink="https://www.codejourney.net/my-list-of-must-have-apps/podcastaddict/" data-orig-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/podcastAddict.png?fit=1024%2C500&amp;ssl=1" data-orig-size="1024,500" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="podcastAddict" data-image-description="" data-image-caption="" data-large-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/podcastAddict.png?fit=1024%2C500&amp;ssl=1" class="alignnone wp-image-1454" src="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/podcastAddict.png?resize=164%2C80&#038;ssl=1" alt="podcastAddict.png" width="164" height="80" srcset="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/podcastAddict.png?w=1024&amp;ssl=1 1024w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/podcastAddict.png?resize=300%2C146&amp;ssl=1 300w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/podcastAddict.png?resize=768%2C375&amp;ssl=1 768w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/podcastAddict.png?resize=720%2C352&amp;ssl=1 720w" sizes="auto, (max-width: 164px) 100vw, 164px" /></a></p>
<p>If you&#8217;re used to (or <em>addicted </em>to) listening podcasts, Podcast Addict will be a perfect app for you. It allows to search for podcast channels and subscribe them (e.g. you can find <a href="http://devtalk.pl" target="_blank" rel="noopener">DevTalk</a> or <a href="http://hanselminutes.com/" target="_blank" rel="noopener">Hanselminutes</a> there). As soon as new episode is published, you can get a notification. What&#8217;s more, you can download each episode when connected to WiFi and then listen it offline.</p>
<h3>Nozbe</h3>
<p><a href="https://nozbe.com/" target="_blank" rel="noopener"><img data-recalc-dims="1" loading="lazy" decoding="async" data-attachment-id="1423" data-permalink="https://www.codejourney.net/my-list-of-must-have-apps/nozbe/" data-orig-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/Nozbe.png?fit=256%2C256&amp;ssl=1" data-orig-size="256,256" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="Nozbe" data-image-description="" data-image-caption="" data-large-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/Nozbe.png?fit=256%2C256&amp;ssl=1" class="alignnone wp-image-1423" src="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/Nozbe.png?resize=142%2C142&#038;ssl=1" alt="Nozbe.png" width="142" height="142" srcset="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/Nozbe.png?w=256&amp;ssl=1 256w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/Nozbe.png?resize=150%2C150&amp;ssl=1 150w" sizes="auto, (max-width: 142px) 100vw, 142px" /></a></p>
<p>I&#8217;ll repeat myself here <img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f642.png" alt="🙂" class="wp-smiley" style="height: 1em; max-height: 1em;" /> Nozbe is also available on most popular mobile platforms, including Android one which I use.  It&#8217;s important to have it installed on the mobile phone, because it comes with notifications panel&#8217;s widget allowing to quickly add a new task:</p>
<figure id="attachment_1468" aria-describedby="caption-attachment-1468" style="width: 338px" class="wp-caption aligncenter"><img data-recalc-dims="1" loading="lazy" decoding="async" data-attachment-id="1468" data-permalink="https://www.codejourney.net/my-list-of-must-have-apps/nozbeandroidquickadding/" data-orig-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/nozbeAndroidQuickAdding.png?fit=1080%2C566&amp;ssl=1" data-orig-size="1080,566" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="nozbeAndroidQuickAdding" data-image-description="" data-image-caption="" data-large-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/nozbeAndroidQuickAdding.png?fit=1024%2C537&amp;ssl=1" class=" wp-image-1468 aligncenter" src="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/nozbeAndroidQuickAdding.png?resize=338%2C177&#038;ssl=1" alt="nozbeAndroidQuickAdding.png" width="338" height="177" srcset="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/nozbeAndroidQuickAdding.png?w=1080&amp;ssl=1 1080w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/nozbeAndroidQuickAdding.png?resize=300%2C157&amp;ssl=1 300w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/nozbeAndroidQuickAdding.png?resize=768%2C402&amp;ssl=1 768w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/nozbeAndroidQuickAdding.png?resize=1024%2C537&amp;ssl=1 1024w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/nozbeAndroidQuickAdding.png?resize=720%2C377&amp;ssl=1 720w" sizes="auto, (max-width: 338px) 100vw, 338px" /><figcaption id="caption-attachment-1468" class="wp-caption-text">Nozbe (Android) widget</figcaption></figure>
<p>May become useful when no PC available to quickly note something down.</p>
<h3>UpNext</h3>
<p><a href="https://play.google.com/store/apps/details?id=cz.simekadam.upnext&amp;hl=en" target="_blank" rel="noopener"><img data-recalc-dims="1" loading="lazy" decoding="async" data-attachment-id="1474" data-permalink="https://www.codejourney.net/my-list-of-must-have-apps/upnextlogo/" data-orig-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/upnextlogo.jpg?fit=176%2C178&amp;ssl=1" data-orig-size="176,178" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;Dawid Sibi\u0144ski&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;1490554988&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="upnextlogo" data-image-description="" data-image-caption="" data-large-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/upnextlogo.jpg?fit=176%2C178&amp;ssl=1" class="alignnone size-full wp-image-1474" src="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/upnextlogo.jpg?resize=142%2C144&#038;ssl=1" alt="upnextlogo.JPG" width="142" height="144" /></a></p>
<p>UpNext allows to add a widget on Android&#8217;s screen, which displays the list of incoming calendar events:</p>
<figure id="attachment_1478" aria-describedby="caption-attachment-1478" style="width: 307px" class="wp-caption aligncenter"><img data-recalc-dims="1" loading="lazy" decoding="async" data-attachment-id="1478" data-permalink="https://www.codejourney.net/my-list-of-must-have-apps/upnextscreenwidget/" data-orig-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/upnextScreenWidget.jpg?fit=474%2C484&amp;ssl=1" data-orig-size="474,484" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;Dawid Sibi\u0144ski&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;1490555133&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="upnextScreenWidget" data-image-description="" data-image-caption="" data-large-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/upnextScreenWidget.jpg?fit=474%2C484&amp;ssl=1" class="aligncenter wp-image-1478" src="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/upnextScreenWidget.jpg?resize=307%2C313&#038;ssl=1" alt="upnextScreenWidget.JPG" width="307" height="313" srcset="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/upnextScreenWidget.jpg?w=474&amp;ssl=1 474w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/upnextScreenWidget.jpg?resize=294%2C300&amp;ssl=1 294w" sizes="auto, (max-width: 307px) 100vw, 307px" /><figcaption id="caption-attachment-1478" class="wp-caption-text">UpNext widget</figcaption></figure>
<p>It&#8217;s very handy for me and I&#8217;m using it all the time. It also allows to easily add new calendar event or open calendar app.</p>
<h2>Summary</h2>
<p>The list I presented contains apps that I use every day and can&#8217;t imagine my computer/mobile life without them. I think they make activities I perform on my PC or smartphone simple and painless. If I find some more must-have apps, I&#8217;ll try to keep this list updated.</p>
<p><span style="text-decoration: underline;"><strong>What are your favourite apps you couldn&#8217;t live without ? Let me know!</strong></span></p>
<p>The post <a href="https://www.codejourney.net/my-list-of-must-have-apps/">My list of must-have apps</a> appeared first on <a href="https://www.codejourney.net">CodeJourney.net</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.codejourney.net/my-list-of-must-have-apps/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1364</post-id>	</item>
		<item>
		<title>Unit Testing Xamarin application</title>
		<link>https://www.codejourney.net/unit-testing-xamarin-application/</link>
					<comments>https://www.codejourney.net/unit-testing-xamarin-application/#respond</comments>
		
		<dc:creator><![CDATA[Dawid Sibiński]]></dc:creator>
		<pubDate>Sat, 25 Mar 2017 23:07:19 +0000</pubDate>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[android]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[dajsiepoznac2017]]></category>
		<category><![CDATA[tests]]></category>
		<category><![CDATA[xamarin]]></category>
		<guid isPermaLink="false">http://www.dsibinski.pl/?p=1166</guid>

					<description><![CDATA[<p>Today we&#8217;ll see how to add unit tests to Xamarin Android application, testing both platform-independent logic and Android-specific features. Issue with unit tests in Visual Studio 2017 When I started to create my data access methods in MoneyBack, I really wanted to start writing even some basic unit tests of that logic. My first trial was to&#8230;</p>
<p>The post <a href="https://www.codejourney.net/unit-testing-xamarin-application/">Unit Testing Xamarin application</a> appeared first on <a href="https://www.codejourney.net">CodeJourney.net</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Today we&#8217;ll see how to add unit tests to Xamarin Android application, testing both platform-independent logic and Android-specific features.<br />
<span id="more-1166"></span></p>
<h2>Issue with unit tests in Visual Studio 2017</h2>
<p>When I started to create my data access methods in <em>MoneyBack</em>, I really wanted to start writing even some basic unit tests of that logic.</p>
<p>My first trial was to add a new project to my solution which contains unit tests. So I checked what kind of projects templates I have available and I I found <strong>Unit Test App (Android) </strong>project template and added it to my solution. Generated project contained <span style="color: #ff6600;"><em>TestsSample</em> </span>class with some unit-looking tests methods, but I had no idea how to execute them. With ReSharper installed, I didn&#8217;t have any &#8220;Run Tests&#8221; option on this project. I read somewhere on the web that this project type is used to execute tests on the device, but I couldn&#8217;t figure out how to do it. I gave up.</p>
<p>Then I found another project template &#8211; <strong>Class Library (Android) with nUnit</strong>. Sounds better, <em>nUnit</em> in the name suggests unit tests, so I added this project to my solution. This time when right-clicking the project I had &#8220;Run Tests&#8221; option, but when clicking on it I got the following exception coming from ReSharper:</p>
<figure id="attachment_1200" aria-describedby="caption-attachment-1200" style="width: 1030px" class="wp-caption aligncenter"><img data-recalc-dims="1" loading="lazy" decoding="async" data-attachment-id="1200" data-permalink="https://www.codejourney.net/unit-testing-xamarin-application/resharper_exc/" data-orig-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/ReSharper_Exc.png?fit=1030%2C829&amp;ssl=1" data-orig-size="1030,829" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="ReSharper_Exc" data-image-description="" data-image-caption="" data-large-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/ReSharper_Exc.png?fit=1024%2C824&amp;ssl=1" class="wp-image-1200 size-full" src="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/ReSharper_Exc.png?resize=1030%2C829&#038;ssl=1" alt="ReSharper_Exc" width="1030" height="829" srcset="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/ReSharper_Exc.png?w=1030&amp;ssl=1 1030w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/ReSharper_Exc.png?resize=300%2C241&amp;ssl=1 300w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/ReSharper_Exc.png?resize=768%2C618&amp;ssl=1 768w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/ReSharper_Exc.png?resize=1024%2C824&amp;ssl=1 1024w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/ReSharper_Exc.png?resize=720%2C579&amp;ssl=1 720w" sizes="auto, (max-width: 1030px) 100vw, 1030px" /><figcaption id="caption-attachment-1200" class="wp-caption-text">ReSharper error when executing unit tests</figcaption></figure>
<p>&#8220;Hmm&#8230; Visual Studio 2017&#8221;, I thought. &#8220;Some bugs for sure&#8221;. And I&#8230;</p>
<p>&#8230; didn&#8217;t give up this time and with some help of folks from StackOverflow I figured out how unit tests should be done in Xamarin app. Let&#8217;s see that in the next chapters.</p>
<h2>Levels of testing Xamarin application</h2>
<p>There are basically three &#8220;levels&#8221; of testing Xamarin apps:</p>
<ol>
<li><strong>Classic unit tests of pure .NET/Mono</strong>
<ul>
<li>standard, good old unit tests of logic independent from targeting platform (Xamarin.Android/iOS/Windows Phone)</li>
<li>unit-testing frameworks can be used (nUnit / xUnit)</li>
</ul>
</li>
<li><strong>Platform-specific tests</strong>
<ul>
<li>unit tests of functionalities specific to targeting platform (e.g. Bluetooth, Location, GPS, SMS etc.)</li>
<li>specific for each platform</li>
<li>don&#8217;t contain GUI tests</li>
<li>executed on the emulator/device</li>
</ul>
</li>
<li><strong>UI tests</strong>
<ul>
<li>tests of UI elements of the app and how those react for input (touch) events</li>
<li>executed by cloud/testing lab services (local or remote)</li>
</ul>
</li>
</ol>
<p>We&#8217;ll dive into the first two, UI tests is more complex topic, which requires setting up tests lab or using cloud testing services. For small projects, in the beginning it&#8217;s not necessary.</p>
<h2>Classic platform-independent unit tests</h2>
<p>In order to simply use ReSharper for executing unit tests of logic, which is independent from Android/iOS/Windows Phone, there is a need to add a new project using template <strong>Unit Test Project (.NET Framework) </strong>to our Xamarin solution.</p>
<p>To such project, you can add your favourite unit-testing framework (such as <em>nUnit</em> or <em>xUnit</em>) by simply installing it from Nuget.  After, ReSharper allows to run your unit tests as in old good times:</p>
<figure id="attachment_1246" aria-describedby="caption-attachment-1246" style="width: 714px" class="wp-caption aligncenter"><img data-recalc-dims="1" loading="lazy" decoding="async" data-attachment-id="1246" data-permalink="https://www.codejourney.net/unit-testing-xamarin-application/tests_rsharper/" data-orig-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/tests_rsharper.png?fit=714%2C149&amp;ssl=1" data-orig-size="714,149" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="tests_rsharper" data-image-description="" data-image-caption="" data-large-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/tests_rsharper.png?fit=714%2C149&amp;ssl=1" class="wp-image-1246 size-full" src="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/tests_rsharper.png?resize=714%2C149&#038;ssl=1" alt="tests_rsharper.PNG" width="714" height="149" srcset="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/tests_rsharper.png?w=714&amp;ssl=1 714w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/tests_rsharper.png?resize=300%2C63&amp;ssl=1 300w" sizes="auto, (max-width: 714px) 100vw, 714px" /><figcaption id="caption-attachment-1246" class="wp-caption-text">nUnit tests executed by ReSharper</figcaption></figure>
<p>The exception I was getting with ReSharper previously was because I added the project using template <em>Class Library (Android) </em>which has its target set to Android device/emulator. ReSharper doesn&#8217;t know about any Android-specific (or Xamarin-specific) testing, so it was displaying unhandled error.</p>
<h2>Platform-specific unit tests</h2>
<p>In order to test platform-specific (in out case Android-specific) functionalities of your application, the tests need targeting runtime environment to run. It means they need to be executed on the physical device or emulator. Providers of the most popular unit-testing frameworks created wrappers for on-device testing. I&#8217;m using <a href="https://github.com/nunit/nunit.xamarin" target="_blank" rel="noopener">NUnit Xamarin Runners</a>.</p>
<p>First of all, a new project should be added to our solution. To make things easier, download <a href="https://marketplace.visualstudio.com/items?itemName=NUnitDevelopers.NUnitTemplatesforVisualStudio" target="_blank" rel="noopener">NUnit Templates for Visual Studio</a> (although it officially supports VS up to 2015, it also works in VS 2017) and install it. After, add new project using appropriate template &#8211; I chose <strong>NUnit 3 Test Project (Android)</strong>. What&#8217;s interesting, the newly created project contains <em><span style="color: #ff6600;">MainActivity</span> </em>class with the following content:</p>
<p><style>.gist table { margin-bottom: 0; }</style>
<div style="tab-size: 8" id="gist46061652" class="gist">
<div class="gist-file" translate="no" data-color-mode="light" data-light-theme="light">
<div class="gist-data">
<div class="js-gist-file-update-container js-task-list-container">
<div id="file-mainactivity_tests-cs" class="file my-2">
<div itemprop="text"
      class="Box-body p-0 blob-wrapper data type-c  "
      style="overflow: auto" tabindex="0" role="region"
      aria-label="MainActivity_Tests.cs content, created by dsibinski on 10:13PM on March 25, 2017."
    ></p>
<div class="js-check-hidden-unicode js-blob-code-container blob-code-content">
<p>  <template class="js-file-alert-template"></p>
<div data-view-component="true" class="flash flash-warn flash-full d-flex flex-items-center">
  <svg aria-hidden="true" data-component="Octicon" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-alert">
    <path d="M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"></path>
</svg><br />
    <span><br />
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.<br />
      <a class="Link--inTextBlock" href="https://github.co/hiddenchars" target="_blank">Learn more about bidirectional Unicode characters</a><br />
    </span></p>
<div data-view-component="true" class="flash-action">        <a href="{{ revealButtonHref }}" data-view-component="true" class="btn-sm btn">    Show hidden characters<br />
</a>
</div>
</div>
<p></template><br />
<template class="js-line-alert-template"><br />
  <span aria-label="This line has hidden Unicode characters" data-view-component="true" class="line-alert tooltipped tooltipped-e"><br />
    <svg aria-hidden="true" data-component="Octicon" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-alert">
    <path d="M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"></path>
</svg><br />
</span></template></p>
<table data-hpc class="highlight tab-size js-file-line-container" data-tab-size="4" data-paste-markdown-skip data-tagsearch-path="MainActivity_Tests.cs">
<tr>
<td id="file-mainactivity_tests-cs-L1" class="blob-num js-line-number js-blob-rnum" data-line-number="1"></td>
<td id="file-mainactivity_tests-cs-LC1" class="blob-code blob-code-inner js-file-line">  public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsApplicationActivity</td>
</tr>
<tr>
<td id="file-mainactivity_tests-cs-L2" class="blob-num js-line-number js-blob-rnum" data-line-number="2"></td>
<td id="file-mainactivity_tests-cs-LC2" class="blob-code blob-code-inner js-file-line">  {</td>
</tr>
<tr>
<td id="file-mainactivity_tests-cs-L3" class="blob-num js-line-number js-blob-rnum" data-line-number="3"></td>
<td id="file-mainactivity_tests-cs-LC3" class="blob-code blob-code-inner js-file-line">      protected override void OnCreate(Bundle savedInstanceState)</td>
</tr>
<tr>
<td id="file-mainactivity_tests-cs-L4" class="blob-num js-line-number js-blob-rnum" data-line-number="4"></td>
<td id="file-mainactivity_tests-cs-LC4" class="blob-code blob-code-inner js-file-line">      {</td>
</tr>
<tr>
<td id="file-mainactivity_tests-cs-L5" class="blob-num js-line-number js-blob-rnum" data-line-number="5"></td>
<td id="file-mainactivity_tests-cs-LC5" class="blob-code blob-code-inner js-file-line">          base.OnCreate(savedInstanceState);</td>
</tr>
<tr>
<td id="file-mainactivity_tests-cs-L6" class="blob-num js-line-number js-blob-rnum" data-line-number="6"></td>
<td id="file-mainactivity_tests-cs-LC6" class="blob-code blob-code-inner js-file-line">
</td>
</tr>
<tr>
<td id="file-mainactivity_tests-cs-L7" class="blob-num js-line-number js-blob-rnum" data-line-number="7"></td>
<td id="file-mainactivity_tests-cs-LC7" class="blob-code blob-code-inner js-file-line">          global::Xamarin.Forms.Forms.Init(this, savedInstanceState);</td>
</tr>
<tr>
<td id="file-mainactivity_tests-cs-L8" class="blob-num js-line-number js-blob-rnum" data-line-number="8"></td>
<td id="file-mainactivity_tests-cs-LC8" class="blob-code blob-code-inner js-file-line">
</td>
</tr>
<tr>
<td id="file-mainactivity_tests-cs-L9" class="blob-num js-line-number js-blob-rnum" data-line-number="9"></td>
<td id="file-mainactivity_tests-cs-LC9" class="blob-code blob-code-inner js-file-line">          // This will load all tests within the current project</td>
</tr>
<tr>
<td id="file-mainactivity_tests-cs-L10" class="blob-num js-line-number js-blob-rnum" data-line-number="10"></td>
<td id="file-mainactivity_tests-cs-LC10" class="blob-code blob-code-inner js-file-line">          var nunit = new NUnit.Runner.App();</td>
</tr>
<tr>
<td id="file-mainactivity_tests-cs-L11" class="blob-num js-line-number js-blob-rnum" data-line-number="11"></td>
<td id="file-mainactivity_tests-cs-LC11" class="blob-code blob-code-inner js-file-line">
</td>
</tr>
<tr>
<td id="file-mainactivity_tests-cs-L12" class="blob-num js-line-number js-blob-rnum" data-line-number="12"></td>
<td id="file-mainactivity_tests-cs-LC12" class="blob-code blob-code-inner js-file-line">          // If you want to add tests in another assembly</td>
</tr>
<tr>
<td id="file-mainactivity_tests-cs-L13" class="blob-num js-line-number js-blob-rnum" data-line-number="13"></td>
<td id="file-mainactivity_tests-cs-LC13" class="blob-code blob-code-inner js-file-line">          //nunit.AddTestAssembly(typeof(MyTests).Assembly);</td>
</tr>
<tr>
<td id="file-mainactivity_tests-cs-L14" class="blob-num js-line-number js-blob-rnum" data-line-number="14"></td>
<td id="file-mainactivity_tests-cs-LC14" class="blob-code blob-code-inner js-file-line">
</td>
</tr>
<tr>
<td id="file-mainactivity_tests-cs-L15" class="blob-num js-line-number js-blob-rnum" data-line-number="15"></td>
<td id="file-mainactivity_tests-cs-LC15" class="blob-code blob-code-inner js-file-line">          // Do you want to automatically run tests when the app starts?</td>
</tr>
<tr>
<td id="file-mainactivity_tests-cs-L16" class="blob-num js-line-number js-blob-rnum" data-line-number="16"></td>
<td id="file-mainactivity_tests-cs-LC16" class="blob-code blob-code-inner js-file-line">          nunit.AutoRun = true;</td>
</tr>
<tr>
<td id="file-mainactivity_tests-cs-L17" class="blob-num js-line-number js-blob-rnum" data-line-number="17"></td>
<td id="file-mainactivity_tests-cs-LC17" class="blob-code blob-code-inner js-file-line">
</td>
</tr>
<tr>
<td id="file-mainactivity_tests-cs-L18" class="blob-num js-line-number js-blob-rnum" data-line-number="18"></td>
<td id="file-mainactivity_tests-cs-LC18" class="blob-code blob-code-inner js-file-line">          LoadApplication(nunit);</td>
</tr>
<tr>
<td id="file-mainactivity_tests-cs-L19" class="blob-num js-line-number js-blob-rnum" data-line-number="19"></td>
<td id="file-mainactivity_tests-cs-LC19" class="blob-code blob-code-inner js-file-line">      }</td>
</tr>
<tr>
<td id="file-mainactivity_tests-cs-L20" class="blob-num js-line-number js-blob-rnum" data-line-number="20"></td>
<td id="file-mainactivity_tests-cs-LC20" class="blob-code blob-code-inner js-file-line">  }</td>
</tr>
</table>
</div></div>
</p></div>
</div></div>
<div class="gist-meta">
        <a href="https://gist.github.com/dsibinski/ea386a734c1021a4ba5430e0306ab732/raw/fc5a31fd21ae36379882b0993be91d216944c4ec/MainActivity_Tests.cs" style="float:right" class="Link--inTextBlock">view raw</a><br />
        <a href="https://gist.github.com/dsibinski/ea386a734c1021a4ba5430e0306ab732#file-mainactivity_tests-cs" class="Link--inTextBlock"><br />
          MainActivity_Tests.cs<br />
        </a><br />
        hosted with &#10084; by <a class="Link--inTextBlock" href="https://github.com">GitHub</a>
      </div>
</p></div>
</div>
<p>As you can see, this is an <a href="https://www.codejourney.net/2017/03/xamarin-android-activities/" target="_blank" rel="noopener">Activity</a>, so it will be launched as a separate app with its own GUI. It&#8217;s built using Xamarin.Forms. The comments in auto-generated class are obvious, so I won&#8217;t explain the details here. That&#8217;s just what nUnit wrapper for Android on-device tests does &#8211; it allows to be run as a separate, small application with a GUI allowing to run unit tests directly on the device (similarly to ReSharper tests runner we use directly in Visual Studio).</p>
<p>One testable piece of <em>MoneyBack</em> application is the <em>Repository</em> used for database operations (by the way I refactored and made it generic, you can see how it looks currently on <a href="https://github.com/dsibinski/MoneyBack" target="_blank" rel="noopener">GitHub</a>), so I added <span style="color: #ff6600;"><em>RepositoryTests</em></span> class to <em>MoneyBack.Android.Tests</em> project with two test methods:</p>
<p><style>.gist table { margin-bottom: 0; }</style>
<div style="tab-size: 8" id="gist46061804" class="gist">
<div class="gist-file" translate="no" data-color-mode="light" data-light-theme="light">
<div class="gist-data">
<div class="js-gist-file-update-container js-task-list-container">
<div id="file-repositorytests_methods-cs" class="file my-2">
<div itemprop="text"
      class="Box-body p-0 blob-wrapper data type-c  "
      style="overflow: auto" tabindex="0" role="region"
      aria-label="RepositoryTests_methods.cs content, created by dsibinski on 10:22PM on March 25, 2017."
    ></p>
<div class="js-check-hidden-unicode js-blob-code-container blob-code-content">
<p>  <template class="js-file-alert-template"></p>
<div data-view-component="true" class="flash flash-warn flash-full d-flex flex-items-center">
  <svg aria-hidden="true" data-component="Octicon" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-alert">
    <path d="M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"></path>
</svg><br />
    <span><br />
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.<br />
      <a class="Link--inTextBlock" href="https://github.co/hiddenchars" target="_blank">Learn more about bidirectional Unicode characters</a><br />
    </span></p>
<div data-view-component="true" class="flash-action">        <a href="{{ revealButtonHref }}" data-view-component="true" class="btn-sm btn">    Show hidden characters<br />
</a>
</div>
</div>
<p></template><br />
<template class="js-line-alert-template"><br />
  <span aria-label="This line has hidden Unicode characters" data-view-component="true" class="line-alert tooltipped tooltipped-e"><br />
    <svg aria-hidden="true" data-component="Octicon" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-alert">
    <path d="M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"></path>
</svg><br />
</span></template></p>
<table data-hpc class="highlight tab-size js-file-line-container" data-tab-size="4" data-paste-markdown-skip data-tagsearch-path="RepositoryTests_methods.cs">
<tr>
<td id="file-repositorytests_methods-cs-L1" class="blob-num js-line-number js-blob-rnum" data-line-number="1"></td>
<td id="file-repositorytests_methods-cs-LC1" class="blob-code blob-code-inner js-file-line">[Test]</td>
</tr>
<tr>
<td id="file-repositorytests_methods-cs-L2" class="blob-num js-line-number js-blob-rnum" data-line-number="2"></td>
<td id="file-repositorytests_methods-cs-LC2" class="blob-code blob-code-inner js-file-line">public void one_new_person_inserted_adds_one_new_row()</td>
</tr>
<tr>
<td id="file-repositorytests_methods-cs-L3" class="blob-num js-line-number js-blob-rnum" data-line-number="3"></td>
<td id="file-repositorytests_methods-cs-LC3" class="blob-code blob-code-inner js-file-line">{</td>
</tr>
<tr>
<td id="file-repositorytests_methods-cs-L4" class="blob-num js-line-number js-blob-rnum" data-line-number="4"></td>
<td id="file-repositorytests_methods-cs-LC4" class="blob-code blob-code-inner js-file-line">    // given</td>
</tr>
<tr>
<td id="file-repositorytests_methods-cs-L5" class="blob-num js-line-number js-blob-rnum" data-line-number="5"></td>
<td id="file-repositorytests_methods-cs-LC5" class="blob-code blob-code-inner js-file-line">    var person = new Person()</td>
</tr>
<tr>
<td id="file-repositorytests_methods-cs-L6" class="blob-num js-line-number js-blob-rnum" data-line-number="6"></td>
<td id="file-repositorytests_methods-cs-LC6" class="blob-code blob-code-inner js-file-line">    {</td>
</tr>
<tr>
<td id="file-repositorytests_methods-cs-L7" class="blob-num js-line-number js-blob-rnum" data-line-number="7"></td>
<td id="file-repositorytests_methods-cs-LC7" class="blob-code blob-code-inner js-file-line">        Name = &quot;A&quot;,</td>
</tr>
<tr>
<td id="file-repositorytests_methods-cs-L8" class="blob-num js-line-number js-blob-rnum" data-line-number="8"></td>
<td id="file-repositorytests_methods-cs-LC8" class="blob-code blob-code-inner js-file-line">        LastName = &quot;B&quot;</td>
</tr>
<tr>
<td id="file-repositorytests_methods-cs-L9" class="blob-num js-line-number js-blob-rnum" data-line-number="9"></td>
<td id="file-repositorytests_methods-cs-LC9" class="blob-code blob-code-inner js-file-line">    };</td>
</tr>
<tr>
<td id="file-repositorytests_methods-cs-L10" class="blob-num js-line-number js-blob-rnum" data-line-number="10"></td>
<td id="file-repositorytests_methods-cs-LC10" class="blob-code blob-code-inner js-file-line">
</td>
</tr>
<tr>
<td id="file-repositorytests_methods-cs-L11" class="blob-num js-line-number js-blob-rnum" data-line-number="11"></td>
<td id="file-repositorytests_methods-cs-LC11" class="blob-code blob-code-inner js-file-line">    var repo = new Repository&lt;Person&gt;(InMemorySqliteConnection);</td>
</tr>
<tr>
<td id="file-repositorytests_methods-cs-L12" class="blob-num js-line-number js-blob-rnum" data-line-number="12"></td>
<td id="file-repositorytests_methods-cs-LC12" class="blob-code blob-code-inner js-file-line">
</td>
</tr>
<tr>
<td id="file-repositorytests_methods-cs-L13" class="blob-num js-line-number js-blob-rnum" data-line-number="13"></td>
<td id="file-repositorytests_methods-cs-LC13" class="blob-code blob-code-inner js-file-line">    // when</td>
</tr>
<tr>
<td id="file-repositorytests_methods-cs-L14" class="blob-num js-line-number js-blob-rnum" data-line-number="14"></td>
<td id="file-repositorytests_methods-cs-LC14" class="blob-code blob-code-inner js-file-line">    var numRows = repo.Insert(person).Result;</td>
</tr>
<tr>
<td id="file-repositorytests_methods-cs-L15" class="blob-num js-line-number js-blob-rnum" data-line-number="15"></td>
<td id="file-repositorytests_methods-cs-LC15" class="blob-code blob-code-inner js-file-line">
</td>
</tr>
<tr>
<td id="file-repositorytests_methods-cs-L16" class="blob-num js-line-number js-blob-rnum" data-line-number="16"></td>
<td id="file-repositorytests_methods-cs-LC16" class="blob-code blob-code-inner js-file-line">    // then</td>
</tr>
<tr>
<td id="file-repositorytests_methods-cs-L17" class="blob-num js-line-number js-blob-rnum" data-line-number="17"></td>
<td id="file-repositorytests_methods-cs-LC17" class="blob-code blob-code-inner js-file-line">    Assert.AreEqual(1, numRows);</td>
</tr>
<tr>
<td id="file-repositorytests_methods-cs-L18" class="blob-num js-line-number js-blob-rnum" data-line-number="18"></td>
<td id="file-repositorytests_methods-cs-LC18" class="blob-code blob-code-inner js-file-line">}</td>
</tr>
<tr>
<td id="file-repositorytests_methods-cs-L19" class="blob-num js-line-number js-blob-rnum" data-line-number="19"></td>
<td id="file-repositorytests_methods-cs-LC19" class="blob-code blob-code-inner js-file-line">
</td>
</tr>
<tr>
<td id="file-repositorytests_methods-cs-L20" class="blob-num js-line-number js-blob-rnum" data-line-number="20"></td>
<td id="file-repositorytests_methods-cs-LC20" class="blob-code blob-code-inner js-file-line">[Test]</td>
</tr>
<tr>
<td id="file-repositorytests_methods-cs-L21" class="blob-num js-line-number js-blob-rnum" data-line-number="21"></td>
<td id="file-repositorytests_methods-cs-LC21" class="blob-code blob-code-inner js-file-line">public void new_person_added_has_id_primarykey_generated()</td>
</tr>
<tr>
<td id="file-repositorytests_methods-cs-L22" class="blob-num js-line-number js-blob-rnum" data-line-number="22"></td>
<td id="file-repositorytests_methods-cs-LC22" class="blob-code blob-code-inner js-file-line">{</td>
</tr>
<tr>
<td id="file-repositorytests_methods-cs-L23" class="blob-num js-line-number js-blob-rnum" data-line-number="23"></td>
<td id="file-repositorytests_methods-cs-LC23" class="blob-code blob-code-inner js-file-line">    // given</td>
</tr>
<tr>
<td id="file-repositorytests_methods-cs-L24" class="blob-num js-line-number js-blob-rnum" data-line-number="24"></td>
<td id="file-repositorytests_methods-cs-LC24" class="blob-code blob-code-inner js-file-line">    var person1 = new Person</td>
</tr>
<tr>
<td id="file-repositorytests_methods-cs-L25" class="blob-num js-line-number js-blob-rnum" data-line-number="25"></td>
<td id="file-repositorytests_methods-cs-LC25" class="blob-code blob-code-inner js-file-line">    {</td>
</tr>
<tr>
<td id="file-repositorytests_methods-cs-L26" class="blob-num js-line-number js-blob-rnum" data-line-number="26"></td>
<td id="file-repositorytests_methods-cs-LC26" class="blob-code blob-code-inner js-file-line">        Name = &quot;A&quot;,</td>
</tr>
<tr>
<td id="file-repositorytests_methods-cs-L27" class="blob-num js-line-number js-blob-rnum" data-line-number="27"></td>
<td id="file-repositorytests_methods-cs-LC27" class="blob-code blob-code-inner js-file-line">        LastName = &quot;B&quot;</td>
</tr>
<tr>
<td id="file-repositorytests_methods-cs-L28" class="blob-num js-line-number js-blob-rnum" data-line-number="28"></td>
<td id="file-repositorytests_methods-cs-LC28" class="blob-code blob-code-inner js-file-line">    };</td>
</tr>
<tr>
<td id="file-repositorytests_methods-cs-L29" class="blob-num js-line-number js-blob-rnum" data-line-number="29"></td>
<td id="file-repositorytests_methods-cs-LC29" class="blob-code blob-code-inner js-file-line">
</td>
</tr>
<tr>
<td id="file-repositorytests_methods-cs-L30" class="blob-num js-line-number js-blob-rnum" data-line-number="30"></td>
<td id="file-repositorytests_methods-cs-LC30" class="blob-code blob-code-inner js-file-line">    var person2 = new Person</td>
</tr>
<tr>
<td id="file-repositorytests_methods-cs-L31" class="blob-num js-line-number js-blob-rnum" data-line-number="31"></td>
<td id="file-repositorytests_methods-cs-LC31" class="blob-code blob-code-inner js-file-line">    {</td>
</tr>
<tr>
<td id="file-repositorytests_methods-cs-L32" class="blob-num js-line-number js-blob-rnum" data-line-number="32"></td>
<td id="file-repositorytests_methods-cs-LC32" class="blob-code blob-code-inner js-file-line">        Name = &quot;A&quot;,</td>
</tr>
<tr>
<td id="file-repositorytests_methods-cs-L33" class="blob-num js-line-number js-blob-rnum" data-line-number="33"></td>
<td id="file-repositorytests_methods-cs-LC33" class="blob-code blob-code-inner js-file-line">        LastName = &quot;B&quot;</td>
</tr>
<tr>
<td id="file-repositorytests_methods-cs-L34" class="blob-num js-line-number js-blob-rnum" data-line-number="34"></td>
<td id="file-repositorytests_methods-cs-LC34" class="blob-code blob-code-inner js-file-line">    };</td>
</tr>
<tr>
<td id="file-repositorytests_methods-cs-L35" class="blob-num js-line-number js-blob-rnum" data-line-number="35"></td>
<td id="file-repositorytests_methods-cs-LC35" class="blob-code blob-code-inner js-file-line">
</td>
</tr>
<tr>
<td id="file-repositorytests_methods-cs-L36" class="blob-num js-line-number js-blob-rnum" data-line-number="36"></td>
<td id="file-repositorytests_methods-cs-LC36" class="blob-code blob-code-inner js-file-line">    var repo = new Repository&lt;Person&gt;(InMemorySqliteConnection);</td>
</tr>
<tr>
<td id="file-repositorytests_methods-cs-L37" class="blob-num js-line-number js-blob-rnum" data-line-number="37"></td>
<td id="file-repositorytests_methods-cs-LC37" class="blob-code blob-code-inner js-file-line">
</td>
</tr>
<tr>
<td id="file-repositorytests_methods-cs-L38" class="blob-num js-line-number js-blob-rnum" data-line-number="38"></td>
<td id="file-repositorytests_methods-cs-LC38" class="blob-code blob-code-inner js-file-line">    // when</td>
</tr>
<tr>
<td id="file-repositorytests_methods-cs-L39" class="blob-num js-line-number js-blob-rnum" data-line-number="39"></td>
<td id="file-repositorytests_methods-cs-LC39" class="blob-code blob-code-inner js-file-line">    var n1 = repo.Insert(person1).Result; // getting Result in order to force Task&#39;s completion before continuing</td>
</tr>
<tr>
<td id="file-repositorytests_methods-cs-L40" class="blob-num js-line-number js-blob-rnum" data-line-number="40"></td>
<td id="file-repositorytests_methods-cs-LC40" class="blob-code blob-code-inner js-file-line">    var n2 = repo.Insert(person2).Result;</td>
</tr>
<tr>
<td id="file-repositorytests_methods-cs-L41" class="blob-num js-line-number js-blob-rnum" data-line-number="41"></td>
<td id="file-repositorytests_methods-cs-LC41" class="blob-code blob-code-inner js-file-line">
</td>
</tr>
<tr>
<td id="file-repositorytests_methods-cs-L42" class="blob-num js-line-number js-blob-rnum" data-line-number="42"></td>
<td id="file-repositorytests_methods-cs-LC42" class="blob-code blob-code-inner js-file-line">    // then</td>
</tr>
<tr>
<td id="file-repositorytests_methods-cs-L43" class="blob-num js-line-number js-blob-rnum" data-line-number="43"></td>
<td id="file-repositorytests_methods-cs-LC43" class="blob-code blob-code-inner js-file-line">    Assert.Greater(person1.Id, 0);</td>
</tr>
<tr>
<td id="file-repositorytests_methods-cs-L44" class="blob-num js-line-number js-blob-rnum" data-line-number="44"></td>
<td id="file-repositorytests_methods-cs-LC44" class="blob-code blob-code-inner js-file-line">    Assert.AreEqual(person2.Id, person1.Id + 1);</td>
</tr>
<tr>
<td id="file-repositorytests_methods-cs-L45" class="blob-num js-line-number js-blob-rnum" data-line-number="45"></td>
<td id="file-repositorytests_methods-cs-LC45" class="blob-code blob-code-inner js-file-line">}</td>
</tr>
</table>
</div></div>
</p></div>
</div></div>
<div class="gist-meta">
        <a href="https://gist.github.com/dsibinski/2cefa097384d3c5e33595f37392cc330/raw/444e616d3480cdad0bda4c96e7112c7e65b2f698/RepositoryTests_methods.cs" style="float:right" class="Link--inTextBlock">view raw</a><br />
        <a href="https://gist.github.com/dsibinski/2cefa097384d3c5e33595f37392cc330#file-repositorytests_methods-cs" class="Link--inTextBlock"><br />
          RepositoryTests_methods.cs<br />
        </a><br />
        hosted with &#10084; by <a class="Link--inTextBlock" href="https://github.com">GitHub</a>
      </div>
</p></div>
</div>
<p>The interesting part is that as I&#8217;m using <a href="https://www.codejourney.net/2017/03/using-sqlite-database-in-xamarin-android/" target="_blank" rel="noopener">SQLite database in my app</a>, I wanted to test it without creating database file on the device. For that purpose, when creating <em><span style="color: #ff6600;">SQLiteAsyncConnection</span> </em>in order<em> </em>to initialize my <em><span style="color: #ff6600;">Repository</span>, </em>I passed to its constructor a <em>&#8220;:memory:&#8221;</em> string, which makes SQLite database created <a href="https://sqlite.org/inmemorydb.html" target="_blank" rel="noopener">in-memory</a> (there is no physical file created):</p>
<p><style>.gist table { margin-bottom: 0; }</style>
<div style="tab-size: 8" id="gist46061888" class="gist">
<div class="gist-file" translate="no" data-color-mode="light" data-light-theme="light">
<div class="gist-data">
<div class="js-gist-file-update-container js-task-list-container">
<div id="file-repositorytests_sqlite-cs" class="file my-2">
<div itemprop="text"
      class="Box-body p-0 blob-wrapper data type-c  "
      style="overflow: auto" tabindex="0" role="region"
      aria-label="RepositoryTests_sqlite.cs content, created by dsibinski on 10:27PM on March 25, 2017."
    ></p>
<div class="js-check-hidden-unicode js-blob-code-container blob-code-content">
<p>  <template class="js-file-alert-template"></p>
<div data-view-component="true" class="flash flash-warn flash-full d-flex flex-items-center">
  <svg aria-hidden="true" data-component="Octicon" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-alert">
    <path d="M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"></path>
</svg><br />
    <span><br />
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.<br />
      <a class="Link--inTextBlock" href="https://github.co/hiddenchars" target="_blank">Learn more about bidirectional Unicode characters</a><br />
    </span></p>
<div data-view-component="true" class="flash-action">        <a href="{{ revealButtonHref }}" data-view-component="true" class="btn-sm btn">    Show hidden characters<br />
</a>
</div>
</div>
<p></template><br />
<template class="js-line-alert-template"><br />
  <span aria-label="This line has hidden Unicode characters" data-view-component="true" class="line-alert tooltipped tooltipped-e"><br />
    <svg aria-hidden="true" data-component="Octicon" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-alert">
    <path d="M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"></path>
</svg><br />
</span></template></p>
<table data-hpc class="highlight tab-size js-file-line-container" data-tab-size="4" data-paste-markdown-skip data-tagsearch-path="RepositoryTests_sqlite.cs">
<tr>
<td id="file-repositorytests_sqlite-cs-L1" class="blob-num js-line-number js-blob-rnum" data-line-number="1"></td>
<td id="file-repositorytests_sqlite-cs-LC1" class="blob-code blob-code-inner js-file-line">  public SQLiteAsyncConnection InMemorySqliteConnection;</td>
</tr>
<tr>
<td id="file-repositorytests_sqlite-cs-L2" class="blob-num js-line-number js-blob-rnum" data-line-number="2"></td>
<td id="file-repositorytests_sqlite-cs-LC2" class="blob-code blob-code-inner js-file-line">
</td>
</tr>
<tr>
<td id="file-repositorytests_sqlite-cs-L3" class="blob-num js-line-number js-blob-rnum" data-line-number="3"></td>
<td id="file-repositorytests_sqlite-cs-LC3" class="blob-code blob-code-inner js-file-line">  [OneTimeSetUp]</td>
</tr>
<tr>
<td id="file-repositorytests_sqlite-cs-L4" class="blob-num js-line-number js-blob-rnum" data-line-number="4"></td>
<td id="file-repositorytests_sqlite-cs-LC4" class="blob-code blob-code-inner js-file-line">  public void Init()</td>
</tr>
<tr>
<td id="file-repositorytests_sqlite-cs-L5" class="blob-num js-line-number js-blob-rnum" data-line-number="5"></td>
<td id="file-repositorytests_sqlite-cs-LC5" class="blob-code blob-code-inner js-file-line">  {</td>
</tr>
<tr>
<td id="file-repositorytests_sqlite-cs-L6" class="blob-num js-line-number js-blob-rnum" data-line-number="6"></td>
<td id="file-repositorytests_sqlite-cs-LC6" class="blob-code blob-code-inner js-file-line">      InMemorySqliteConnection = new SQLiteAsyncConnection(&quot;:memory:&quot;);</td>
</tr>
<tr>
<td id="file-repositorytests_sqlite-cs-L7" class="blob-num js-line-number js-blob-rnum" data-line-number="7"></td>
<td id="file-repositorytests_sqlite-cs-LC7" class="blob-code blob-code-inner js-file-line">  }</td>
</tr>
</table>
</div></div>
</p></div>
</div></div>
<div class="gist-meta">
        <a href="https://gist.github.com/dsibinski/e205d0eacd107226c0986a2b9d2d8422/raw/53f9fb2a2be3c5f28320fbc09049b087694ed624/RepositoryTests_sqlite.cs" style="float:right" class="Link--inTextBlock">view raw</a><br />
        <a href="https://gist.github.com/dsibinski/e205d0eacd107226c0986a2b9d2d8422#file-repositorytests_sqlite-cs" class="Link--inTextBlock"><br />
          RepositoryTests_sqlite.cs<br />
        </a><br />
        hosted with &#10084; by <a class="Link--inTextBlock" href="https://github.com">GitHub</a>
      </div>
</p></div>
</div>
<p>&nbsp;</p>
<p>Such database lives in device&#8217;s memory only for the time of our unit tests.</p>
<p>After having tests written, there&#8217;s a time to execute them. As the project contains <em><span style="color: #ff6600;">MainActivity</span> </em>class, we simply deploy and run it on a device/emulator, which presents the following view:</p>
<figure id="attachment_1306" aria-describedby="caption-attachment-1306" style="width: 210px" class="wp-caption aligncenter"><img data-recalc-dims="1" loading="lazy" decoding="async" data-attachment-id="1306" data-permalink="https://www.codejourney.net/unit-testing-xamarin-application/screenshot_2017-03-25-23-31-44/" data-orig-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/Screenshot_2017-03-25-23-31-44.png?fit=1080%2C1920&amp;ssl=1" data-orig-size="1080,1920" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="Screenshot_2017-03-25-23-31-44" data-image-description="" data-image-caption="" data-large-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/Screenshot_2017-03-25-23-31-44.png?fit=576%2C1024&amp;ssl=1" class=" wp-image-1306 aligncenter" src="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/Screenshot_2017-03-25-23-31-44.png?resize=210%2C374&#038;ssl=1" alt="Screenshot_2017-03-25-23-31-44.png" width="210" height="374" srcset="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/Screenshot_2017-03-25-23-31-44.png?w=1080&amp;ssl=1 1080w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/Screenshot_2017-03-25-23-31-44.png?resize=169%2C300&amp;ssl=1 169w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/Screenshot_2017-03-25-23-31-44.png?resize=768%2C1365&amp;ssl=1 768w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/Screenshot_2017-03-25-23-31-44.png?resize=576%2C1024&amp;ssl=1 576w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/Screenshot_2017-03-25-23-31-44.png?resize=720%2C1280&amp;ssl=1 720w" sizes="auto, (max-width: 210px) 100vw, 210px" /><figcaption id="caption-attachment-1306" class="wp-caption-text">Device &#8211; tests results</figcaption></figure>
<p>If any of our tests is not passed, we can see the failure&#8217;s details:</p>
<figure id="attachment_1311" aria-describedby="caption-attachment-1311" style="width: 219px" class="wp-caption aligncenter"><img data-recalc-dims="1" loading="lazy" decoding="async" data-attachment-id="1311" data-permalink="https://www.codejourney.net/unit-testing-xamarin-application/screenshot_2017-03-25-21-23-07/" data-orig-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/Screenshot_2017-03-25-21-23-07.png?fit=1080%2C1920&amp;ssl=1" data-orig-size="1080,1920" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="Screenshot_2017-03-25-21-23-07" data-image-description="" data-image-caption="" data-large-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/Screenshot_2017-03-25-21-23-07.png?fit=576%2C1024&amp;ssl=1" class=" wp-image-1311 aligncenter" src="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/Screenshot_2017-03-25-21-23-07.png?resize=219%2C389&#038;ssl=1" alt="Screenshot_2017-03-25-21-23-07.png" width="219" height="389" srcset="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/Screenshot_2017-03-25-21-23-07.png?w=1080&amp;ssl=1 1080w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/Screenshot_2017-03-25-21-23-07.png?resize=169%2C300&amp;ssl=1 169w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/Screenshot_2017-03-25-21-23-07.png?resize=768%2C1365&amp;ssl=1 768w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/Screenshot_2017-03-25-21-23-07.png?resize=576%2C1024&amp;ssl=1 576w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/Screenshot_2017-03-25-21-23-07.png?resize=720%2C1280&amp;ssl=1 720w" sizes="auto, (max-width: 219px) 100vw, 219px" /><figcaption id="caption-attachment-1311" class="wp-caption-text">Device &#8211; test failed</figcaption></figure>
<p>We can of course debug our units tests in Visual Studio. The GUI on the device also allows to re-run the tests and see results of all of them.</p>
<h2>Summary</h2>
<p>We&#8217;ve seen how to add two new projects to Xamarin solution: one containing platform-independent unit tests (old good ones), the other one testing Android-specific stuff which is run directly on the device or emulator.</p>
<p>For bigger and more &#8220;real&#8221; apps, UI testing would also be necessary. This however requires using some cloud testing lab or setting up your own testing environment. More details can be found <a href="https://developer.xamarin.com/guides/testcloud/introduction-to-test-cloud/" target="_blank" rel="noopener">here</a>.</p>
<p><span style="text-decoration: underline;"><strong>If you have any experience in testing Xamarin applications, share your insights/advices <img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f642.png" alt="🙂" class="wp-smiley" style="height: 1em; max-height: 1em;" /></strong></span></p>
<h2> </h2>
<p>&nbsp;</p>
<p>The post <a href="https://www.codejourney.net/unit-testing-xamarin-application/">Unit Testing Xamarin application</a> appeared first on <a href="https://www.codejourney.net">CodeJourney.net</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.codejourney.net/unit-testing-xamarin-application/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1166</post-id>	</item>
		<item>
		<title>Using SQLite database in Xamarin.Android</title>
		<link>https://www.codejourney.net/using-sqlite-database-in-xamarin-android/</link>
					<comments>https://www.codejourney.net/using-sqlite-database-in-xamarin-android/#comments</comments>
		
		<dc:creator><![CDATA[Dawid Sibiński]]></dc:creator>
		<pubDate>Sun, 19 Mar 2017 22:32:29 +0000</pubDate>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[android]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[dajsiepoznac2017]]></category>
		<category><![CDATA[sqlite]]></category>
		<category><![CDATA[xamarin]]></category>
		<guid isPermaLink="false">http://www.dsibinski.pl/?p=970</guid>

					<description><![CDATA[<p>I started to define development tasks to be done within MoneyBack project in the coming days (maybe I&#8217;ll even publish my Trello board soon 🙂 ) and it turned out that each functionality the app is going to offer needs persistent storage (e.g. to store people, payments, events etc.). The obvious choice is the local database in which&#8230;</p>
<p>The post <a href="https://www.codejourney.net/using-sqlite-database-in-xamarin-android/">Using SQLite database in Xamarin.Android</a> appeared first on <a href="https://www.codejourney.net">CodeJourney.net</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>I started to define development tasks to be done within <em>MoneyBack</em> project in the coming days (maybe I&#8217;ll even publish my Trello board soon <img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f642.png" alt="🙂" class="wp-smiley" style="height: 1em; max-height: 1em;" /> ) and it turned out that each functionality the app is going to offer needs persistent storage (e.g. to store people, payments, events etc.). The obvious choice is the local database in which I could store my entities and application&#8217;s data.</p>
<p>In this post, I&#8217;d like to show you how quickly and easily SQLite database can be added and started to be used in Xamarin.Android project using <a href="https://www.nuget.org/packages/sqlite-net/" target="_blank" rel="noopener">SQLite.NET</a> and Visual Studio 2017.<br />
<span id="more-970"></span></p>
<h2>What is SQLite?</h2>
<p><a href="http://sqlite.org/" target="_blank" rel="noopener">SQLite</a> is an open-source database engine, which allows to store data in SQL structures. The whole database is stored in a single file, which makes it easily manageable on mobile devices. It&#8217;s lightweight, small and easily portable. It&#8217;s also prepared to work on multiple platforms.</p>
<p>There are some limitations in contrast to &#8220;classic&#8221; SQL database engines, including:</p>
<ul>
<li>OUTER join syntax is not fully supported</li>
<li>for altering tables, only &#8220;RENAME&#8221; and &#8220;ADDCOLUMN&#8221; operations are available</li>
<li>writing to views is impossible (views are read-only).</li>
</ul>
<p>SQLite database can be easily operated using SQLite.NET ORM library available to download and install via Nuget. Let&#8217;s see how to do it.</p>
<h2>Installing SQLite.NET package</h2>
<p>In order to install SQLite.NET package, simply open Android.Xamarin solution in Visual Studio, open Package Manager Console and type the following command:</p>
<pre><pre class="brush: csharp; title: ; notranslate">install-package Sqlite-Net</pre>
<p>After few seconds, two files are added to our project:</p>
<figure id="attachment_1007" aria-describedby="caption-attachment-1007" style="width: 185px" class="wp-caption aligncenter"><img data-recalc-dims="1" loading="lazy" decoding="async" data-attachment-id="1007" data-permalink="https://www.codejourney.net/using-sqlite-database-in-xamarin-android/sqlitenetfiles/" data-orig-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/SQLiteNetFiles.png?fit=315%2C420&amp;ssl=1" data-orig-size="315,420" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="SQLiteNetFiles" data-image-description="" data-image-caption="" data-large-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/SQLiteNetFiles.png?fit=315%2C420&amp;ssl=1" class=" wp-image-1007 aligncenter" src="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/SQLiteNetFiles.png?resize=185%2C247&#038;ssl=1" alt="SQLiteNetFiles" width="185" height="247" srcset="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/SQLiteNetFiles.png?w=315&amp;ssl=1 315w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/SQLiteNetFiles.png?resize=225%2C300&amp;ssl=1 225w" sizes="auto, (max-width: 185px) 100vw, 185px" /><figcaption id="caption-attachment-1007" class="wp-caption-text">Files added by SQLite.NET</figcaption></figure>
<p>It means we&#8217;re all set <img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f642.png" alt="🙂" class="wp-smiley" style="height: 1em; max-height: 1em;" /></p>
<h2>Entity definition</h2>
<p>We have SQLite ORM ready to use. Now we need to define our first entity. In case of <em>MoneyBack</em>, I decided to start with defining <em>Person </em>(plural: <em>People</em>) entity. First thing we need to do is to define entity class. I created &#8220;Entities&#8221; folder for that and added the following class file:</p>
<p><style>.gist table { margin-bottom: 0; }</style>
<div style="tab-size: 8" id="gist45864679" class="gist">
<div class="gist-file" translate="no" data-color-mode="light" data-light-theme="light">
<div class="gist-data">
<div class="js-gist-file-update-container js-task-list-container">
<div id="file-person-cs" class="file my-2">
<div itemprop="text"
      class="Box-body p-0 blob-wrapper data type-c  "
      style="overflow: auto" tabindex="0" role="region"
      aria-label="Person.cs content, created by dsibinski on 09:06PM on March 19, 2017."
    ></p>
<div class="js-check-hidden-unicode js-blob-code-container blob-code-content">
<p>  <template class="js-file-alert-template"></p>
<div data-view-component="true" class="flash flash-warn flash-full d-flex flex-items-center">
  <svg aria-hidden="true" data-component="Octicon" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-alert">
    <path d="M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"></path>
</svg><br />
    <span><br />
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.<br />
      <a class="Link--inTextBlock" href="https://github.co/hiddenchars" target="_blank">Learn more about bidirectional Unicode characters</a><br />
    </span></p>
<div data-view-component="true" class="flash-action">        <a href="{{ revealButtonHref }}" data-view-component="true" class="btn-sm btn">    Show hidden characters<br />
</a>
</div>
</div>
<p></template><br />
<template class="js-line-alert-template"><br />
  <span aria-label="This line has hidden Unicode characters" data-view-component="true" class="line-alert tooltipped tooltipped-e"><br />
    <svg aria-hidden="true" data-component="Octicon" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-alert">
    <path d="M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"></path>
</svg><br />
</span></template></p>
<table data-hpc class="highlight tab-size js-file-line-container" data-tab-size="4" data-paste-markdown-skip data-tagsearch-path="Person.cs">
<tr>
<td id="file-person-cs-L1" class="blob-num js-line-number js-blob-rnum" data-line-number="1"></td>
<td id="file-person-cs-LC1" class="blob-code blob-code-inner js-file-line">namespace MoneyBack.Entities</td>
</tr>
<tr>
<td id="file-person-cs-L2" class="blob-num js-line-number js-blob-rnum" data-line-number="2"></td>
<td id="file-person-cs-LC2" class="blob-code blob-code-inner js-file-line">{</td>
</tr>
<tr>
<td id="file-person-cs-L3" class="blob-num js-line-number js-blob-rnum" data-line-number="3"></td>
<td id="file-person-cs-LC3" class="blob-code blob-code-inner js-file-line">    [Table(&quot;People&quot;)]</td>
</tr>
<tr>
<td id="file-person-cs-L4" class="blob-num js-line-number js-blob-rnum" data-line-number="4"></td>
<td id="file-person-cs-LC4" class="blob-code blob-code-inner js-file-line">    public class Person</td>
</tr>
<tr>
<td id="file-person-cs-L5" class="blob-num js-line-number js-blob-rnum" data-line-number="5"></td>
<td id="file-person-cs-LC5" class="blob-code blob-code-inner js-file-line">    {</td>
</tr>
<tr>
<td id="file-person-cs-L6" class="blob-num js-line-number js-blob-rnum" data-line-number="6"></td>
<td id="file-person-cs-LC6" class="blob-code blob-code-inner js-file-line">        [PrimaryKey, AutoIncrement]</td>
</tr>
<tr>
<td id="file-person-cs-L7" class="blob-num js-line-number js-blob-rnum" data-line-number="7"></td>
<td id="file-person-cs-LC7" class="blob-code blob-code-inner js-file-line">        public int Id { get; set; }</td>
</tr>
<tr>
<td id="file-person-cs-L8" class="blob-num js-line-number js-blob-rnum" data-line-number="8"></td>
<td id="file-person-cs-LC8" class="blob-code blob-code-inner js-file-line">
</td>
</tr>
<tr>
<td id="file-person-cs-L9" class="blob-num js-line-number js-blob-rnum" data-line-number="9"></td>
<td id="file-person-cs-LC9" class="blob-code blob-code-inner js-file-line">        public string Name { get; set; }</td>
</tr>
<tr>
<td id="file-person-cs-L10" class="blob-num js-line-number js-blob-rnum" data-line-number="10"></td>
<td id="file-person-cs-LC10" class="blob-code blob-code-inner js-file-line">
</td>
</tr>
<tr>
<td id="file-person-cs-L11" class="blob-num js-line-number js-blob-rnum" data-line-number="11"></td>
<td id="file-person-cs-LC11" class="blob-code blob-code-inner js-file-line">        public string LastName { get; set; }</td>
</tr>
<tr>
<td id="file-person-cs-L12" class="blob-num js-line-number js-blob-rnum" data-line-number="12"></td>
<td id="file-person-cs-LC12" class="blob-code blob-code-inner js-file-line">
</td>
</tr>
<tr>
<td id="file-person-cs-L13" class="blob-num js-line-number js-blob-rnum" data-line-number="13"></td>
<td id="file-person-cs-LC13" class="blob-code blob-code-inner js-file-line">        public string PhoneNumber { get; set; }</td>
</tr>
<tr>
<td id="file-person-cs-L14" class="blob-num js-line-number js-blob-rnum" data-line-number="14"></td>
<td id="file-person-cs-LC14" class="blob-code blob-code-inner js-file-line">
</td>
</tr>
<tr>
<td id="file-person-cs-L15" class="blob-num js-line-number js-blob-rnum" data-line-number="15"></td>
<td id="file-person-cs-LC15" class="blob-code blob-code-inner js-file-line">        public string Email { get; set; }</td>
</tr>
<tr>
<td id="file-person-cs-L16" class="blob-num js-line-number js-blob-rnum" data-line-number="16"></td>
<td id="file-person-cs-LC16" class="blob-code blob-code-inner js-file-line">
</td>
</tr>
<tr>
<td id="file-person-cs-L17" class="blob-num js-line-number js-blob-rnum" data-line-number="17"></td>
<td id="file-person-cs-LC17" class="blob-code blob-code-inner js-file-line">        public override string ToString()</td>
</tr>
<tr>
<td id="file-person-cs-L18" class="blob-num js-line-number js-blob-rnum" data-line-number="18"></td>
<td id="file-person-cs-LC18" class="blob-code blob-code-inner js-file-line">        {</td>
</tr>
<tr>
<td id="file-person-cs-L19" class="blob-num js-line-number js-blob-rnum" data-line-number="19"></td>
<td id="file-person-cs-LC19" class="blob-code blob-code-inner js-file-line">            return $&quot;[Person: Id={Id}, Name={Name}, LastName={LastName}, PhoneNumber={PhoneNumber}, Email={Email}]&quot;;</td>
</tr>
<tr>
<td id="file-person-cs-L20" class="blob-num js-line-number js-blob-rnum" data-line-number="20"></td>
<td id="file-person-cs-LC20" class="blob-code blob-code-inner js-file-line">        }</td>
</tr>
<tr>
<td id="file-person-cs-L21" class="blob-num js-line-number js-blob-rnum" data-line-number="21"></td>
<td id="file-person-cs-LC21" class="blob-code blob-code-inner js-file-line">    }</td>
</tr>
<tr>
<td id="file-person-cs-L22" class="blob-num js-line-number js-blob-rnum" data-line-number="22"></td>
<td id="file-person-cs-LC22" class="blob-code blob-code-inner js-file-line">}</td>
</tr>
</table>
</div></div>
</p></div>
</div></div>
<div class="gist-meta">
        <a href="https://gist.github.com/dsibinski/a1d1ca6c5380e0acc5c439f3060da9cc/raw/afc1d9b4c0442489fdb760ba88e681d3663b9e07/Person.cs" style="float:right" class="Link--inTextBlock">view raw</a><br />
        <a href="https://gist.github.com/dsibinski/a1d1ca6c5380e0acc5c439f3060da9cc#file-person-cs" class="Link--inTextBlock"><br />
          Person.cs<br />
        </a><br />
        hosted with &#10084; by <a class="Link--inTextBlock" href="https://github.com">GitHub</a>
      </div>
</p></div>
</div>
<p>Just a class, in which we define basic properties of a Person &#8211;<em> Name, LastName, PhoneNumber</em> and <em>Email</em>. As we are designing a database entities, we also need to have keys for each of them &#8211; in this case we add <em>Id</em> property, and decorate it with two attributes:</p>
<ul>
<li><em>PrimaryKeyAttribute</em> &#8211; marks the column as PRIMARY KEY</li>
<li><em>AutoIncrementAttribute</em> &#8211; marks the column with AUTO_INCREMENT (unique number is generated when a new record is added into a table).</li>
</ul>
<p>We also have <em>TableAttribute</em> defined on <em>Person</em> class. This attribute&#8217;s constructor takes a single argument <em>name</em>, which is the name of the table which will be created underneath. In our case, single entity is called <em>Person</em>, but the table should be named in plural (table == set of entities) so we want it to be called <em>People</em>.</p>
<p>I also implemented <em>ToString() </em>method in order to be able to easily see details of our entity if needed.</p>
<h2>Location of database file</h2>
<p>Before database can be used, a database file must be created on the device. ORM does it for us before any query is made on the database, but we need to specify where we want to keep the db file. On Android, it can be stored either on internal or external storage.</p>
<p>I created <em>Constants.cs</em> class in which I put a read-only constant string returning path to database file. As a folder to store db file, I used <em>Environment.GetFolderPath(Environment.SpecialFolder.Personal) </em>which returns local path defined in Android system&#8217;s environmental variable $HOME:</p>
<p><style>.gist table { margin-bottom: 0; }</style>
<div style="tab-size: 8" id="gist45865151" class="gist">
<div class="gist-file" translate="no" data-color-mode="light" data-light-theme="light">
<div class="gist-data">
<div class="js-gist-file-update-container js-task-list-container">
<div id="file-constants_dbpath-cs" class="file my-2">
<div itemprop="text"
      class="Box-body p-0 blob-wrapper data type-c  "
      style="overflow: auto" tabindex="0" role="region"
      aria-label="Constants_dbPath.cs content, created by dsibinski on 09:30PM on March 19, 2017."
    ></p>
<div class="js-check-hidden-unicode js-blob-code-container blob-code-content">
<p>  <template class="js-file-alert-template"></p>
<div data-view-component="true" class="flash flash-warn flash-full d-flex flex-items-center">
  <svg aria-hidden="true" data-component="Octicon" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-alert">
    <path d="M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"></path>
</svg><br />
    <span><br />
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.<br />
      <a class="Link--inTextBlock" href="https://github.co/hiddenchars" target="_blank">Learn more about bidirectional Unicode characters</a><br />
    </span></p>
<div data-view-component="true" class="flash-action">        <a href="{{ revealButtonHref }}" data-view-component="true" class="btn-sm btn">    Show hidden characters<br />
</a>
</div>
</div>
<p></template><br />
<template class="js-line-alert-template"><br />
  <span aria-label="This line has hidden Unicode characters" data-view-component="true" class="line-alert tooltipped tooltipped-e"><br />
    <svg aria-hidden="true" data-component="Octicon" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-alert">
    <path d="M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"></path>
</svg><br />
</span></template></p>
<table data-hpc class="highlight tab-size js-file-line-container" data-tab-size="4" data-paste-markdown-skip data-tagsearch-path="Constants_dbPath.cs">
<tr>
<td id="file-constants_dbpath-cs-L1" class="blob-num js-line-number js-blob-rnum" data-line-number="1"></td>
<td id="file-constants_dbpath-cs-LC1" class="blob-code blob-code-inner js-file-line">public class Constants</td>
</tr>
<tr>
<td id="file-constants_dbpath-cs-L2" class="blob-num js-line-number js-blob-rnum" data-line-number="2"></td>
<td id="file-constants_dbpath-cs-LC2" class="blob-code blob-code-inner js-file-line">{</td>
</tr>
<tr>
<td id="file-constants_dbpath-cs-L3" class="blob-num js-line-number js-blob-rnum" data-line-number="3"></td>
<td id="file-constants_dbpath-cs-LC3" class="blob-code blob-code-inner js-file-line">    public static readonly string DbFilePath = </td>
</tr>
<tr>
<td id="file-constants_dbpath-cs-L4" class="blob-num js-line-number js-blob-rnum" data-line-number="4"></td>
<td id="file-constants_dbpath-cs-LC4" class="blob-code blob-code-inner js-file-line">        Path.Combine(</td>
</tr>
<tr>
<td id="file-constants_dbpath-cs-L5" class="blob-num js-line-number js-blob-rnum" data-line-number="5"></td>
<td id="file-constants_dbpath-cs-LC5" class="blob-code blob-code-inner js-file-line">                Environment.GetFolderPath(Environment.SpecialFolder.Personal), </td>
</tr>
<tr>
<td id="file-constants_dbpath-cs-L6" class="blob-num js-line-number js-blob-rnum" data-line-number="6"></td>
<td id="file-constants_dbpath-cs-LC6" class="blob-code blob-code-inner js-file-line">                &quot;moneyback.db&quot;</td>
</tr>
<tr>
<td id="file-constants_dbpath-cs-L7" class="blob-num js-line-number js-blob-rnum" data-line-number="7"></td>
<td id="file-constants_dbpath-cs-LC7" class="blob-code blob-code-inner js-file-line">        );</td>
</tr>
<tr>
<td id="file-constants_dbpath-cs-L8" class="blob-num js-line-number js-blob-rnum" data-line-number="8"></td>
<td id="file-constants_dbpath-cs-LC8" class="blob-code blob-code-inner js-file-line">}</td>
</tr>
</table>
</div></div>
</p></div>
</div></div>
<div class="gist-meta">
        <a href="https://gist.github.com/dsibinski/d5fb45ea47ee86b0540bf9f68666d103/raw/f01a0588740a5477cc78d7ce8e9e89b80d95d299/Constants_dbPath.cs" style="float:right" class="Link--inTextBlock">view raw</a><br />
        <a href="https://gist.github.com/dsibinski/d5fb45ea47ee86b0540bf9f68666d103#file-constants_dbpath-cs" class="Link--inTextBlock"><br />
          Constants_dbPath.cs<br />
        </a><br />
        hosted with &#10084; by <a class="Link--inTextBlock" href="https://github.com">GitHub</a>
      </div>
</p></div>
</div>
<h2>Database access methods</h2>
<p>As soon as we have entity class defined and location of database file, we can start performing operations on the db &#8211; define tables, add new entities (rows), retrieve rows from the database, delete them etc. In general, it comes down to creating <em>SQLiteConnection </em>object and performing operations on it.</p>
<p>There are several approaches of exposing Data Access Layer services/methods &#8211; we can create a database service, entities repository or use complex services location and dependency injection in order to operate our persistent data. I don&#8217;t know what is a standard way in Android applications, but I decided to create a very simple repository for our <em>Person</em> entity and expose database-access methods in it:</p>
<p><style>.gist table { margin-bottom: 0; }</style>
<div style="tab-size: 8" id="gist45865287" class="gist">
<div class="gist-file" translate="no" data-color-mode="light" data-light-theme="light">
<div class="gist-data">
<div class="js-gist-file-update-container js-task-list-container">
<div id="file-peoplerepository-cs" class="file my-2">
<div itemprop="text"
      class="Box-body p-0 blob-wrapper data type-c  "
      style="overflow: auto" tabindex="0" role="region"
      aria-label="PeopleRepository.cs content, created by dsibinski on 09:39PM on March 19, 2017."
    ></p>
<div class="js-check-hidden-unicode js-blob-code-container blob-code-content">
<p>  <template class="js-file-alert-template"></p>
<div data-view-component="true" class="flash flash-warn flash-full d-flex flex-items-center">
  <svg aria-hidden="true" data-component="Octicon" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-alert">
    <path d="M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"></path>
</svg><br />
    <span><br />
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.<br />
      <a class="Link--inTextBlock" href="https://github.co/hiddenchars" target="_blank">Learn more about bidirectional Unicode characters</a><br />
    </span></p>
<div data-view-component="true" class="flash-action">        <a href="{{ revealButtonHref }}" data-view-component="true" class="btn-sm btn">    Show hidden characters<br />
</a>
</div>
</div>
<p></template><br />
<template class="js-line-alert-template"><br />
  <span aria-label="This line has hidden Unicode characters" data-view-component="true" class="line-alert tooltipped tooltipped-e"><br />
    <svg aria-hidden="true" data-component="Octicon" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-alert">
    <path d="M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"></path>
</svg><br />
</span></template></p>
<table data-hpc class="highlight tab-size js-file-line-container" data-tab-size="4" data-paste-markdown-skip data-tagsearch-path="PeopleRepository.cs">
<tr>
<td id="file-peoplerepository-cs-L1" class="blob-num js-line-number js-blob-rnum" data-line-number="1"></td>
<td id="file-peoplerepository-cs-LC1" class="blob-code blob-code-inner js-file-line">public class PeopleRepository</td>
</tr>
<tr>
<td id="file-peoplerepository-cs-L2" class="blob-num js-line-number js-blob-rnum" data-line-number="2"></td>
<td id="file-peoplerepository-cs-LC2" class="blob-code blob-code-inner js-file-line">{</td>
</tr>
<tr>
<td id="file-peoplerepository-cs-L3" class="blob-num js-line-number js-blob-rnum" data-line-number="3"></td>
<td id="file-peoplerepository-cs-LC3" class="blob-code blob-code-inner js-file-line">    private SQLiteConnection db = null;</td>
</tr>
<tr>
<td id="file-peoplerepository-cs-L4" class="blob-num js-line-number js-blob-rnum" data-line-number="4"></td>
<td id="file-peoplerepository-cs-LC4" class="blob-code blob-code-inner js-file-line">    protected static PeopleRepository me;</td>
</tr>
<tr>
<td id="file-peoplerepository-cs-L5" class="blob-num js-line-number js-blob-rnum" data-line-number="5"></td>
<td id="file-peoplerepository-cs-LC5" class="blob-code blob-code-inner js-file-line">
</td>
</tr>
<tr>
<td id="file-peoplerepository-cs-L6" class="blob-num js-line-number js-blob-rnum" data-line-number="6"></td>
<td id="file-peoplerepository-cs-LC6" class="blob-code blob-code-inner js-file-line">    static PeopleRepository()</td>
</tr>
<tr>
<td id="file-peoplerepository-cs-L7" class="blob-num js-line-number js-blob-rnum" data-line-number="7"></td>
<td id="file-peoplerepository-cs-LC7" class="blob-code blob-code-inner js-file-line">    {</td>
</tr>
<tr>
<td id="file-peoplerepository-cs-L8" class="blob-num js-line-number js-blob-rnum" data-line-number="8"></td>
<td id="file-peoplerepository-cs-LC8" class="blob-code blob-code-inner js-file-line">        me = new PeopleRepository();</td>
</tr>
<tr>
<td id="file-peoplerepository-cs-L9" class="blob-num js-line-number js-blob-rnum" data-line-number="9"></td>
<td id="file-peoplerepository-cs-LC9" class="blob-code blob-code-inner js-file-line">    }</td>
</tr>
<tr>
<td id="file-peoplerepository-cs-L10" class="blob-num js-line-number js-blob-rnum" data-line-number="10"></td>
<td id="file-peoplerepository-cs-LC10" class="blob-code blob-code-inner js-file-line">
</td>
</tr>
<tr>
<td id="file-peoplerepository-cs-L11" class="blob-num js-line-number js-blob-rnum" data-line-number="11"></td>
<td id="file-peoplerepository-cs-LC11" class="blob-code blob-code-inner js-file-line">    protected PeopleRepository()</td>
</tr>
<tr>
<td id="file-peoplerepository-cs-L12" class="blob-num js-line-number js-blob-rnum" data-line-number="12"></td>
<td id="file-peoplerepository-cs-LC12" class="blob-code blob-code-inner js-file-line">    {</td>
</tr>
<tr>
<td id="file-peoplerepository-cs-L13" class="blob-num js-line-number js-blob-rnum" data-line-number="13"></td>
<td id="file-peoplerepository-cs-LC13" class="blob-code blob-code-inner js-file-line">        db = new SQLiteConnection(Constants.DbFilePath);</td>
</tr>
<tr>
<td id="file-peoplerepository-cs-L14" class="blob-num js-line-number js-blob-rnum" data-line-number="14"></td>
<td id="file-peoplerepository-cs-LC14" class="blob-code blob-code-inner js-file-line">        db.CreateTable&lt;Person&gt;();</td>
</tr>
<tr>
<td id="file-peoplerepository-cs-L15" class="blob-num js-line-number js-blob-rnum" data-line-number="15"></td>
<td id="file-peoplerepository-cs-LC15" class="blob-code blob-code-inner js-file-line">    }</td>
</tr>
<tr>
<td id="file-peoplerepository-cs-L16" class="blob-num js-line-number js-blob-rnum" data-line-number="16"></td>
<td id="file-peoplerepository-cs-LC16" class="blob-code blob-code-inner js-file-line">
</td>
</tr>
<tr>
<td id="file-peoplerepository-cs-L17" class="blob-num js-line-number js-blob-rnum" data-line-number="17"></td>
<td id="file-peoplerepository-cs-LC17" class="blob-code blob-code-inner js-file-line">    public static int SavePerson(Person person)</td>
</tr>
<tr>
<td id="file-peoplerepository-cs-L18" class="blob-num js-line-number js-blob-rnum" data-line-number="18"></td>
<td id="file-peoplerepository-cs-LC18" class="blob-code blob-code-inner js-file-line">    {</td>
</tr>
<tr>
<td id="file-peoplerepository-cs-L19" class="blob-num js-line-number js-blob-rnum" data-line-number="19"></td>
<td id="file-peoplerepository-cs-LC19" class="blob-code blob-code-inner js-file-line">        me.db.Insert(person);</td>
</tr>
<tr>
<td id="file-peoplerepository-cs-L20" class="blob-num js-line-number js-blob-rnum" data-line-number="20"></td>
<td id="file-peoplerepository-cs-LC20" class="blob-code blob-code-inner js-file-line">        return person.Id;</td>
</tr>
<tr>
<td id="file-peoplerepository-cs-L21" class="blob-num js-line-number js-blob-rnum" data-line-number="21"></td>
<td id="file-peoplerepository-cs-LC21" class="blob-code blob-code-inner js-file-line">    }</td>
</tr>
<tr>
<td id="file-peoplerepository-cs-L22" class="blob-num js-line-number js-blob-rnum" data-line-number="22"></td>
<td id="file-peoplerepository-cs-LC22" class="blob-code blob-code-inner js-file-line">
</td>
</tr>
<tr>
<td id="file-peoplerepository-cs-L23" class="blob-num js-line-number js-blob-rnum" data-line-number="23"></td>
<td id="file-peoplerepository-cs-LC23" class="blob-code blob-code-inner js-file-line">    public static Person GetPerson(int id)</td>
</tr>
<tr>
<td id="file-peoplerepository-cs-L24" class="blob-num js-line-number js-blob-rnum" data-line-number="24"></td>
<td id="file-peoplerepository-cs-LC24" class="blob-code blob-code-inner js-file-line">    {</td>
</tr>
<tr>
<td id="file-peoplerepository-cs-L25" class="blob-num js-line-number js-blob-rnum" data-line-number="25"></td>
<td id="file-peoplerepository-cs-LC25" class="blob-code blob-code-inner js-file-line">        return me.db.Get&lt;Person&gt;(p =&gt; p.Id == id);</td>
</tr>
<tr>
<td id="file-peoplerepository-cs-L26" class="blob-num js-line-number js-blob-rnum" data-line-number="26"></td>
<td id="file-peoplerepository-cs-LC26" class="blob-code blob-code-inner js-file-line">    }</td>
</tr>
<tr>
<td id="file-peoplerepository-cs-L27" class="blob-num js-line-number js-blob-rnum" data-line-number="27"></td>
<td id="file-peoplerepository-cs-LC27" class="blob-code blob-code-inner js-file-line">}</td>
</tr>
</table>
</div></div>
</p></div>
</div></div>
<div class="gist-meta">
        <a href="https://gist.github.com/dsibinski/c8256dbaaf5970a512062aa3a9fe5ad3/raw/5371465e526cbf189e77c720e9f97e2b37748042/PeopleRepository.cs" style="float:right" class="Link--inTextBlock">view raw</a><br />
        <a href="https://gist.github.com/dsibinski/c8256dbaaf5970a512062aa3a9fe5ad3#file-peoplerepository-cs" class="Link--inTextBlock"><br />
          PeopleRepository.cs<br />
        </a><br />
        hosted with &#10084; by <a class="Link--inTextBlock" href="https://github.com">GitHub</a>
      </div>
</p></div>
</div>
<p>I haven&#8217;t even created any abstract layer for the repository (e.g. interface), as I simply don&#8217;t know what approach I will use for the next entities. I&#8217;m not sure if the repository is the right choice. On the other hand, I don&#8217;t think such rather simple app requires something more. <span style="text-decoration: underline;"><strong>What do you think ?</p>
<p></strong></span></p>
<p>As you can see, <em>PeopleRepository</em> executes its static constructor when any of static methods is called for the first time, in which it instantiates <em>db</em> variable of type <em>SQLiteConnection</em>, giving it the path to db file we defined. If database file doesn&#8217;t exist, it will be automatically created. Then, <em>db.CreateTable&lt;Person&gt;()</em> creates <em>People</em> table if it doesn&#8217;t exist, according to what we defined in <em>Person</em> entity model.</p>
<p>Two static methods &#8211; <em>SavePerson</em> and <em>GetPerson </em>allow to save and retrieve <em>Person</em> entity to/from the database accordingly. The first one is additionally returning the integer <em>Id</em> of newly added row.</p>
<h2>Usage in the code</h2>
<p>I added two text fields to <em>MoneyBack</em> app to enter name and last name of person to be added and one button which actually allows to perform saving operation:</p>
<figure id="attachment_1088" aria-describedby="caption-attachment-1088" style="width: 233px" class="wp-caption aligncenter"><img data-recalc-dims="1" loading="lazy" decoding="async" data-attachment-id="1088" data-permalink="https://www.codejourney.net/using-sqlite-database-in-xamarin-android/moneyback_savingperson/" data-orig-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/MoneyBack_SavingPerson.png?fit=768%2C1280&amp;ssl=1" data-orig-size="768,1280" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="MoneyBack_SavingPerson" data-image-description="" data-image-caption="" data-large-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/MoneyBack_SavingPerson.png?fit=614%2C1024&amp;ssl=1" class=" wp-image-1088 aligncenter" src="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/MoneyBack_SavingPerson.png?resize=233%2C388&#038;ssl=1" alt="MoneyBack_SavingPerson.png" width="233" height="388" srcset="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/MoneyBack_SavingPerson.png?w=768&amp;ssl=1 768w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/MoneyBack_SavingPerson.png?resize=180%2C300&amp;ssl=1 180w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/MoneyBack_SavingPerson.png?resize=614%2C1024&amp;ssl=1 614w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/MoneyBack_SavingPerson.png?resize=720%2C1200&amp;ssl=1 720w" sizes="auto, (max-width: 233px) 100vw, 233px" /><figcaption id="caption-attachment-1088" class="wp-caption-text">Adding new Person</figcaption></figure>
<p>On clicking the button, the following method is executed:</p>
<p><style>.gist table { margin-bottom: 0; }</style>
<div style="tab-size: 8" id="gist45865616" class="gist">
<div class="gist-file" translate="no" data-color-mode="light" data-light-theme="light">
<div class="gist-data">
<div class="js-gist-file-update-container js-task-list-container">
<div id="file-addpersonbuttonclick-cs" class="file my-2">
<div itemprop="text"
      class="Box-body p-0 blob-wrapper data type-c  "
      style="overflow: auto" tabindex="0" role="region"
      aria-label="addPersonButtonClick.cs content, created by dsibinski on 09:58PM on March 19, 2017."
    ></p>
<div class="js-check-hidden-unicode js-blob-code-container blob-code-content">
<p>  <template class="js-file-alert-template"></p>
<div data-view-component="true" class="flash flash-warn flash-full d-flex flex-items-center">
  <svg aria-hidden="true" data-component="Octicon" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-alert">
    <path d="M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"></path>
</svg><br />
    <span><br />
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.<br />
      <a class="Link--inTextBlock" href="https://github.co/hiddenchars" target="_blank">Learn more about bidirectional Unicode characters</a><br />
    </span></p>
<div data-view-component="true" class="flash-action">        <a href="{{ revealButtonHref }}" data-view-component="true" class="btn-sm btn">    Show hidden characters<br />
</a>
</div>
</div>
<p></template><br />
<template class="js-line-alert-template"><br />
  <span aria-label="This line has hidden Unicode characters" data-view-component="true" class="line-alert tooltipped tooltipped-e"><br />
    <svg aria-hidden="true" data-component="Octicon" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-alert">
    <path d="M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"></path>
</svg><br />
</span></template></p>
<table data-hpc class="highlight tab-size js-file-line-container" data-tab-size="4" data-paste-markdown-skip data-tagsearch-path="addPersonButtonClick.cs">
<tr>
<td id="file-addpersonbuttonclick-cs-L1" class="blob-num js-line-number js-blob-rnum" data-line-number="1"></td>
<td id="file-addpersonbuttonclick-cs-LC1" class="blob-code blob-code-inner js-file-line">private void _btnAddPerson_Click(object sender, EventArgs e)</td>
</tr>
<tr>
<td id="file-addpersonbuttonclick-cs-L2" class="blob-num js-line-number js-blob-rnum" data-line-number="2"></td>
<td id="file-addpersonbuttonclick-cs-LC2" class="blob-code blob-code-inner js-file-line">{</td>
</tr>
<tr>
<td id="file-addpersonbuttonclick-cs-L3" class="blob-num js-line-number js-blob-rnum" data-line-number="3"></td>
<td id="file-addpersonbuttonclick-cs-LC3" class="blob-code blob-code-inner js-file-line">    var name = _inputName.Text;</td>
</tr>
<tr>
<td id="file-addpersonbuttonclick-cs-L4" class="blob-num js-line-number js-blob-rnum" data-line-number="4"></td>
<td id="file-addpersonbuttonclick-cs-LC4" class="blob-code blob-code-inner js-file-line">    var lastName = _inputLastName.Text;</td>
</tr>
<tr>
<td id="file-addpersonbuttonclick-cs-L5" class="blob-num js-line-number js-blob-rnum" data-line-number="5"></td>
<td id="file-addpersonbuttonclick-cs-LC5" class="blob-code blob-code-inner js-file-line">
</td>
</tr>
<tr>
<td id="file-addpersonbuttonclick-cs-L6" class="blob-num js-line-number js-blob-rnum" data-line-number="6"></td>
<td id="file-addpersonbuttonclick-cs-LC6" class="blob-code blob-code-inner js-file-line">    var id = PeopleRepository.SavePerson(new Person</td>
</tr>
<tr>
<td id="file-addpersonbuttonclick-cs-L7" class="blob-num js-line-number js-blob-rnum" data-line-number="7"></td>
<td id="file-addpersonbuttonclick-cs-LC7" class="blob-code blob-code-inner js-file-line">    {</td>
</tr>
<tr>
<td id="file-addpersonbuttonclick-cs-L8" class="blob-num js-line-number js-blob-rnum" data-line-number="8"></td>
<td id="file-addpersonbuttonclick-cs-LC8" class="blob-code blob-code-inner js-file-line">        Name = name,</td>
</tr>
<tr>
<td id="file-addpersonbuttonclick-cs-L9" class="blob-num js-line-number js-blob-rnum" data-line-number="9"></td>
<td id="file-addpersonbuttonclick-cs-LC9" class="blob-code blob-code-inner js-file-line">        LastName = lastName</td>
</tr>
<tr>
<td id="file-addpersonbuttonclick-cs-L10" class="blob-num js-line-number js-blob-rnum" data-line-number="10"></td>
<td id="file-addpersonbuttonclick-cs-LC10" class="blob-code blob-code-inner js-file-line">    });</td>
</tr>
<tr>
<td id="file-addpersonbuttonclick-cs-L11" class="blob-num js-line-number js-blob-rnum" data-line-number="11"></td>
<td id="file-addpersonbuttonclick-cs-LC11" class="blob-code blob-code-inner js-file-line">
</td>
</tr>
<tr>
<td id="file-addpersonbuttonclick-cs-L12" class="blob-num js-line-number js-blob-rnum" data-line-number="12"></td>
<td id="file-addpersonbuttonclick-cs-LC12" class="blob-code blob-code-inner js-file-line">    var person = PeopleRepository.GetPerson(id);</td>
</tr>
<tr>
<td id="file-addpersonbuttonclick-cs-L13" class="blob-num js-line-number js-blob-rnum" data-line-number="13"></td>
<td id="file-addpersonbuttonclick-cs-LC13" class="blob-code blob-code-inner js-file-line">
</td>
</tr>
<tr>
<td id="file-addpersonbuttonclick-cs-L14" class="blob-num js-line-number js-blob-rnum" data-line-number="14"></td>
<td id="file-addpersonbuttonclick-cs-LC14" class="blob-code blob-code-inner js-file-line">    if (person == null)</td>
</tr>
<tr>
<td id="file-addpersonbuttonclick-cs-L15" class="blob-num js-line-number js-blob-rnum" data-line-number="15"></td>
<td id="file-addpersonbuttonclick-cs-LC15" class="blob-code blob-code-inner js-file-line">        Toast.MakeText(this, $&quot;Person: Name={name}, LastName={lastName} wasn&#39;t properly saved!&quot;, ToastLength.Long).Show();</td>
</tr>
<tr>
<td id="file-addpersonbuttonclick-cs-L16" class="blob-num js-line-number js-blob-rnum" data-line-number="16"></td>
<td id="file-addpersonbuttonclick-cs-LC16" class="blob-code blob-code-inner js-file-line">    else</td>
</tr>
<tr>
<td id="file-addpersonbuttonclick-cs-L17" class="blob-num js-line-number js-blob-rnum" data-line-number="17"></td>
<td id="file-addpersonbuttonclick-cs-LC17" class="blob-code blob-code-inner js-file-line">        Toast.MakeText(this, $&quot;Person saved, details: {person}&quot;, ToastLength.Long).Show();</td>
</tr>
<tr>
<td id="file-addpersonbuttonclick-cs-L18" class="blob-num js-line-number js-blob-rnum" data-line-number="18"></td>
<td id="file-addpersonbuttonclick-cs-LC18" class="blob-code blob-code-inner js-file-line">
</td>
</tr>
<tr>
<td id="file-addpersonbuttonclick-cs-L19" class="blob-num js-line-number js-blob-rnum" data-line-number="19"></td>
<td id="file-addpersonbuttonclick-cs-LC19" class="blob-code blob-code-inner js-file-line">}</td>
</tr>
</table>
</div></div>
</p></div>
</div></div>
<div class="gist-meta">
        <a href="https://gist.github.com/dsibinski/4b9472f0a5f787a265fee0982dfcec96/raw/5b9be5b6240b78b71654a2a3651315b9e508b3c6/addPersonButtonClick.cs" style="float:right" class="Link--inTextBlock">view raw</a><br />
        <a href="https://gist.github.com/dsibinski/4b9472f0a5f787a265fee0982dfcec96#file-addpersonbuttonclick-cs" class="Link--inTextBlock"><br />
          addPersonButtonClick.cs<br />
        </a><br />
        hosted with &#10084; by <a class="Link--inTextBlock" href="https://github.com">GitHub</a>
      </div>
</p></div>
</div>
<p>&nbsp;</p>
<p>Here&#8217;s the result of clicking the button in the app:</p>
<figure id="attachment_1093" aria-describedby="caption-attachment-1093" style="width: 249px" class="wp-caption aligncenter"><img data-recalc-dims="1" loading="lazy" decoding="async" data-attachment-id="1093" data-permalink="https://www.codejourney.net/using-sqlite-database-in-xamarin-android/moneyback_savingperson_success/" data-orig-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/MoneyBack_SavingPerson_Success.png?fit=768%2C1280&amp;ssl=1" data-orig-size="768,1280" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="MoneyBack_SavingPerson_Success" data-image-description="" data-image-caption="" data-large-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/MoneyBack_SavingPerson_Success.png?fit=614%2C1024&amp;ssl=1" class=" wp-image-1093 aligncenter" src="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/MoneyBack_SavingPerson_Success.png?resize=249%2C415&#038;ssl=1" alt="MoneyBack_SavingPerson_Success.png" width="249" height="415" srcset="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/MoneyBack_SavingPerson_Success.png?w=768&amp;ssl=1 768w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/MoneyBack_SavingPerson_Success.png?resize=180%2C300&amp;ssl=1 180w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/MoneyBack_SavingPerson_Success.png?resize=614%2C1024&amp;ssl=1 614w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/MoneyBack_SavingPerson_Success.png?resize=720%2C1200&amp;ssl=1 720w" sizes="auto, (max-width: 249px) 100vw, 249px" /><figcaption id="caption-attachment-1093" class="wp-caption-text">Person saved successfully</figcaption></figure>
<p>As you can see, in the toast message received, <em>Id</em> of the <em>Person</em> added has value 3. That&#8217;s because when I launched the app previously I&#8217;ve already added two new people. It shows that the data is really persistently stored and doesn&#8217;t disappear when the app is restarted.</p>
<h2>Summary</h2>
<p>Today we&#8217;ve seen that using SQLite file database in Xamarin.Android is very easy. Thanks to SQLite.NET lightweight ORM library we were able to quickly start working with the db.</p>
<p>To make the code ready for &#8220;production&#8221; use, I should also make it thread-safe (more details e.g. <a href="https://developer.xamarin.com/guides/android/application_fundamentals/data/part_2_configuration/" target="_blank" rel="noopener">here</a>) and add unit tests (which I&#8217;m BTW not able to do for now, I&#8217;m getting <em>TargetInvocationException</em> when trying to run any NUnit tests adding <em>Unit Test App (Android)</em> project in VS 2017&#8230;).</p>
<p>I&#8217;m also not sure if repository is a proper concept for managing local db entities in Android project. <span style="text-decoration: underline;"><strong>If you have more experience, I&#8217;d be grateful to hear how it should be done in a really &#8220;Android way&#8221; <img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f642.png" alt="🙂" class="wp-smiley" style="height: 1em; max-height: 1em;" /></strong></span></p>
<p>The post <a href="https://www.codejourney.net/using-sqlite-database-in-xamarin-android/">Using SQLite database in Xamarin.Android</a> appeared first on <a href="https://www.codejourney.net">CodeJourney.net</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.codejourney.net/using-sqlite-database-in-xamarin-android/feed/</wfw:commentRss>
			<slash:comments>7</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">970</post-id>	</item>
		<item>
		<title>Simple habits for better productivity</title>
		<link>https://www.codejourney.net/simple-habits-for-better-productivity/</link>
					<comments>https://www.codejourney.net/simple-habits-for-better-productivity/#comments</comments>
		
		<dc:creator><![CDATA[Dawid Sibiński]]></dc:creator>
		<pubDate>Sat, 18 Mar 2017 21:23:04 +0000</pubDate>
				<category><![CDATA[Productivity]]></category>
		<category><![CDATA[dajsiepoznac2017]]></category>
		<guid isPermaLink="false">http://www.dsibinski.pl/?p=790</guid>

					<description><![CDATA[<p>It&#8217;s been a really tough week, so today I have a non-technical post for you. I&#8217;m going to move on with the project this weekend, so I can put some technical stuff here tomorrow. If you don&#8217;t really care about productivity, organization of your days, planning of tasks to be done during next X days,&#8230;</p>
<p>The post <a href="https://www.codejourney.net/simple-habits-for-better-productivity/">Simple habits for better productivity</a> appeared first on <a href="https://www.codejourney.net">CodeJourney.net</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>It&#8217;s been a really tough week, so today I have a non-technical post for you. I&#8217;m going to move on with the project this weekend, so I can put some technical stuff here tomorrow.</p>
<p>I<strong>f you don&#8217;t really care about productivity, organization of your days, planning of tasks to be done during next X days, this post is for you <img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f642.png" alt="🙂" class="wp-smiley" style="height: 1em; max-height: 1em;" /></strong> I totally didn&#8217;t care as well, but I felt a bit disorganized, I knew I could do more or at least be conscious of what I&#8217;m able to do and what I&#8217;m not. Finally, without studying anything like <a href="http://gettingthingsdone.com/" target="_blank" rel="noopener noreferrer">GTD</a>, I managed to introduce few simple <strong>habits </strong>to my everyday life that make my life easier, allow to complete some tasks faster and make me aware of what I have to do and when. I&#8217;d like to share those manners with you &#8211; maybe you&#8217;ll also find them helpful.<br />
<span id="more-790"></span></p>
<h2>Write everything down</h2>
<p>I heard from many people promoting better life organization, that writing things down is a very important step in being more productive. <strong>I definitely confirm</strong>. Writing things down cleans up your brain &#8211; it makes you not thinking about something you have to do &#8211; you just write it down and you are sure you&#8217;ll take care of it when the time comes. Such <em>brain-liberty </em>is<strong> very powerful</strong>. You can use your brain to think about the activity you&#8217;re actually working on at the moment, not having many &#8220;background&#8221; topics taking your brain&#8217;s &#8220;resources&#8221;.</p>
<p>Of course, you need to find a <em>place</em> in which you store your notes (or tasks &#8211; whatever you call it). For me, such <em>place </em>must meet the following requirements:</p>
<ul>
<li>be easy and fast to use in every situation</li>
<li>be accessible from every place, on every device</li>
<li>synchronizing across multiple devices</li>
<li>allowing to set deadlines for each task</li>
<li>giving a possibility to group tasks</li>
</ul>
<p>I&#8217;ve personally tested few todo lists / tasks management applications, including <a href="https://freedcamp.com/" target="_blank" rel="noopener noreferrer">Freedcamp</a>, <a href="https://en.todoist.com/" target="_blank" rel="noopener noreferrer">Todoist </a>or <a href="https://wunderslist.org/" target="_blank" rel="noopener noreferrer">Wunderlist</a>, but finally I found <strong>the perfect one &#8211; <a href="https://nozbe.com/" target="_blank" rel="noopener noreferrer">Nozbe. </a></strong>You can use <a href="https://Nozbe.com/?a=dawidsibinski@gmail.com" target="_blank" rel="noopener noreferrer">my affiliate link to register</a>, if you don&#8217;t mind <img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f609.png" alt="😉" class="wp-smiley" style="height: 1em; max-height: 1em;" /> As a bonus you&#8217;ll get one additional month if you decide to but a premium subscription. This project has been started and is developed by <a href="https://sliwinski.com/" target="_blank" rel="noopener noreferrer">Michał Śliwiński</a> who is productivity enthusiast. You can hear more about him and his project in <a href="http://devstyle.pl/2016/11/21/devtalk44-o-produktywnosci-z-michalem-sliwinskim/" target="_blank" rel="noopener noreferrer">DevTalk#44 podcast</a> (Polish only).</p>
<p>Nozbe allows to store tasks, set their deadlines, group them into projects and categories. It&#8217;s very simple and that&#8217;s the best about it. Free version allows to create maximally 5 projects, which is fair enough for me. Nozbe can be installed on Windows, Mac, Linux, Android or iOS, which allows for quick adding of tasks (there is a keyboard shortcut in Windows and notifications panel&#8217;s widget for Android). I&#8217;ve already been using it for few months and I&#8217;m very happy, it helps me a lot, really.</p>
<p>As soon as you have your <em>place</em> chosen, just work out that simple habit of writing things down (in case of Nozbe &#8211; adding them to your <em>Inbox</em>). When someone comes to you and asks you for something &#8211; write it down and say &#8220;Sure, added to my tasks list&#8221;. The person is then confident that you&#8217;ll take care of what he/she asks for and your brain is not occupied by it until you have time for it. When you&#8217;re on a meeting, and something to be done by you appears &#8211; write it down. If you suddenly recall you need to visit your dentist soon &#8211; write it down. Simple as that. <strong>You&#8217;ll see how much it helps</strong>.</p>
<h2>Review and plan your tasks</h2>
<p>As soon as you write everything down, try to work out the habit to review your list of tasks. If you have only one <em>place</em> in which you put everything you want to do, <strong>review such tasks <em>inbox</em> every day</strong> (e.g. in the evenings) and decide what to do with each task &#8211; either add it to the project/category and set the deadline, leave as it is if there&#8217;s nothing to do for now or delete if there&#8217;s actually nothing more to be done in a particular topic.</p>
<p>Apart from daily tasks review, perform a general, <strong>weekly-review of all your tasks</strong> in all projects/categories. I do such reviews every Sunday in the evening. It allows me to know the scope of things to be done on a higher level &#8211; across different projects and categories. I can also see if all the tasks are properly scheduled so I can manage to complete them. <strong>It&#8217;s better to plan than not, even if you finally don&#8217;t realize all tasks as planned</strong>.</p>
<h2>Create what-to-take lists</h2>
<p>When you pack for a business trip or holidays, don&#8217;t you forget something every time ? If yes, just create a check-box list containing all the things to take for particular type of trip. When you pack for the next time, add necessary things to it. If during the journey you notice you forgot something, add it to your list, so the next time you don&#8217;t forget it. <strong>Very simple, but saves a huge amount of time for packing</strong>.</p>
<p>I use <a href="https://keep.google.com/" target="_blank" rel="noopener noreferrer">Google Keep</a> for storing such lists. Here you can see how my list of the things to take for a business trip looks like:</p>
<figure id="attachment_878" aria-describedby="caption-attachment-878" style="width: 454px" class="wp-caption aligncenter"><img data-recalc-dims="1" loading="lazy" decoding="async" data-attachment-id="878" data-permalink="https://www.codejourney.net/simple-habits-for-better-productivity/thingstotake/" data-orig-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/thingsToTake.png?fit=603%2C615&amp;ssl=1" data-orig-size="603,615" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="thingsToTake" data-image-description="" data-image-caption="" data-large-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/thingsToTake.png?fit=603%2C615&amp;ssl=1" class="wp-image-878" src="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/thingsToTake.png?resize=454%2C463&#038;ssl=1" alt="thingsToTake.PNG" width="454" height="463" srcset="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/thingsToTake.png?w=603&amp;ssl=1 603w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/thingsToTake.png?resize=294%2C300&amp;ssl=1 294w" sizes="auto, (max-width: 454px) 100vw, 454px" /><figcaption id="caption-attachment-878" class="wp-caption-text">Business Trip &#8211; things to take</figcaption></figure>
<p>Having such <em>what-to-take</em> lists, I don&#8217;t wonder what I should take when I go for a business trip, what should I take when I go for holidays etc. Firstly packing is fast, and secondly I know I won&#8217;t forget anything. I totally recommend such approach.</p>
<h2>Create what-to-bring lists</h2>
<p>Does it sound familiar to you: your family members asking you &#8220;Oh, bring me that nice shirt when you visit me the next time if you&#8217;re not using it anymore!&#8221; ? Or your mum calling you and saying &#8220;I bought you a beautiful sweater, don&#8217;t forget to take it when you visit us!&#8221; ? If yes, then for each such place you visit (parent&#8217;s house, sister&#8217;s house, brother&#8217;s house etc.) <strong>create <em>what-to-bring</em> list</strong> and just add to it each thing you need to either bring from or take to there. Then when you spontaneously visit your sister, you just open the <em>sister&#8217;s home</em> list and see if you have something to bring her or to take with you. Again &#8211; simple, but helpful.</p>
<h2>Digitize your receipts</h2>
<p>Have you ever wasted few hours on looking for a receipt, when wanting to return something for a warranty repair ? Maybe you finally found the receipt, but it got blank ? If yes, <strong>move your receipts to the cloud</strong>. As soon as you buy something and you know the receipt or invoice may be useful in the future, make a photo of it using your smartphone and store it in some cloud files storage service.</p>
<p>I use Android application called <a href="https://play.google.com/store/apps/details?id=com.intsig.camscanner&amp;hl=en" target="_blank" rel="noopener noreferrer">CamScanner</a> for that &#8211; it allows to make a photo of a document, cut it, make it look as scanned and send to Google Drive, on which I store all my receipts and invoices. If you name your scanning files properly, it may save much of your time looking for a receipt or even make it possible at all to return something on a warranty repair if needed.</p>
<h2>Use calendar only for time-important events</h2>
<p>Before I discovered todo list apps and finally found Nozbe, I used to store everything I need to do in my <a href="https://calendar.google.com" target="_blank" rel="noopener noreferrer">Google Calendar</a>. I treated it as my <em>inbox</em> &#8211; if I had something to do, I added it as a reminder to the calendar and set its reminding date at certain time, usually in the evenings. It happened that around 9 PM I had 5 or 6 pending calendar reminders notifications on my phone. When I mistakenly cleaned up my notifications panel, all those reminders were lost.</p>
<p>Calendar &#8211; as its name suggests &#8211; should be used <strong>only for events for which the time really matters</strong>. For instance, when you arrange a doctor&#8217;s visit in a month or two for concrete day and hour, add it to your calendar setting event&#8217;s time to exactly your visit&#8217;s day and hour. If you need a reminder few days/hours before, don&#8217;t add another calendar event few days/hours before (as I used to do) reminding you about the event &#8211; instead &#8211; if you use Google Calendar &#8211; use &#8220;remind before&#8221; notifications:</p>
<figure id="attachment_933" aria-describedby="caption-attachment-933" style="width: 394px" class="wp-caption aligncenter"><img data-recalc-dims="1" loading="lazy" decoding="async" data-attachment-id="933" data-permalink="https://www.codejourney.net/simple-habits-for-better-productivity/googlecalendarnotifications/" data-orig-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/GoogleCalendarNotifications.png?fit=394%2C149&amp;ssl=1" data-orig-size="394,149" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="GoogleCalendarNotifications" data-image-description="" data-image-caption="" data-large-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/GoogleCalendarNotifications.png?fit=394%2C149&amp;ssl=1" class="wp-image-933 size-full" src="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/GoogleCalendarNotifications.png?resize=394%2C149&#038;ssl=1" alt="GoogleCalendarNotifications.PNG" width="394" height="149" srcset="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/GoogleCalendarNotifications.png?w=394&amp;ssl=1 394w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/GoogleCalendarNotifications.png?resize=300%2C113&amp;ssl=1 300w" sizes="auto, (max-width: 394px) 100vw, 394px" /><figcaption id="caption-attachment-933" class="wp-caption-text">Google Calendar &#8211; notifications</figcaption></figure>
<p>I also use Google Calendar for recurring events, for instance end of my car&#8217;s insurance or family members birthdays. <strong>The time is the most important for such events.</strong></p>
<h2>Summary</h2>
<p>I&#8217;m not any kind of productivity fanatic. I also didn&#8217;t read any productivity/GTD books or courses. I think that such involvement in productivity management is not needed in many cases. In this post I presented few simple habits I introduced in my life that help me to be a lot more productive and just make my life simpler. If you want, you can try them out yourself <img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f642.png" alt="🙂" class="wp-smiley" style="height: 1em; max-height: 1em;" /></p>
<p><span style="text-decoration: underline;"><strong>What productivity habits do you have ? What kind of tasks management tools/todo lists are you using ? Share your thoughts in the comments!</strong></span></p>
<p>The post <a href="https://www.codejourney.net/simple-habits-for-better-productivity/">Simple habits for better productivity</a> appeared first on <a href="https://www.codejourney.net">CodeJourney.net</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.codejourney.net/simple-habits-for-better-productivity/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">790</post-id>	</item>
		<item>
		<title>Solving performance issues with dotTrace</title>
		<link>https://www.codejourney.net/solving-performance-issues-with-dottrace/</link>
					<comments>https://www.codejourney.net/solving-performance-issues-with-dottrace/#comments</comments>
		
		<dc:creator><![CDATA[Dawid Sibiński]]></dc:creator>
		<pubDate>Sun, 12 Mar 2017 14:40:24 +0000</pubDate>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[dajsiepoznac2017]]></category>
		<category><![CDATA[performance]]></category>
		<guid isPermaLink="false">http://www.dsibinski.pl/?p=728</guid>

					<description><![CDATA[<p>If you&#8217;ve ever had any performance issues with your .NET applications, you may find this writing interesting. In this post I&#8217;d like to present to you a tool produced by JetBrains &#8211; dotTrace, showing how using only one of its functionalities can help in finding causes of performance issues in .NET applications. Performance issue on production Months&#8230;</p>
<p>The post <a href="https://www.codejourney.net/solving-performance-issues-with-dottrace/">Solving performance issues with dotTrace</a> appeared first on <a href="https://www.codejourney.net">CodeJourney.net</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>If you&#8217;ve ever had any performance issues with your .NET applications, you may find this writing interesting.</p>
<p>In this post I&#8217;d like to present to you a tool produced by JetBrains &#8211; <strong>dotTrace</strong>, showing how using only one of its functionalities can help in finding causes of performance issues in .NET applications.<br />
<span id="more-728"></span></p>
<h2>Performance issue on production</h2>
<p>Months ago some of your colleagues implemented an application and delivered it to the Customer. The app is &#8220;Countries and Cities Manager&#8221;, which is used by some administrator working in local government unit. That&#8217;s how it looks:</p>
<figure id="attachment_735" aria-describedby="caption-attachment-735" style="width: 380px" class="wp-caption aligncenter"><a href="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/countriesAndCitiesManager.png?ssl=1"><img data-recalc-dims="1" loading="lazy" decoding="async" data-attachment-id="735" data-permalink="https://www.codejourney.net/solving-performance-issues-with-dottrace/countriesandcitiesmanager/" data-orig-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/countriesAndCitiesManager.png?fit=646%2C232&amp;ssl=1" data-orig-size="646,232" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="countriesAndCitiesManager" data-image-description="" data-image-caption="" data-large-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/countriesAndCitiesManager.png?fit=646%2C232&amp;ssl=1" class="wp-image-735 " src="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/countriesAndCitiesManager.png?resize=380%2C137&#038;ssl=1" alt="" width="380" height="137" srcset="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/countriesAndCitiesManager.png?resize=300%2C108&amp;ssl=1 300w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/countriesAndCitiesManager.png?w=646&amp;ssl=1 646w" sizes="auto, (max-width: 380px) 100vw, 380px" /></a><figcaption id="caption-attachment-735" class="wp-caption-text">Countries and Cities Manager</figcaption></figure>
<p>That&#8217;s cool, isn&#8217;t it ? This &#8220;administration panel&#8221; allows to add a new city to the country. User fills name of the city and provides ISO code of the country considered. You may think &#8220;who would ever use it and for what?&#8221;. True. But first of all, this is just an example <img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f642.png" alt="🙂" class="wp-smiley" style="height: 1em; max-height: 1em;" /> , and secondly, imagine that Russia annexes some big European country. What happens then ? User administrating local government system must use your manager application to insert hundreds or thousands of new cities in Russia. Gotcha!</p>
<p>The next day you receive a ticket in your company&#8217;s issues tracking system. Taking into consideration that an average number of cities in east-European countries is ~600, the ticket&#8217;s priority is set to &#8220;Blocking&#8221;. The description of the issue is:</p>
<ol>
<li>User fills the &#8220;City&#8221; and &#8220;Country ISO Code&#8221;, clicks &#8220;Add city&#8221;</li>
<li>Waits for 10 seconds&#8230;</li>
<li>Waits for 20 seconds&#8230;</li>
<li>Waits for 30 seconds&#8230;</li>
<li>Error message received:<br />
<figure id="attachment_738" aria-describedby="caption-attachment-738" style="width: 395px" class="wp-caption alignnone"><img data-recalc-dims="1" loading="lazy" decoding="async" data-attachment-id="738" data-permalink="https://www.codejourney.net/solving-performance-issues-with-dottrace/errorisonotfound/" data-orig-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/errorISONotFound.png?fit=702%2C319&amp;ssl=1" data-orig-size="702,319" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="errorISONotFound" data-image-description="" data-image-caption="" data-large-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/errorISONotFound.png?fit=702%2C319&amp;ssl=1" class="wp-image-738 " src="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/errorISONotFound.png?resize=395%2C179&#038;ssl=1" alt="" width="395" height="179" srcset="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/errorISONotFound.png?resize=300%2C136&amp;ssl=1 300w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/errorISONotFound.png?w=702&amp;ssl=1 702w" sizes="auto, (max-width: 395px) 100vw, 395px" /><figcaption id="caption-attachment-738" class="wp-caption-text">ISO not found</figcaption></figure>
</li>
<li>User corrects &#8220;RU&#8221; to &#8220;RUS&#8221;
<div class="mceTemp"> </div>
</li>
<li>Waits for 10 seconds&#8230;</li>
<li>Waits for 20 seconds&#8230;</li>
<li>Waits for 30 seconds&#8230;</li>
<li> City added!</li>
<li>Scenario repeats for each new city to be added. Performance is unacceptable.</li>
</ol>
<p>Initially you have no idea what could be the reason. Such simple operation and such terrible performance? Let&#8217;s see&#8230;</p>
<h2>Looking for issue with dotTrace profiling</h2>
<p>In such cases, especially if I don&#8217;t know the code of the application considered, the very first thing I do it to use <a href="https://www.jetbrains.com/profiler/" target="_blank" rel="noopener"><strong>dotTrace</strong></a> in order to profile the application when executing bad-performance actions. It provides many features, including:</p>
<ul>
<li>detecting performance bottlenecks in .NET applications</li>
<li>getting information about calls execution times</li>
<li>analyzing calls order on a timeline</li>
<li>profilling SQL queries and HTTP requests</li>
<li>profiling unit tests</li>
<li>&#8230; and <a href="https://www.jetbrains.com/profiler/" target="_blank" rel="noopener">many more</a>.</li>
</ul>
<p>We will use only the simplest profiling mode which is called <em>Sampling</em>.</p>
<p>After you <a href="https://www.jetbrains.com/profiler/" target="_blank" rel="noopener">downloaded and installed dotTrace</a>, launch the application you want to profile first. Then, launch <em>dotTrace </em>and in <em>Attach to Process</em> section find and select process of your app and select <em>Sampling</em> mode:</p>
<figure id="attachment_740" aria-describedby="caption-attachment-740" style="width: 514px" class="wp-caption aligncenter"><a href="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/dotTrace_attaching.png?ssl=1"><img data-recalc-dims="1" loading="lazy" decoding="async" data-attachment-id="740" data-permalink="https://www.codejourney.net/solving-performance-issues-with-dottrace/dottrace_attaching/" data-orig-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/dotTrace_attaching.png?fit=1245%2C583&amp;ssl=1" data-orig-size="1245,583" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="dotTrace_attaching" data-image-description="" data-image-caption="" data-large-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/dotTrace_attaching.png?fit=1024%2C480&amp;ssl=1" class="wp-image-740" src="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/dotTrace_attaching.png?resize=514%2C240&#038;ssl=1" alt="" width="514" height="240" srcset="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/dotTrace_attaching.png?resize=300%2C140&amp;ssl=1 300w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/dotTrace_attaching.png?resize=768%2C360&amp;ssl=1 768w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/dotTrace_attaching.png?resize=1024%2C480&amp;ssl=1 1024w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/dotTrace_attaching.png?resize=720%2C337&amp;ssl=1 720w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/dotTrace_attaching.png?w=1245&amp;ssl=1 1245w" sizes="auto, (max-width: 514px) 100vw, 514px" /></a><figcaption id="caption-attachment-740" class="wp-caption-text">dotTrace &#8211; Sampling mode</figcaption></figure>
<p>Then, click &#8220;Run&#8221; button just below <em>Sampling </em>mode selection &#8211; you&#8217;ll see the profiling session has started:</p>
<figure id="attachment_742" aria-describedby="caption-attachment-742" style="width: 402px" class="wp-caption aligncenter"><a href="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/dotTrace_session_running.png?ssl=1"><img data-recalc-dims="1" loading="lazy" decoding="async" data-attachment-id="742" data-permalink="https://www.codejourney.net/solving-performance-issues-with-dottrace/dottrace_session_running/" data-orig-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/dotTrace_session_running.png?fit=826%2C122&amp;ssl=1" data-orig-size="826,122" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="dotTrace_session_running" data-image-description="" data-image-caption="&lt;p&gt;dotTrace session&lt;/p&gt;
" data-large-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/dotTrace_session_running.png?fit=826%2C122&amp;ssl=1" class=" wp-image-742" src="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/dotTrace_session_running.png?resize=402%2C59&#038;ssl=1" alt="" width="402" height="59" srcset="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/dotTrace_session_running.png?resize=300%2C44&amp;ssl=1 300w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/dotTrace_session_running.png?resize=768%2C113&amp;ssl=1 768w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/dotTrace_session_running.png?resize=720%2C106&amp;ssl=1 720w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/dotTrace_session_running.png?w=826&amp;ssl=1 826w" sizes="auto, (max-width: 402px) 100vw, 402px" /></a><figcaption id="caption-attachment-742" class="wp-caption-text">dotTrace session</figcaption></figure>
<p>Next, go to your application and execute bad-performance action. In our case, we click on &#8220;Add city&#8221; button:</p>
<figure id="attachment_779" aria-describedby="caption-attachment-779" style="width: 460px" class="wp-caption aligncenter"><a href="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/addCity_Click-3.png?ssl=1"><img data-recalc-dims="1" loading="lazy" decoding="async" data-attachment-id="779" data-permalink="https://www.codejourney.net/solving-performance-issues-with-dottrace/addcity_click-4/" data-orig-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/addCity_Click-3.png?fit=430%2C154&amp;ssl=1" data-orig-size="430,154" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="addCity_Click" data-image-description="" data-image-caption="&lt;p&gt;Add City clicked&lt;/p&gt;
" data-large-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/addCity_Click-3.png?fit=430%2C154&amp;ssl=1" class=" wp-image-779" src="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/addCity_Click-3.png?resize=460%2C164&#038;ssl=1" alt="" width="460" height="164" srcset="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/addCity_Click-3.png?resize=300%2C107&amp;ssl=1 300w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/addCity_Click-3.png?w=430&amp;ssl=1 430w" sizes="auto, (max-width: 460px) 100vw, 460px" /></a><figcaption id="caption-attachment-779" class="wp-caption-text">Add City clicked</figcaption></figure>
<p>App is not responding &#8211; cool! Now we wait those 10, 20, 30 seconds until we get the error message described by the user. To be sure what&#8217;s happening, we can click the button few more times (maybe the next executions are better?). I clicked it 3 times are the times were pretty the same.</p>
<p>That&#8217;s the end of our bad-performance action, so in <em>dotTrace</em> session&#8217;s window click &#8220;Get Snapshot and Wait&#8221;:</p>
<figure id="attachment_744" aria-describedby="caption-attachment-744" style="width: 460px" class="wp-caption aligncenter"><a href="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/dotTrace_GetSnapshot.png?ssl=1"><img data-recalc-dims="1" loading="lazy" decoding="async" data-attachment-id="744" data-permalink="https://www.codejourney.net/solving-performance-issues-with-dottrace/dottrace_getsnapshot/" data-orig-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/dotTrace_GetSnapshot.png?fit=828%2C159&amp;ssl=1" data-orig-size="828,159" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="dotTrace_GetSnapshot" data-image-description="&lt;p&gt;dotTrace &amp;#8211; getting snapshot&lt;/p&gt;
" data-image-caption="" data-large-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/dotTrace_GetSnapshot.png?fit=828%2C159&amp;ssl=1" class="wp-image-744 " src="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/dotTrace_GetSnapshot.png?resize=460%2C89&#038;ssl=1" alt="" width="460" height="89" srcset="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/dotTrace_GetSnapshot.png?resize=300%2C58&amp;ssl=1 300w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/dotTrace_GetSnapshot.png?resize=768%2C147&amp;ssl=1 768w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/dotTrace_GetSnapshot.png?resize=720%2C138&amp;ssl=1 720w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/dotTrace_GetSnapshot.png?w=828&amp;ssl=1 828w" sizes="auto, (max-width: 460px) 100vw, 460px" /></a><figcaption id="caption-attachment-744" class="wp-caption-text">dotTrace &#8211; getting snapshot</figcaption></figure>
<p>After few seconds, <em>JetBrains dotTrace Performance Viewer</em> opens. Open &#8220;Threads Tree&#8221; on &#8220;All Calls&#8221; tab:</p>
<figure id="attachment_747" aria-describedby="caption-attachment-747" style="width: 435px" class="wp-caption aligncenter"><a href="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/perfViewer_ThreadsTree.png?ssl=1"><img data-recalc-dims="1" loading="lazy" decoding="async" data-attachment-id="747" data-permalink="https://www.codejourney.net/solving-performance-issues-with-dottrace/perfviewer_threadstree/" data-orig-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/perfViewer_ThreadsTree.png?fit=709%2C326&amp;ssl=1" data-orig-size="709,326" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="perfViewer_ThreadsTree" data-image-description="" data-image-caption="&lt;p&gt;Threads Tree&lt;/p&gt;
" data-large-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/perfViewer_ThreadsTree.png?fit=709%2C326&amp;ssl=1" class=" wp-image-747" src="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/perfViewer_ThreadsTree.png?resize=435%2C200&#038;ssl=1" alt="" width="435" height="200" srcset="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/perfViewer_ThreadsTree.png?resize=300%2C138&amp;ssl=1 300w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/perfViewer_ThreadsTree.png?w=709&amp;ssl=1 709w" sizes="auto, (max-width: 435px) 100vw, 435px" /></a><figcaption id="caption-attachment-747" class="wp-caption-text">Threads Tree</figcaption></figure>
<p>In this section we normally see all the threads running within our application during profiling time. We had only one thread, so let&#8217;s expand the details to see the time and percentage duration of particular calls from the calls stack:</p>
<figure id="attachment_748" aria-describedby="caption-attachment-748" style="width: 665px" class="wp-caption aligncenter"><a href="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/perfViewer_LongestCall.png?ssl=1"><img data-recalc-dims="1" loading="lazy" decoding="async" data-attachment-id="748" data-permalink="https://www.codejourney.net/solving-performance-issues-with-dottrace/perfviewer_longestcall/" data-orig-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/perfViewer_LongestCall.png?fit=1269%2C311&amp;ssl=1" data-orig-size="1269,311" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="perfViewer_LongestCall" data-image-description="" data-image-caption="&lt;p&gt;Calls duration in performance viewer&lt;/p&gt;
" data-large-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/perfViewer_LongestCall.png?fit=1024%2C251&amp;ssl=1" class=" wp-image-748" src="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/perfViewer_LongestCall.png?resize=665%2C164&#038;ssl=1" alt="" width="665" height="164" srcset="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/perfViewer_LongestCall.png?resize=300%2C74&amp;ssl=1 300w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/perfViewer_LongestCall.png?resize=768%2C188&amp;ssl=1 768w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/perfViewer_LongestCall.png?resize=1024%2C251&amp;ssl=1 1024w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/perfViewer_LongestCall.png?resize=720%2C176&amp;ssl=1 720w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/perfViewer_LongestCall.png?w=1269&amp;ssl=1 1269w" sizes="auto, (max-width: 665px) 100vw, 665px" /></a><figcaption id="caption-attachment-748" class="wp-caption-text">Calls duration in performance viewer</figcaption></figure>
<p>At this moment, without even opening the code, we already see that method called <em>GetAllEuropeanCountries</em> takes <strong>83.63%</strong> of our thread&#8217;s execution time. What&#8217;s more, we can see that this method is defined in <strong><em>CountriesCitiesDbService</em></strong><strong> </strong>which apperently retrieves list of European countries from the database or some external source.</p>
<p>The most percipient of you probably noticed there is <em>Thread.Sleep(Int32) </em>method called one level down &#8211; yes, that&#8217;s for example&#8217;s purposes <img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f642.png" alt="🙂" class="wp-smiley" style="height: 1em; max-height: 1em;" /> , but in real world this would be a database query or a web service call here. The most important is that we know what takes the longest during our operation. Let&#8217;s now fix it!</p>
<h2>Fixing the issue</h2>
<p>Let&#8217;s open <em>CountriesCitiesManager</em> solution and use the knowledge we already have from the profiling. We go to the <em>AddNewCity(String, String)</em> method, in which the method for getting countries was called (this is deductible from the calls tree in performance viewer). Here&#8217;s the code:</p>
<p><style>.gist table { margin-bottom: 0; }</style>
<div style="tab-size: 8" id="gist45629395" class="gist">
<div class="gist-file" translate="no" data-color-mode="light" data-light-theme="light">
<div class="gist-data">
<div class="js-gist-file-update-container js-task-list-container">
<div id="file-addnewcity-cs" class="file my-2">
<div itemprop="text"
      class="Box-body p-0 blob-wrapper data type-c  "
      style="overflow: auto" tabindex="0" role="region"
      aria-label="AddNewCity.cs content, created by dsibinski on 01:02PM on March 12, 2017."
    ></p>
<div class="js-check-hidden-unicode js-blob-code-container blob-code-content">
<p>  <template class="js-file-alert-template"></p>
<div data-view-component="true" class="flash flash-warn flash-full d-flex flex-items-center">
  <svg aria-hidden="true" data-component="Octicon" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-alert">
    <path d="M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"></path>
</svg><br />
    <span><br />
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.<br />
      <a class="Link--inTextBlock" href="https://github.co/hiddenchars" target="_blank">Learn more about bidirectional Unicode characters</a><br />
    </span></p>
<div data-view-component="true" class="flash-action">        <a href="{{ revealButtonHref }}" data-view-component="true" class="btn-sm btn">    Show hidden characters<br />
</a>
</div>
</div>
<p></template><br />
<template class="js-line-alert-template"><br />
  <span aria-label="This line has hidden Unicode characters" data-view-component="true" class="line-alert tooltipped tooltipped-e"><br />
    <svg aria-hidden="true" data-component="Octicon" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-alert">
    <path d="M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"></path>
</svg><br />
</span></template></p>
<table data-hpc class="highlight tab-size js-file-line-container" data-tab-size="4" data-paste-markdown-skip data-tagsearch-path="AddNewCity.cs">
<tr>
<td id="file-addnewcity-cs-L1" class="blob-num js-line-number js-blob-rnum" data-line-number="1"></td>
<td id="file-addnewcity-cs-LC1" class="blob-code blob-code-inner js-file-line">private bool AddNewCity(string cityName, string countryIso)</td>
</tr>
<tr>
<td id="file-addnewcity-cs-L2" class="blob-num js-line-number js-blob-rnum" data-line-number="2"></td>
<td id="file-addnewcity-cs-LC2" class="blob-code blob-code-inner js-file-line">{</td>
</tr>
<tr>
<td id="file-addnewcity-cs-L3" class="blob-num js-line-number js-blob-rnum" data-line-number="3"></td>
<td id="file-addnewcity-cs-LC3" class="blob-code blob-code-inner js-file-line">    var city = CountriesCitiesDbService.GetNewCity();</td>
</tr>
<tr>
<td id="file-addnewcity-cs-L4" class="blob-num js-line-number js-blob-rnum" data-line-number="4"></td>
<td id="file-addnewcity-cs-LC4" class="blob-code blob-code-inner js-file-line">    var europeanCountries = CountriesCitiesDbService.GetAllEuropeanCountries();</td>
</tr>
<tr>
<td id="file-addnewcity-cs-L5" class="blob-num js-line-number js-blob-rnum" data-line-number="5"></td>
<td id="file-addnewcity-cs-LC5" class="blob-code blob-code-inner js-file-line">    var country = europeanCountries.FirstOrDefault(ec =&gt; ec.IsoCode.Equals(countryIso));</td>
</tr>
<tr>
<td id="file-addnewcity-cs-L6" class="blob-num js-line-number js-blob-rnum" data-line-number="6"></td>
<td id="file-addnewcity-cs-LC6" class="blob-code blob-code-inner js-file-line">
</td>
</tr>
<tr>
<td id="file-addnewcity-cs-L7" class="blob-num js-line-number js-blob-rnum" data-line-number="7"></td>
<td id="file-addnewcity-cs-LC7" class="blob-code blob-code-inner js-file-line">    if (country == null)</td>
</tr>
<tr>
<td id="file-addnewcity-cs-L8" class="blob-num js-line-number js-blob-rnum" data-line-number="8"></td>
<td id="file-addnewcity-cs-LC8" class="blob-code blob-code-inner js-file-line">        throw new ArgumentException($&quot;Country with ISO Code {countryIso} does not exist!&quot;);</td>
</tr>
<tr>
<td id="file-addnewcity-cs-L9" class="blob-num js-line-number js-blob-rnum" data-line-number="9"></td>
<td id="file-addnewcity-cs-LC9" class="blob-code blob-code-inner js-file-line">
</td>
</tr>
<tr>
<td id="file-addnewcity-cs-L10" class="blob-num js-line-number js-blob-rnum" data-line-number="10"></td>
<td id="file-addnewcity-cs-LC10" class="blob-code blob-code-inner js-file-line">    city.Name = cityName;</td>
</tr>
<tr>
<td id="file-addnewcity-cs-L11" class="blob-num js-line-number js-blob-rnum" data-line-number="11"></td>
<td id="file-addnewcity-cs-LC11" class="blob-code blob-code-inner js-file-line">    city.Country = country;</td>
</tr>
<tr>
<td id="file-addnewcity-cs-L12" class="blob-num js-line-number js-blob-rnum" data-line-number="12"></td>
<td id="file-addnewcity-cs-LC12" class="blob-code blob-code-inner js-file-line">
</td>
</tr>
<tr>
<td id="file-addnewcity-cs-L13" class="blob-num js-line-number js-blob-rnum" data-line-number="13"></td>
<td id="file-addnewcity-cs-LC13" class="blob-code blob-code-inner js-file-line">    CountriesCitiesDbService.SaveCity(city);</td>
</tr>
<tr>
<td id="file-addnewcity-cs-L14" class="blob-num js-line-number js-blob-rnum" data-line-number="14"></td>
<td id="file-addnewcity-cs-LC14" class="blob-code blob-code-inner js-file-line">    return true;</td>
</tr>
<tr>
<td id="file-addnewcity-cs-L15" class="blob-num js-line-number js-blob-rnum" data-line-number="15"></td>
<td id="file-addnewcity-cs-LC15" class="blob-code blob-code-inner js-file-line">
</td>
</tr>
<tr>
<td id="file-addnewcity-cs-L16" class="blob-num js-line-number js-blob-rnum" data-line-number="16"></td>
<td id="file-addnewcity-cs-LC16" class="blob-code blob-code-inner js-file-line">}</td>
</tr>
</table>
</div></div>
</p></div>
</div></div>
<div class="gist-meta">
        <a href="https://gist.github.com/dsibinski/9e459fb3d6cd16567fc09f90ba948efb/raw/716d4066a91294a0b47dc8a30432887a07906b4e/AddNewCity.cs" style="float:right" class="Link--inTextBlock">view raw</a><br />
        <a href="https://gist.github.com/dsibinski/9e459fb3d6cd16567fc09f90ba948efb#file-addnewcity-cs" class="Link--inTextBlock"><br />
          AddNewCity.cs<br />
        </a><br />
        hosted with &#10084; by <a class="Link--inTextBlock" href="https://github.com">GitHub</a>
      </div>
</p></div>
</div>
<p><em>AddNewCity</em> method is called every time the &#8220;Add city&#8221; button is pressed. In line number 4. we are getting the list of all 46 European countries:</p>
<figure id="attachment_754" aria-describedby="caption-attachment-754" style="width: 483px" class="wp-caption aligncenter"><a href="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/getAllEUCountriesList.png?ssl=1"><img data-recalc-dims="1" loading="lazy" decoding="async" data-attachment-id="754" data-permalink="https://www.codejourney.net/solving-performance-issues-with-dottrace/getalleucountrieslist/" data-orig-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/getAllEUCountriesList.png?fit=839%2C63&amp;ssl=1" data-orig-size="839,63" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="getAllEUCountriesList" data-image-description="" data-image-caption="&lt;p&gt;Variable storing 46 EU countries&lt;/p&gt;
" data-large-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/getAllEUCountriesList.png?fit=839%2C63&amp;ssl=1" class="wp-image-754 " src="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/getAllEUCountriesList.png?resize=483%2C37&#038;ssl=1" alt="" width="483" height="37" srcset="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/getAllEUCountriesList.png?resize=300%2C23&amp;ssl=1 300w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/getAllEUCountriesList.png?resize=768%2C58&amp;ssl=1 768w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/getAllEUCountriesList.png?resize=720%2C54&amp;ssl=1 720w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/getAllEUCountriesList.png?w=839&amp;ssl=1 839w" sizes="auto, (max-width: 483px) 100vw, 483px" /></a><figcaption id="caption-attachment-754" class="wp-caption-text">Variable storing 46 EU countries</figcaption></figure>
<p>How probable it is that the number of countries in Europe changes during our application&#8217;s runtime? Very close to 0, I&#8217;d say. <strong>So there is totally no sense in retrieving the list of EU countries (from the DB, web service or whatever) every time the button is clicked!</p>
<p></strong></p>
<p>We need to cache this list somehow. Let&#8217;s simply extract the variable for storing EU countries as read-only class property initialized only when used for the first time:</p>
<p><style>.gist table { margin-bottom: 0; }</style>
<div style="tab-size: 8" id="gist45630185" class="gist">
<div class="gist-file" translate="no" data-color-mode="light" data-light-theme="light">
<div class="gist-data">
<div class="js-gist-file-update-container js-task-list-container">
<div id="file-europeancitiesproperty-cs" class="file my-2">
<div itemprop="text"
      class="Box-body p-0 blob-wrapper data type-c  "
      style="overflow: auto" tabindex="0" role="region"
      aria-label="EuropeanCitiesProperty.cs content, created by dsibinski on 01:50PM on March 12, 2017."
    ></p>
<div class="js-check-hidden-unicode js-blob-code-container blob-code-content">
<p>  <template class="js-file-alert-template"></p>
<div data-view-component="true" class="flash flash-warn flash-full d-flex flex-items-center">
  <svg aria-hidden="true" data-component="Octicon" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-alert">
    <path d="M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"></path>
</svg><br />
    <span><br />
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.<br />
      <a class="Link--inTextBlock" href="https://github.co/hiddenchars" target="_blank">Learn more about bidirectional Unicode characters</a><br />
    </span></p>
<div data-view-component="true" class="flash-action">        <a href="{{ revealButtonHref }}" data-view-component="true" class="btn-sm btn">    Show hidden characters<br />
</a>
</div>
</div>
<p></template><br />
<template class="js-line-alert-template"><br />
  <span aria-label="This line has hidden Unicode characters" data-view-component="true" class="line-alert tooltipped tooltipped-e"><br />
    <svg aria-hidden="true" data-component="Octicon" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-alert">
    <path d="M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"></path>
</svg><br />
</span></template></p>
<table data-hpc class="highlight tab-size js-file-line-container" data-tab-size="4" data-paste-markdown-skip data-tagsearch-path="EuropeanCitiesProperty.cs">
<tr>
<td id="file-europeancitiesproperty-cs-L1" class="blob-num js-line-number js-blob-rnum" data-line-number="1"></td>
<td id="file-europeancitiesproperty-cs-LC1" class="blob-code blob-code-inner js-file-line">private List&lt;Country&gt; _europeanCountries;</td>
</tr>
<tr>
<td id="file-europeancitiesproperty-cs-L2" class="blob-num js-line-number js-blob-rnum" data-line-number="2"></td>
<td id="file-europeancitiesproperty-cs-LC2" class="blob-code blob-code-inner js-file-line">
</td>
</tr>
<tr>
<td id="file-europeancitiesproperty-cs-L3" class="blob-num js-line-number js-blob-rnum" data-line-number="3"></td>
<td id="file-europeancitiesproperty-cs-LC3" class="blob-code blob-code-inner js-file-line">public List&lt;Country&gt; EuropeanCountries =&gt; </td>
</tr>
<tr>
<td id="file-europeancitiesproperty-cs-L4" class="blob-num js-line-number js-blob-rnum" data-line-number="4"></td>
<td id="file-europeancitiesproperty-cs-LC4" class="blob-code blob-code-inner js-file-line">    _europeanCountries ?? (_europeanCountries = CountriesCitiesDbService.GetAllEuropeanCountries());</td>
</tr>
</table>
</div></div>
</p></div>
</div></div>
<div class="gist-meta">
        <a href="https://gist.github.com/dsibinski/5c1d7f2e77f61ac081d6b20f4cf1f86b/raw/4e3bc93235f938e4e0b2f0ac9473186230e3fe2f/EuropeanCitiesProperty.cs" style="float:right" class="Link--inTextBlock">view raw</a><br />
        <a href="https://gist.github.com/dsibinski/5c1d7f2e77f61ac081d6b20f4cf1f86b#file-europeancitiesproperty-cs" class="Link--inTextBlock"><br />
          EuropeanCitiesProperty.cs<br />
        </a><br />
        hosted with &#10084; by <a class="Link--inTextBlock" href="https://github.com">GitHub</a>
      </div>
</p></div>
</div>
<p>and use it in <em>AddNewCity</em> method:</p>
<p><style>.gist table { margin-bottom: 0; }</style>
<div style="tab-size: 8" id="gist45630262" class="gist">
<div class="gist-file" translate="no" data-color-mode="light" data-light-theme="light">
<div class="gist-data">
<div class="js-gist-file-update-container js-task-list-container">
<div id="file-addnewcity_corrected-cs" class="file my-2">
<div itemprop="text"
      class="Box-body p-0 blob-wrapper data type-c  "
      style="overflow: auto" tabindex="0" role="region"
      aria-label="AddNewCity_Corrected.cs content, created by dsibinski on 01:54PM on March 12, 2017."
    ></p>
<div class="js-check-hidden-unicode js-blob-code-container blob-code-content">
<p>  <template class="js-file-alert-template"></p>
<div data-view-component="true" class="flash flash-warn flash-full d-flex flex-items-center">
  <svg aria-hidden="true" data-component="Octicon" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-alert">
    <path d="M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"></path>
</svg><br />
    <span><br />
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.<br />
      <a class="Link--inTextBlock" href="https://github.co/hiddenchars" target="_blank">Learn more about bidirectional Unicode characters</a><br />
    </span></p>
<div data-view-component="true" class="flash-action">        <a href="{{ revealButtonHref }}" data-view-component="true" class="btn-sm btn">    Show hidden characters<br />
</a>
</div>
</div>
<p></template><br />
<template class="js-line-alert-template"><br />
  <span aria-label="This line has hidden Unicode characters" data-view-component="true" class="line-alert tooltipped tooltipped-e"><br />
    <svg aria-hidden="true" data-component="Octicon" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-alert">
    <path d="M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"></path>
</svg><br />
</span></template></p>
<table data-hpc class="highlight tab-size js-file-line-container" data-tab-size="4" data-paste-markdown-skip data-tagsearch-path="AddNewCity_Corrected.cs">
<tr>
<td id="file-addnewcity_corrected-cs-L1" class="blob-num js-line-number js-blob-rnum" data-line-number="1"></td>
<td id="file-addnewcity_corrected-cs-LC1" class="blob-code blob-code-inner js-file-line">private bool AddNewCity(string cityName, string countryIso)</td>
</tr>
<tr>
<td id="file-addnewcity_corrected-cs-L2" class="blob-num js-line-number js-blob-rnum" data-line-number="2"></td>
<td id="file-addnewcity_corrected-cs-LC2" class="blob-code blob-code-inner js-file-line">{</td>
</tr>
<tr>
<td id="file-addnewcity_corrected-cs-L3" class="blob-num js-line-number js-blob-rnum" data-line-number="3"></td>
<td id="file-addnewcity_corrected-cs-LC3" class="blob-code blob-code-inner js-file-line">    var city = CountriesCitiesDbService.GetNewCity();</td>
</tr>
<tr>
<td id="file-addnewcity_corrected-cs-L4" class="blob-num js-line-number js-blob-rnum" data-line-number="4"></td>
<td id="file-addnewcity_corrected-cs-LC4" class="blob-code blob-code-inner js-file-line">
</td>
</tr>
<tr>
<td id="file-addnewcity_corrected-cs-L5" class="blob-num js-line-number js-blob-rnum" data-line-number="5"></td>
<td id="file-addnewcity_corrected-cs-LC5" class="blob-code blob-code-inner js-file-line">    var country = EuropeanCountries.FirstOrDefault(ec =&gt; ec.IsoCode.Equals(countryIso));</td>
</tr>
<tr>
<td id="file-addnewcity_corrected-cs-L6" class="blob-num js-line-number js-blob-rnum" data-line-number="6"></td>
<td id="file-addnewcity_corrected-cs-LC6" class="blob-code blob-code-inner js-file-line">    // the rest of method&#39;s code&#8230;</td>
</tr>
<tr>
<td id="file-addnewcity_corrected-cs-L7" class="blob-num js-line-number js-blob-rnum" data-line-number="7"></td>
<td id="file-addnewcity_corrected-cs-LC7" class="blob-code blob-code-inner js-file-line">}</td>
</tr>
</table>
</div></div>
</p></div>
</div></div>
<div class="gist-meta">
        <a href="https://gist.github.com/dsibinski/e767ddb0a04208ba01729e0c460ca537/raw/0b61f0394e1fe7f7f5e37c8e7a89d603b59f010d/AddNewCity_Corrected.cs" style="float:right" class="Link--inTextBlock">view raw</a><br />
        <a href="https://gist.github.com/dsibinski/e767ddb0a04208ba01729e0c460ca537#file-addnewcity_corrected-cs" class="Link--inTextBlock"><br />
          AddNewCity_Corrected.cs<br />
        </a><br />
        hosted with &#10084; by <a class="Link--inTextBlock" href="https://github.com">GitHub</a>
      </div>
</p></div>
</div>
<p>When the application is now launched, s<em>ampling </em>started and button clicked 3 times, we already see the improvement:</p>
<figure id="attachment_759" aria-describedby="caption-attachment-759" style="width: 707px" class="wp-caption aligncenter"><a href="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/perfViewer_Corrected1.png?ssl=1"><img data-recalc-dims="1" loading="lazy" decoding="async" data-attachment-id="759" data-permalink="https://www.codejourney.net/solving-performance-issues-with-dottrace/perfviewer_corrected1/" data-orig-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/perfViewer_Corrected1.png?fit=1265%2C296&amp;ssl=1" data-orig-size="1265,296" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="perfViewer_Corrected1" data-image-description="" data-image-caption="&lt;p&gt;Calls after improvement&lt;/p&gt;
" data-large-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/perfViewer_Corrected1.png?fit=1024%2C240&amp;ssl=1" class=" wp-image-759" src="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/perfViewer_Corrected1.png?resize=707%2C165&#038;ssl=1" alt="" width="707" height="165" srcset="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/perfViewer_Corrected1.png?resize=300%2C70&amp;ssl=1 300w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/perfViewer_Corrected1.png?resize=768%2C180&amp;ssl=1 768w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/perfViewer_Corrected1.png?resize=1024%2C240&amp;ssl=1 1024w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/perfViewer_Corrected1.png?resize=720%2C168&amp;ssl=1 720w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/perfViewer_Corrected1.png?w=1265&amp;ssl=1 1265w" sizes="auto, (max-width: 707px) 100vw, 707px" /></a><figcaption id="caption-attachment-759" class="wp-caption-text">Calls after improvement</figcaption></figure>
<p><em>AddNewCity</em> takes <strong>65.96%</strong> now. This is average value from all the calls we made, so let&#8217;s now perform <em>sampling</em> starting from the 2nd click:</p>
<figure id="attachment_761" aria-describedby="caption-attachment-761" style="width: 762px" class="wp-caption aligncenter"><a href="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/perfViewer_Corrected2.png?ssl=1"><img data-recalc-dims="1" loading="lazy" decoding="async" data-attachment-id="761" data-permalink="https://www.codejourney.net/solving-performance-issues-with-dottrace/perfviewer_corrected2/" data-orig-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/perfViewer_Corrected2.png?fit=1271%2C277&amp;ssl=1" data-orig-size="1271,277" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="perfViewer_Corrected2" data-image-description="" data-image-caption="&lt;p&gt;Performance omitting 1st click&lt;/p&gt;
" data-large-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/perfViewer_Corrected2.png?fit=1024%2C223&amp;ssl=1" class=" wp-image-761" src="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/perfViewer_Corrected2.png?resize=762%2C165&#038;ssl=1" alt="" width="762" height="165" srcset="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/perfViewer_Corrected2.png?resize=300%2C65&amp;ssl=1 300w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/perfViewer_Corrected2.png?resize=768%2C167&amp;ssl=1 768w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/perfViewer_Corrected2.png?resize=1024%2C223&amp;ssl=1 1024w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/perfViewer_Corrected2.png?resize=720%2C157&amp;ssl=1 720w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/perfViewer_Corrected2.png?w=1271&amp;ssl=1 1271w" sizes="auto, (max-width: 762px) 100vw, 762px" /></a><figcaption id="caption-attachment-761" class="wp-caption-text">Performance omitting 1st click</figcaption></figure>
<p>The whole <em>AddNewCity</em> method is now taking only <strong>0.41% of the calls</strong> during the operation.</p>
<p>Now, if we want to make Customer&#8217;s life beautiful, we&#8217;d extract initialization of EU countries list to another thread, so it can happen when the application launches and UI is not frozen. We will however stop here. You get the idea, don&#8217;t you ? <img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f609.png" alt="😉" class="wp-smiley" style="height: 1em; max-height: 1em;" /></p>
<h2>Summary</h2>
<p>Today we&#8217;ve seen how easily &#8211; by performing just the simplest profiling session that can be done in <em>dotTrace </em>&#8211; it may be to detect what causes real performance issues in .NET application. Of course the example was pretty naive and simple, but I didn&#8217;t make it up &#8211; many times I&#8217;ve already worked with performance issues in production code which were caused by retrieving so called &#8220;dictionary&#8221; or static data using some API or database connection every time in a loop or repetitive process, which was totally unnecessary. By only implementing some kind of cache (maybe a bit more reasonable than the one we did, which in our case was actually enough), I managed to optimize processes executing time from 3 or 4 hours to several seconds.</p>
<p>Obviously if you&#8217;re an experienced developer, you&#8217;d probably identify such places in which caching or similar mechanism should be used when writing code. Profiling may however be useful for less experienced programmers or when working with legacy code we didn&#8217;t write (or we wrote months or years ago <img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f642.png" alt="🙂" class="wp-smiley" style="height: 1em; max-height: 1em;" /> ). It doesn&#8217;t cost much, except the cost of <em>dotTrace </em>itself, which is a part of <a href="https://www.jetbrains.com/resharper/buy/index.jsp?product=ultimate#edition=commercial" target="_blank" rel="noopener">ReSharper Ultimate</a>, but this tool is just an example, you are not limited to it. For sure there are many other tools that offer the same (or maybe even more?) functionalities.</p>
<p><span style="text-decoration: underline;"><strong>What are the tools you use for debugging performance issues ? Maybe you also use <em>dotTrace</em>, but can share some experience in using its other functionalities?</strong></span></p>
<p>The post <a href="https://www.codejourney.net/solving-performance-issues-with-dottrace/">Solving performance issues with dotTrace</a> appeared first on <a href="https://www.codejourney.net">CodeJourney.net</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.codejourney.net/solving-performance-issues-with-dottrace/feed/</wfw:commentRss>
			<slash:comments>3</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">728</post-id>	</item>
		<item>
		<title>Xamarin – Android Activities</title>
		<link>https://www.codejourney.net/xamarin-android-activities/</link>
					<comments>https://www.codejourney.net/xamarin-android-activities/#comments</comments>
		
		<dc:creator><![CDATA[Dawid Sibiński]]></dc:creator>
		<pubDate>Sat, 11 Mar 2017 18:53:10 +0000</pubDate>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[android]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[dajsiepoznac2017]]></category>
		<category><![CDATA[xamarin]]></category>
		<guid isPermaLink="false">http://www.dsibinski.pl/?p=405</guid>

					<description><![CDATA[<p>Today we’re going to take a look at Android’s most basic and in the same time most important concept, which is an Activity. To create even the simplest “HelloWorld” app one should know what are the Activities and how to work with them. What is an Activity ? The simplest, an Activity is a single&#8230;</p>
<p>The post <a href="https://www.codejourney.net/xamarin-android-activities/">Xamarin – Android Activities</a> appeared first on <a href="https://www.codejourney.net">CodeJourney.net</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p style="text-align: left;">Today we’re going to take a look at Android’s most basic and in the same time most important concept, which is an <strong>Activity</strong>. To create even the simplest “HelloWorld” app one should know what are the Activities and how to work with them.<br />
<span id="more-405"></span></p>
<h2>What is an Activity ?</h2>
<p style="text-align: left;" align="left">The simplest, an <strong>Activity is a single screen in Android application</strong>. The concept of Activities is unusual in programming and it&#8217;s specific to Android platform.</p>
<p style="text-align: left;" align="left">Every Activity in Xamarin consists of two components:</p>
<ul>
<li style="text-align: left;"><strong>UI </strong>(XML) &#8211; layout with user controls defined</li>
<li style="text-align: left;"><strong>Code </strong>(C#) &#8211; implementing the behavior</li>
</ul>
<p>Let&#8217;s consider email client application &#8211; it&#8217;d probably have several Activities: &#8220;New email&#8221;, &#8220;List of emails&#8221;, &#8220;Email details&#8221;, &#8220;Settings&#8221; &#8211; notice all of them having both UI and behavior. We&#8217;d probably need &#8220;Email sending service&#8221;, which doesn&#8217;t necessarily need UI, so it wouldn&#8217;t be created as an Activity, but rather as a separate class realizing concrete task.</p>
<p>As we can already see, every Android app contains several Activities:</p>
<figure id="attachment_484" aria-describedby="caption-attachment-484" style="width: 1823px" class="wp-caption alignnone"><img data-recalc-dims="1" loading="lazy" decoding="async" data-attachment-id="484" data-permalink="https://www.codejourney.net/xamarin-android-activities/activities/" data-orig-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/activities.png?fit=1823%2C914&amp;ssl=1" data-orig-size="1823,914" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="activities" data-image-description="" data-image-caption="" data-large-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/activities.png?fit=1024%2C513&amp;ssl=1" class="alignnone size-full wp-image-484" src="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/activities.png?resize=1140%2C572&#038;ssl=1" alt="activities" width="1140" height="572" srcset="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/activities.png?w=1823&amp;ssl=1 1823w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/activities.png?resize=300%2C150&amp;ssl=1 300w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/activities.png?resize=768%2C385&amp;ssl=1 768w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/activities.png?resize=1024%2C513&amp;ssl=1 1024w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/activities.png?resize=720%2C361&amp;ssl=1 720w" sizes="auto, (max-width: 1140px) 100vw, 1140px" /><figcaption id="caption-attachment-484" class="wp-caption-text">Android app composed of Activities, source: <a href="https://elearning.xamarin.com/android/AND101/2-activities/default" target="_blank" rel="noopener">elearning.xamarin.com</a></figcaption></figure>
<p>In most programming platforms, the application has a static method which is called on the application&#8217;s startup. This is not the case in Android &#8211; do you remember our <em>MainActivity </em>class <a href="https://www.codejourney.net/2017/03/hello-xamarin-world-first-steps/" target="_blank" rel="noopener">from the previous post</a> ? It&#8217;s decorated with <em>ActivityAttribute</em> which registers the Activity within the Android system, but what&#8217;s more important by having <em>MainLauncher</em> attribute&#8217;s property set to <strong>true</strong> it tells the system it&#8217;s the startup Activity for the application within which it&#8217;s registered. It means nothing more than when our app is launched, Android creates <em>MainActivity</em> as the first one from all Activities in our application. Apart from that, OS operates the <em>MainActivity</em> as all other Activities.</p>
<h2>Activities Back Stack</h2>
<p>Android app starts its own Activities from other Activities. It may also start Activities that are defined by different apps, e.g. your Android app can offer a possibility to send an email. You don&#8217;t have to implement your own email sending client for that &#8211; it&#8217;s possible to use already existing email sending Activities (using <a href="https://developer.xamarin.com/recipes/android/fundamentals/intent/" target="_blank" rel="noopener">Android Intents</a>, which we&#8217;ll also cover one day) registered within another apps installed in the system which expose such &#8220;external calling&#8221; possibility. Then, this external app launches looking as if it was the part of your application. This is very <strong>powerful!</strong></p>
<p>When your email is finally sent, you are redirected back to your app from which you triggered email&#8217;s sending. <em><strong>How is that possible?</p>
<p></strong></em></p>
<p>In order to ensure such way of functioning, Android keeps all the Activities needed to perform a certain job (even if they come from different apps) in the same <em>task</em>. The &#8220;scope&#8221; of a <em>task</em> (when new <em>task</em> is created, what Activities it contains etc.) depends, among others, on Android version (e.g. starting from Android 7.0 many apps can be started in multiple windows in the same time on a single screen &#8211; in that case, the system keeps a separate <em>task</em> for each window).</p>
<p>Within a particular <em>task</em>, several Activities are started. Each started Activity is pushed to the <strong>Activities</strong> <strong>Back Stack</strong>. The Activity being on the top of the stack <strong>has focus </strong>(is visible to the user). The previous Activities remain on the stack, but are stopped or even destroyed by Android system in certain cases (few more words about it in the next chapter).</p>
<p>Activities Back Stack is a LIFO objects structure: when user presses <a href="https://www.codejourney.net/wp-content/uploads/2017/03/android_back_button.png" target="_blank" rel="noopener"><strong>Back</strong> button</a> the current Activity is popped from the top of the stack and the state of the previous Activity is restored. The following figure visualizes this behavior:</p>
<figure id="attachment_550" aria-describedby="caption-attachment-550" style="width: 617px" class="wp-caption alignnone"><img data-recalc-dims="1" loading="lazy" decoding="async" data-attachment-id="550" data-permalink="https://www.codejourney.net/xamarin-android-activities/diagram_backstack/" data-orig-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/diagram_backstack.png?fit=617%2C195&amp;ssl=1" data-orig-size="617,195" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="diagram_backstack" data-image-description="" data-image-caption="" data-large-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/diagram_backstack.png?fit=617%2C195&amp;ssl=1" class="alignnone size-full wp-image-550" src="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/diagram_backstack.png?resize=617%2C195&#038;ssl=1" alt="diagram_backstack" width="617" height="195" srcset="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/diagram_backstack.png?w=617&amp;ssl=1 617w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/diagram_backstack.png?resize=300%2C95&amp;ssl=1 300w" sizes="auto, (max-width: 617px) 100vw, 617px" /><figcaption id="caption-attachment-550" class="wp-caption-text">Activities Back Stack (LIFO) visualization, source: <a href="https://developer.android.com/guide/components/activities/tasks-and-back-stack.html" target="_blank" rel="noopener">developer.android.com</a></figcaption></figure>
<h2>Android Activities Lifecycle</h2>
<p>We already know the Activities are kept on Back Stack. We also need to know that Android OS may try to <strong>restart</strong> the application (after it crashed, for instance) at the last opened Activity. The OS may also <strong>pause</strong> the Activities when they&#8217;re not active or <strong>kill </strong>them when the device is low on memory. All those possible operations and states&#8217; changes form <strong>Android Activities Lifecycle</strong>, which is a set of defined states in which every Activity may be:</p>
<figure id="attachment_578" aria-describedby="caption-attachment-578" style="width: 1720px" class="wp-caption alignnone"><img data-recalc-dims="1" loading="lazy" decoding="async" data-attachment-id="578" data-permalink="https://www.codejourney.net/xamarin-android-activities/activities_states/" data-orig-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/activities_states.png?fit=1720%2C347&amp;ssl=1" data-orig-size="1720,347" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="activities_states" data-image-description="" data-image-caption="" data-large-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/activities_states.png?fit=1024%2C207&amp;ssl=1" class="alignnone size-full wp-image-578" src="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/activities_states.png?resize=1140%2C230&#038;ssl=1" alt="activities_states" width="1140" height="230" srcset="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/activities_states.png?w=1720&amp;ssl=1 1720w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/activities_states.png?resize=300%2C61&amp;ssl=1 300w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/activities_states.png?resize=768%2C155&amp;ssl=1 768w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/activities_states.png?resize=1024%2C207&amp;ssl=1 1024w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/activities_states.png?resize=720%2C145&amp;ssl=1 720w" sizes="auto, (max-width: 1140px) 100vw, 1140px" /><figcaption id="caption-attachment-578" class="wp-caption-text">Activity states, source: <a href="https://developer.xamarin.com/guides/android/application_fundamentals/activity_lifecycle/" target="_blank" rel="noopener">developer.xamarin.com</a></figcaption></figure>
<p>Let&#8217;s see what those states mean:</p>
<ul>
<li><strong>Running</strong> &#8211; Activity is in the foreground (top of the activities stack); <span style="text-decoration: underline;">highest-priority Activity</span> for OS</li>
<li><strong>Paused </strong>&#8211; Activity is in this state when still visible, but covered by another non-full sized Activity or when the device enters sleep mode; <span style="text-decoration: underline;">second-highest-priority Activity</span> for OS</li>
<li><strong>Backgrounded/Stopped</strong>&#8211; Activity enters Backgrounded state when it&#8217;s overtaken by another, completely new Activity which is pushed on the top of the back stack; <span style="text-decoration: underline;">lowest-priority Activity</span> for OS, which will be killed firstly in order to free resources</li>
<li><strong>Restarted </strong>&#8211; this state is not visible on the diagram, however it&#8217;s possible that Android (e.g. user using task manager or similar app) kills the app being in any of above-mentioned states; if the user wants to go back to this Activity later, it must be restarted (previous state must be retrieved).</li>
</ul>
<h2>Handling states changes &#8211; lifecycle methods</h2>
<p>Android (and Xamarin) provides SDK methods that are called by the OS each time an Activity&#8217;s state changes. Those methods may be overridden and implemented for each Activity in order to react on states changes and ensure application&#8217;s stability. The following diagram visualizes the dependencies and flow of methods being called:</p>
<figure id="attachment_605" aria-describedby="caption-attachment-605" style="width: 399px" class="wp-caption aligncenter"><img data-recalc-dims="1" loading="lazy" decoding="async" data-attachment-id="605" data-permalink="https://www.codejourney.net/xamarin-android-activities/android_lifecycle_methods/" data-orig-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/android_lifecycle_methods.png?fit=1720%2C1998&amp;ssl=1" data-orig-size="1720,1998" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="android_lifecycle_methods" data-image-description="" data-image-caption="" data-large-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/android_lifecycle_methods.png?fit=882%2C1024&amp;ssl=1" class=" wp-image-605 aligncenter" src="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/android_lifecycle_methods.png?resize=399%2C464&#038;ssl=1" alt="android_lifecycle_methods" width="399" height="464" srcset="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/android_lifecycle_methods.png?w=1720&amp;ssl=1 1720w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/android_lifecycle_methods.png?resize=258%2C300&amp;ssl=1 258w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/android_lifecycle_methods.png?resize=768%2C892&amp;ssl=1 768w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/android_lifecycle_methods.png?resize=882%2C1024&amp;ssl=1 882w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/android_lifecycle_methods.png?resize=720%2C836&amp;ssl=1 720w" sizes="auto, (max-width: 399px) 100vw, 399px" /><figcaption id="caption-attachment-605" class="wp-caption-text">Android lifecycle methods, source: <a href="https://developer.xamarin.com/guides/android/application_fundamentals/activity_lifecycle/" target="_blank" rel="noopener">developer.xamarin.com</a></figcaption></figure>
<p>Let&#8217;s see in what cases the particular methods should be implemented:</p>
<ul>
<li><strong>OnCreate()</strong> &#8211; called when an Activity is created; used for initializing views and variables</li>
<li><strong>OnStart()</strong> &#8211; called immediately after <em>OnCreate()</em> finishes; UI refreshing can be handled here</li>
<li><strong>OnResume()</strong> &#8211; called after <em>OnStart()</em> finishes and also when Activity is restarted after being paused</li>
<li><strong>OnPause()</strong> &#8211; called when OS is about to pause or move the Activity to the background; here all resources-consuming objects should be cleaned-up, unsaved changes should be stored in some kind of persistent storage to be able to restore it when the Activity is revealed</li>
<li><strong>OnStop()</strong> &#8211; called when the Activity stops being visible to the user or is destroyed (e.g. when OS needs to release some resources)</li>
<li><strong>OnDestroy()</strong> &#8211; final method called on Activity just before it&#8217;s destroyed; it may not be called in some cases, so it&#8217;s better to clean-up resources in <em>OnPause()</em> and <em>OnStop()</em> methods.</li>
</ul>
<h2>Let&#8217;s see some code</h2>
<p>In order to really test those lifecycle methods, I added a stunning functionality to <em>MoneyBack</em> app:</p>
<figure id="attachment_629" aria-describedby="caption-attachment-629" style="width: 238px" class="wp-caption aligncenter"><img data-recalc-dims="1" loading="lazy" decoding="async" data-attachment-id="629" data-permalink="https://www.codejourney.net/xamarin-android-activities/screenshot_lifecycle/" data-orig-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/Screenshot_Lifecycle.png?fit=768%2C1280&amp;ssl=1" data-orig-size="768,1280" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="Screenshot_Lifecycle" data-image-description="" data-image-caption="" data-large-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/Screenshot_Lifecycle.png?fit=614%2C1024&amp;ssl=1" class=" wp-image-629 aligncenter" src="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/Screenshot_Lifecycle.png?resize=238%2C397&#038;ssl=1" alt="Screenshot_Lifecycle" width="238" height="397" srcset="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/Screenshot_Lifecycle.png?w=768&amp;ssl=1 768w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/Screenshot_Lifecycle.png?resize=180%2C300&amp;ssl=1 180w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/Screenshot_Lifecycle.png?resize=614%2C1024&amp;ssl=1 614w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/Screenshot_Lifecycle.png?resize=720%2C1200&amp;ssl=1 720w" sizes="auto, (max-width: 238px) 100vw, 238px" /><figcaption id="caption-attachment-629" class="wp-caption-text">Simple division Activity</figcaption></figure>
<p>As you could already realize, you can enter amount of money spent, number of people involved and it will make a simple division operation to split the costs equally. That&#8217;s already kinda costs splitting, right ?! <img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f642.png" alt="🙂" class="wp-smiley" style="height: 1em; max-height: 1em;" /></p>
<p>I implemented the lifecycle-control methods to check how it really behaves.</p>
<h3>OnCreate</h3>
<p><style>.gist table { margin-bottom: 0; }</style>
<div style="tab-size: 8" id="gist45611437" class="gist">
<div class="gist-file" translate="no" data-color-mode="light" data-light-theme="light">
<div class="gist-data">
<div class="js-gist-file-update-container js-task-list-container">
<div id="file-mainactivity_oncreate-cs" class="file my-2">
<div itemprop="text"
      class="Box-body p-0 blob-wrapper data type-c  "
      style="overflow: auto" tabindex="0" role="region"
      aria-label="MainActivity_OnCreate.cs content, created by dsibinski on 05:54PM on March 11, 2017."
    ></p>
<div class="js-check-hidden-unicode js-blob-code-container blob-code-content">
<p>  <template class="js-file-alert-template"></p>
<div data-view-component="true" class="flash flash-warn flash-full d-flex flex-items-center">
  <svg aria-hidden="true" data-component="Octicon" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-alert">
    <path d="M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"></path>
</svg><br />
    <span><br />
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.<br />
      <a class="Link--inTextBlock" href="https://github.co/hiddenchars" target="_blank">Learn more about bidirectional Unicode characters</a><br />
    </span></p>
<div data-view-component="true" class="flash-action">        <a href="{{ revealButtonHref }}" data-view-component="true" class="btn-sm btn">    Show hidden characters<br />
</a>
</div>
</div>
<p></template><br />
<template class="js-line-alert-template"><br />
  <span aria-label="This line has hidden Unicode characters" data-view-component="true" class="line-alert tooltipped tooltipped-e"><br />
    <svg aria-hidden="true" data-component="Octicon" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-alert">
    <path d="M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"></path>
</svg><br />
</span></template></p>
<table data-hpc class="highlight tab-size js-file-line-container" data-tab-size="4" data-paste-markdown-skip data-tagsearch-path="MainActivity_OnCreate.cs">
<tr>
<td id="file-mainactivity_oncreate-cs-L1" class="blob-num js-line-number js-blob-rnum" data-line-number="1"></td>
<td id="file-mainactivity_oncreate-cs-LC1" class="blob-code blob-code-inner js-file-line">protected override void OnCreate(Bundle bundle)</td>
</tr>
<tr>
<td id="file-mainactivity_oncreate-cs-L2" class="blob-num js-line-number js-blob-rnum" data-line-number="2"></td>
<td id="file-mainactivity_oncreate-cs-LC2" class="blob-code blob-code-inner js-file-line">{</td>
</tr>
<tr>
<td id="file-mainactivity_oncreate-cs-L3" class="blob-num js-line-number js-blob-rnum" data-line-number="3"></td>
<td id="file-mainactivity_oncreate-cs-LC3" class="blob-code blob-code-inner js-file-line">    base.OnCreate(bundle);</td>
</tr>
<tr>
<td id="file-mainactivity_oncreate-cs-L4" class="blob-num js-line-number js-blob-rnum" data-line-number="4"></td>
<td id="file-mainactivity_oncreate-cs-LC4" class="blob-code blob-code-inner js-file-line">
</td>
</tr>
<tr>
<td id="file-mainactivity_oncreate-cs-L5" class="blob-num js-line-number js-blob-rnum" data-line-number="5"></td>
<td id="file-mainactivity_oncreate-cs-LC5" class="blob-code blob-code-inner js-file-line">    // Set our view from the &quot;main&quot; layout resource</td>
</tr>
<tr>
<td id="file-mainactivity_oncreate-cs-L6" class="blob-num js-line-number js-blob-rnum" data-line-number="6"></td>
<td id="file-mainactivity_oncreate-cs-LC6" class="blob-code blob-code-inner js-file-line">    SetContentView(Resource.Layout.Main);</td>
</tr>
<tr>
<td id="file-mainactivity_oncreate-cs-L7" class="blob-num js-line-number js-blob-rnum" data-line-number="7"></td>
<td id="file-mainactivity_oncreate-cs-LC7" class="blob-code blob-code-inner js-file-line">
</td>
</tr>
<tr>
<td id="file-mainactivity_oncreate-cs-L8" class="blob-num js-line-number js-blob-rnum" data-line-number="8"></td>
<td id="file-mainactivity_oncreate-cs-LC8" class="blob-code blob-code-inner js-file-line">    _amount = 0.00m;</td>
</tr>
<tr>
<td id="file-mainactivity_oncreate-cs-L9" class="blob-num js-line-number js-blob-rnum" data-line-number="9"></td>
<td id="file-mainactivity_oncreate-cs-LC9" class="blob-code blob-code-inner js-file-line">    _result = 0.00m;</td>
</tr>
<tr>
<td id="file-mainactivity_oncreate-cs-L10" class="blob-num js-line-number js-blob-rnum" data-line-number="10"></td>
<td id="file-mainactivity_oncreate-cs-LC10" class="blob-code blob-code-inner js-file-line">    _numberOfPeople = 0;</td>
</tr>
<tr>
<td id="file-mainactivity_oncreate-cs-L11" class="blob-num js-line-number js-blob-rnum" data-line-number="11"></td>
<td id="file-mainactivity_oncreate-cs-LC11" class="blob-code blob-code-inner js-file-line">
</td>
</tr>
<tr>
<td id="file-mainactivity_oncreate-cs-L12" class="blob-num js-line-number js-blob-rnum" data-line-number="12"></td>
<td id="file-mainactivity_oncreate-cs-LC12" class="blob-code blob-code-inner js-file-line">    InitializeUserControls();</td>
</tr>
<tr>
<td id="file-mainactivity_oncreate-cs-L13" class="blob-num js-line-number js-blob-rnum" data-line-number="13"></td>
<td id="file-mainactivity_oncreate-cs-LC13" class="blob-code blob-code-inner js-file-line">}</td>
</tr>
<tr>
<td id="file-mainactivity_oncreate-cs-L14" class="blob-num js-line-number js-blob-rnum" data-line-number="14"></td>
<td id="file-mainactivity_oncreate-cs-LC14" class="blob-code blob-code-inner js-file-line">
</td>
</tr>
<tr>
<td id="file-mainactivity_oncreate-cs-L15" class="blob-num js-line-number js-blob-rnum" data-line-number="15"></td>
<td id="file-mainactivity_oncreate-cs-LC15" class="blob-code blob-code-inner js-file-line">// &#8230;</td>
</tr>
<tr>
<td id="file-mainactivity_oncreate-cs-L16" class="blob-num js-line-number js-blob-rnum" data-line-number="16"></td>
<td id="file-mainactivity_oncreate-cs-LC16" class="blob-code blob-code-inner js-file-line">
</td>
</tr>
<tr>
<td id="file-mainactivity_oncreate-cs-L17" class="blob-num js-line-number js-blob-rnum" data-line-number="17"></td>
<td id="file-mainactivity_oncreate-cs-LC17" class="blob-code blob-code-inner js-file-line">private void InitializeUserControls()</td>
</tr>
<tr>
<td id="file-mainactivity_oncreate-cs-L18" class="blob-num js-line-number js-blob-rnum" data-line-number="18"></td>
<td id="file-mainactivity_oncreate-cs-LC18" class="blob-code blob-code-inner js-file-line">{</td>
</tr>
<tr>
<td id="file-mainactivity_oncreate-cs-L19" class="blob-num js-line-number js-blob-rnum" data-line-number="19"></td>
<td id="file-mainactivity_oncreate-cs-LC19" class="blob-code blob-code-inner js-file-line">    _inputAmount = this.FindViewById&lt;EditText&gt;(Resource.Id.inputAmount);</td>
</tr>
<tr>
<td id="file-mainactivity_oncreate-cs-L20" class="blob-num js-line-number js-blob-rnum" data-line-number="20"></td>
<td id="file-mainactivity_oncreate-cs-LC20" class="blob-code blob-code-inner js-file-line">    _inputNumberOfPeople = this.FindViewById&lt;EditText&gt;(Resource.Id.inputNumberOfPeople);</td>
</tr>
<tr>
<td id="file-mainactivity_oncreate-cs-L21" class="blob-num js-line-number js-blob-rnum" data-line-number="21"></td>
<td id="file-mainactivity_oncreate-cs-LC21" class="blob-code blob-code-inner js-file-line">    _txtResultDecimal = this.FindViewById&lt;EditText&gt;(Resource.Id.txtResultDecimal);</td>
</tr>
<tr>
<td id="file-mainactivity_oncreate-cs-L22" class="blob-num js-line-number js-blob-rnum" data-line-number="22"></td>
<td id="file-mainactivity_oncreate-cs-LC22" class="blob-code blob-code-inner js-file-line">    _btnCalculate = this.FindViewById&lt;Button&gt;(Resource.Id.btnCalculate);</td>
</tr>
<tr>
<td id="file-mainactivity_oncreate-cs-L23" class="blob-num js-line-number js-blob-rnum" data-line-number="23"></td>
<td id="file-mainactivity_oncreate-cs-LC23" class="blob-code blob-code-inner js-file-line">}</td>
</tr>
</table>
</div></div>
</p></div>
</div></div>
<div class="gist-meta">
        <a href="https://gist.github.com/dsibinski/5ace702ca7109b4f6ae08c35cce9ee84/raw/1fcf175d5220a6938bce340691a4a14e4f1ff391/MainActivity_OnCreate.cs" style="float:right" class="Link--inTextBlock">view raw</a><br />
        <a href="https://gist.github.com/dsibinski/5ace702ca7109b4f6ae08c35cce9ee84#file-mainactivity_oncreate-cs" class="Link--inTextBlock"><br />
          MainActivity_OnCreate.cs<br />
        </a><br />
        hosted with &#10084; by <a class="Link--inTextBlock" href="https://github.com">GitHub</a>
      </div>
</p></div>
</div>
<p>Here I only initialize my view from layout, Activity&#8217;s private variables and instantiate user controls. Nothing more for this simple example.</p>
<h3>OnStart</h3>
<p><style>.gist table { margin-bottom: 0; }</style>
<div style="tab-size: 8" id="gist45611494" class="gist">
<div class="gist-file" translate="no" data-color-mode="light" data-light-theme="light">
<div class="gist-data">
<div class="js-gist-file-update-container js-task-list-container">
<div id="file-mainactivity_onstart-cs" class="file my-2">
<div itemprop="text"
      class="Box-body p-0 blob-wrapper data type-c  "
      style="overflow: auto" tabindex="0" role="region"
      aria-label="MainActivity_OnStart.cs content, created by dsibinski on 05:56PM on March 11, 2017."
    ></p>
<div class="js-check-hidden-unicode js-blob-code-container blob-code-content">
<p>  <template class="js-file-alert-template"></p>
<div data-view-component="true" class="flash flash-warn flash-full d-flex flex-items-center">
  <svg aria-hidden="true" data-component="Octicon" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-alert">
    <path d="M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"></path>
</svg><br />
    <span><br />
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.<br />
      <a class="Link--inTextBlock" href="https://github.co/hiddenchars" target="_blank">Learn more about bidirectional Unicode characters</a><br />
    </span></p>
<div data-view-component="true" class="flash-action">        <a href="{{ revealButtonHref }}" data-view-component="true" class="btn-sm btn">    Show hidden characters<br />
</a>
</div>
</div>
<p></template><br />
<template class="js-line-alert-template"><br />
  <span aria-label="This line has hidden Unicode characters" data-view-component="true" class="line-alert tooltipped tooltipped-e"><br />
    <svg aria-hidden="true" data-component="Octicon" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-alert">
    <path d="M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"></path>
</svg><br />
</span></template></p>
<table data-hpc class="highlight tab-size js-file-line-container" data-tab-size="4" data-paste-markdown-skip data-tagsearch-path="MainActivity_OnStart.cs">
<tr>
<td id="file-mainactivity_onstart-cs-L1" class="blob-num js-line-number js-blob-rnum" data-line-number="1"></td>
<td id="file-mainactivity_onstart-cs-LC1" class="blob-code blob-code-inner js-file-line">protected override void OnStart()</td>
</tr>
<tr>
<td id="file-mainactivity_onstart-cs-L2" class="blob-num js-line-number js-blob-rnum" data-line-number="2"></td>
<td id="file-mainactivity_onstart-cs-LC2" class="blob-code blob-code-inner js-file-line">{</td>
</tr>
<tr>
<td id="file-mainactivity_onstart-cs-L3" class="blob-num js-line-number js-blob-rnum" data-line-number="3"></td>
<td id="file-mainactivity_onstart-cs-LC3" class="blob-code blob-code-inner js-file-line">    base.OnStart();</td>
</tr>
<tr>
<td id="file-mainactivity_onstart-cs-L4" class="blob-num js-line-number js-blob-rnum" data-line-number="4"></td>
<td id="file-mainactivity_onstart-cs-LC4" class="blob-code blob-code-inner js-file-line">    RefreshUserInputsFromVariables();</td>
</tr>
<tr>
<td id="file-mainactivity_onstart-cs-L5" class="blob-num js-line-number js-blob-rnum" data-line-number="5"></td>
<td id="file-mainactivity_onstart-cs-LC5" class="blob-code blob-code-inner js-file-line">}</td>
</tr>
<tr>
<td id="file-mainactivity_onstart-cs-L6" class="blob-num js-line-number js-blob-rnum" data-line-number="6"></td>
<td id="file-mainactivity_onstart-cs-LC6" class="blob-code blob-code-inner js-file-line">// &#8230;</td>
</tr>
<tr>
<td id="file-mainactivity_onstart-cs-L7" class="blob-num js-line-number js-blob-rnum" data-line-number="7"></td>
<td id="file-mainactivity_onstart-cs-LC7" class="blob-code blob-code-inner js-file-line">private void RefreshUserInputsFromVariables()</td>
</tr>
<tr>
<td id="file-mainactivity_onstart-cs-L8" class="blob-num js-line-number js-blob-rnum" data-line-number="8"></td>
<td id="file-mainactivity_onstart-cs-LC8" class="blob-code blob-code-inner js-file-line">{</td>
</tr>
<tr>
<td id="file-mainactivity_onstart-cs-L9" class="blob-num js-line-number js-blob-rnum" data-line-number="9"></td>
<td id="file-mainactivity_onstart-cs-LC9" class="blob-code blob-code-inner js-file-line">    _inputAmount.SetText(_amount.ToString(CultureInfo.InvariantCulture), TextView.BufferType.Editable);</td>
</tr>
<tr>
<td id="file-mainactivity_onstart-cs-L10" class="blob-num js-line-number js-blob-rnum" data-line-number="10"></td>
<td id="file-mainactivity_onstart-cs-LC10" class="blob-code blob-code-inner js-file-line">    _txtResultDecimal.SetText(_result.ToString(CultureInfo.InvariantCulture), TextView.BufferType.Editable);</td>
</tr>
<tr>
<td id="file-mainactivity_onstart-cs-L11" class="blob-num js-line-number js-blob-rnum" data-line-number="11"></td>
<td id="file-mainactivity_onstart-cs-LC11" class="blob-code blob-code-inner js-file-line">    _inputNumberOfPeople.SetText(_numberOfPeople.ToString(CultureInfo.InvariantCulture),</td>
</tr>
<tr>
<td id="file-mainactivity_onstart-cs-L12" class="blob-num js-line-number js-blob-rnum" data-line-number="12"></td>
<td id="file-mainactivity_onstart-cs-LC12" class="blob-code blob-code-inner js-file-line">        TextView.BufferType.Editable);</td>
</tr>
<tr>
<td id="file-mainactivity_onstart-cs-L13" class="blob-num js-line-number js-blob-rnum" data-line-number="13"></td>
<td id="file-mainactivity_onstart-cs-LC13" class="blob-code blob-code-inner js-file-line">}</td>
</tr>
</table>
</div></div>
</p></div>
</div></div>
<div class="gist-meta">
        <a href="https://gist.github.com/dsibinski/f5b27956b31e09db96167eeca264ee8a/raw/27d5ba3b21973ac87435bb671966bfce121567a2/MainActivity_OnStart.cs" style="float:right" class="Link--inTextBlock">view raw</a><br />
        <a href="https://gist.github.com/dsibinski/f5b27956b31e09db96167eeca264ee8a#file-mainactivity_onstart-cs" class="Link--inTextBlock"><br />
          MainActivity_OnStart.cs<br />
        </a><br />
        hosted with &#10084; by <a class="Link--inTextBlock" href="https://github.com">GitHub</a>
      </div>
</p></div>
</div>
<p>In <em>OnStart()</em> method I just refresh UI elements &#8211; in that case initialize their <em>Text</em> properties with values stored in private variables.</p>
<h3>OnResume</h3>
<p><style>.gist table { margin-bottom: 0; }</style>
<div style="tab-size: 8" id="gist45611550" class="gist">
<div class="gist-file" translate="no" data-color-mode="light" data-light-theme="light">
<div class="gist-data">
<div class="js-gist-file-update-container js-task-list-container">
<div id="file-mainactivity_onresume-cs" class="file my-2">
<div itemprop="text"
      class="Box-body p-0 blob-wrapper data type-c  "
      style="overflow: auto" tabindex="0" role="region"
      aria-label="MainActivity_OnResume.cs content, created by dsibinski on 05:59PM on March 11, 2017."
    ></p>
<div class="js-check-hidden-unicode js-blob-code-container blob-code-content">
<p>  <template class="js-file-alert-template"></p>
<div data-view-component="true" class="flash flash-warn flash-full d-flex flex-items-center">
  <svg aria-hidden="true" data-component="Octicon" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-alert">
    <path d="M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"></path>
</svg><br />
    <span><br />
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.<br />
      <a class="Link--inTextBlock" href="https://github.co/hiddenchars" target="_blank">Learn more about bidirectional Unicode characters</a><br />
    </span></p>
<div data-view-component="true" class="flash-action">        <a href="{{ revealButtonHref }}" data-view-component="true" class="btn-sm btn">    Show hidden characters<br />
</a>
</div>
</div>
<p></template><br />
<template class="js-line-alert-template"><br />
  <span aria-label="This line has hidden Unicode characters" data-view-component="true" class="line-alert tooltipped tooltipped-e"><br />
    <svg aria-hidden="true" data-component="Octicon" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-alert">
    <path d="M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"></path>
</svg><br />
</span></template></p>
<table data-hpc class="highlight tab-size js-file-line-container" data-tab-size="4" data-paste-markdown-skip data-tagsearch-path="MainActivity_OnResume.cs">
<tr>
<td id="file-mainactivity_onresume-cs-L1" class="blob-num js-line-number js-blob-rnum" data-line-number="1"></td>
<td id="file-mainactivity_onresume-cs-LC1" class="blob-code blob-code-inner js-file-line">protected override void OnResume()</td>
</tr>
<tr>
<td id="file-mainactivity_onresume-cs-L2" class="blob-num js-line-number js-blob-rnum" data-line-number="2"></td>
<td id="file-mainactivity_onresume-cs-LC2" class="blob-code blob-code-inner js-file-line">{</td>
</tr>
<tr>
<td id="file-mainactivity_onresume-cs-L3" class="blob-num js-line-number js-blob-rnum" data-line-number="3"></td>
<td id="file-mainactivity_onresume-cs-LC3" class="blob-code blob-code-inner js-file-line">    base.OnResume();</td>
</tr>
<tr>
<td id="file-mainactivity_onresume-cs-L4" class="blob-num js-line-number js-blob-rnum" data-line-number="4"></td>
<td id="file-mainactivity_onresume-cs-LC4" class="blob-code blob-code-inner js-file-line">    InitializeUserControlsEvents();</td>
</tr>
<tr>
<td id="file-mainactivity_onresume-cs-L5" class="blob-num js-line-number js-blob-rnum" data-line-number="5"></td>
<td id="file-mainactivity_onresume-cs-LC5" class="blob-code blob-code-inner js-file-line">    // TODO: retrieving variables (amount, number of people) from persistent storage (file, database)</td>
</tr>
<tr>
<td id="file-mainactivity_onresume-cs-L6" class="blob-num js-line-number js-blob-rnum" data-line-number="6"></td>
<td id="file-mainactivity_onresume-cs-LC6" class="blob-code blob-code-inner js-file-line">}</td>
</tr>
<tr>
<td id="file-mainactivity_onresume-cs-L7" class="blob-num js-line-number js-blob-rnum" data-line-number="7"></td>
<td id="file-mainactivity_onresume-cs-LC7" class="blob-code blob-code-inner js-file-line">
</td>
</tr>
<tr>
<td id="file-mainactivity_onresume-cs-L8" class="blob-num js-line-number js-blob-rnum" data-line-number="8"></td>
<td id="file-mainactivity_onresume-cs-LC8" class="blob-code blob-code-inner js-file-line">// &#8230;</td>
</tr>
<tr>
<td id="file-mainactivity_onresume-cs-L9" class="blob-num js-line-number js-blob-rnum" data-line-number="9"></td>
<td id="file-mainactivity_onresume-cs-LC9" class="blob-code blob-code-inner js-file-line">private void InitializeUserControlsEvents()</td>
</tr>
<tr>
<td id="file-mainactivity_onresume-cs-L10" class="blob-num js-line-number js-blob-rnum" data-line-number="10"></td>
<td id="file-mainactivity_onresume-cs-LC10" class="blob-code blob-code-inner js-file-line">{</td>
</tr>
<tr>
<td id="file-mainactivity_onresume-cs-L11" class="blob-num js-line-number js-blob-rnum" data-line-number="11"></td>
<td id="file-mainactivity_onresume-cs-LC11" class="blob-code blob-code-inner js-file-line">    _btnCalculate.Click += _btnCalculate_Click;</td>
</tr>
<tr>
<td id="file-mainactivity_onresume-cs-L12" class="blob-num js-line-number js-blob-rnum" data-line-number="12"></td>
<td id="file-mainactivity_onresume-cs-LC12" class="blob-code blob-code-inner js-file-line">}</td>
</tr>
</table>
</div></div>
</p></div>
</div></div>
<div class="gist-meta">
        <a href="https://gist.github.com/dsibinski/543cdbccbb0e28c144d15548db8b9e6f/raw/479a1e85703fa5680d62daee5acbd2187da89e76/MainActivity_OnResume.cs" style="float:right" class="Link--inTextBlock">view raw</a><br />
        <a href="https://gist.github.com/dsibinski/543cdbccbb0e28c144d15548db8b9e6f#file-mainactivity_onresume-cs" class="Link--inTextBlock"><br />
          MainActivity_OnResume.cs<br />
        </a><br />
        hosted with &#10084; by <a class="Link--inTextBlock" href="https://github.com">GitHub</a>
      </div>
</p></div>
</div>
<p>As we know, <em>OnResume</em> method is called every time our Activity is brought to the top of Activities stack (either after <em>OnCreate -&gt; OnStart</em> or when revealing it after being backgrounded). That&#8217;s a very good place to initialize dependencies to external services (e.g. open communication with DB or remote service). In my case, I just subscribed to <em>Click</em> events of the button. If I had any persistent storage present (for instance local DB) I would in this place retrieve recently saved values from it to my Activity&#8217;s variables to restore its state (<em>OnResume</em> might be called when Activity class&#8217;s state is already cleaned up).</p>
<h3>OnPause</h3>
<p><style>.gist table { margin-bottom: 0; }</style>
<div style="tab-size: 8" id="gist45611682" class="gist">
<div class="gist-file" translate="no" data-color-mode="light" data-light-theme="light">
<div class="gist-data">
<div class="js-gist-file-update-container js-task-list-container">
<div id="file-mainactivity_onpause-cs" class="file my-2">
<div itemprop="text"
      class="Box-body p-0 blob-wrapper data type-c  "
      style="overflow: auto" tabindex="0" role="region"
      aria-label="MainActivity_OnPause.cs content, created by dsibinski on 06:05PM on March 11, 2017."
    ></p>
<div class="js-check-hidden-unicode js-blob-code-container blob-code-content">
<p>  <template class="js-file-alert-template"></p>
<div data-view-component="true" class="flash flash-warn flash-full d-flex flex-items-center">
  <svg aria-hidden="true" data-component="Octicon" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-alert">
    <path d="M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"></path>
</svg><br />
    <span><br />
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.<br />
      <a class="Link--inTextBlock" href="https://github.co/hiddenchars" target="_blank">Learn more about bidirectional Unicode characters</a><br />
    </span></p>
<div data-view-component="true" class="flash-action">        <a href="{{ revealButtonHref }}" data-view-component="true" class="btn-sm btn">    Show hidden characters<br />
</a>
</div>
</div>
<p></template><br />
<template class="js-line-alert-template"><br />
  <span aria-label="This line has hidden Unicode characters" data-view-component="true" class="line-alert tooltipped tooltipped-e"><br />
    <svg aria-hidden="true" data-component="Octicon" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-alert">
    <path d="M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"></path>
</svg><br />
</span></template></p>
<table data-hpc class="highlight tab-size js-file-line-container" data-tab-size="4" data-paste-markdown-skip data-tagsearch-path="MainActivity_OnPause.cs">
<tr>
<td id="file-mainactivity_onpause-cs-L1" class="blob-num js-line-number js-blob-rnum" data-line-number="1"></td>
<td id="file-mainactivity_onpause-cs-LC1" class="blob-code blob-code-inner js-file-line">protected override void OnPause()</td>
</tr>
<tr>
<td id="file-mainactivity_onpause-cs-L2" class="blob-num js-line-number js-blob-rnum" data-line-number="2"></td>
<td id="file-mainactivity_onpause-cs-LC2" class="blob-code blob-code-inner js-file-line">{</td>
</tr>
<tr>
<td id="file-mainactivity_onpause-cs-L3" class="blob-num js-line-number js-blob-rnum" data-line-number="3"></td>
<td id="file-mainactivity_onpause-cs-LC3" class="blob-code blob-code-inner js-file-line">    base.OnPause();</td>
</tr>
<tr>
<td id="file-mainactivity_onpause-cs-L4" class="blob-num js-line-number js-blob-rnum" data-line-number="4"></td>
<td id="file-mainactivity_onpause-cs-LC4" class="blob-code blob-code-inner js-file-line">    DetatchUserControlsEvents();</td>
</tr>
<tr>
<td id="file-mainactivity_onpause-cs-L5" class="blob-num js-line-number js-blob-rnum" data-line-number="5"></td>
<td id="file-mainactivity_onpause-cs-LC5" class="blob-code blob-code-inner js-file-line">    // TODO: saving variables (amount, number of people) to persistent storage (file, database)</td>
</tr>
<tr>
<td id="file-mainactivity_onpause-cs-L6" class="blob-num js-line-number js-blob-rnum" data-line-number="6"></td>
<td id="file-mainactivity_onpause-cs-LC6" class="blob-code blob-code-inner js-file-line">}</td>
</tr>
<tr>
<td id="file-mainactivity_onpause-cs-L7" class="blob-num js-line-number js-blob-rnum" data-line-number="7"></td>
<td id="file-mainactivity_onpause-cs-LC7" class="blob-code blob-code-inner js-file-line">// &#8230;</td>
</tr>
<tr>
<td id="file-mainactivity_onpause-cs-L8" class="blob-num js-line-number js-blob-rnum" data-line-number="8"></td>
<td id="file-mainactivity_onpause-cs-LC8" class="blob-code blob-code-inner js-file-line">private void DetatchUserControlsEvents()</td>
</tr>
<tr>
<td id="file-mainactivity_onpause-cs-L9" class="blob-num js-line-number js-blob-rnum" data-line-number="9"></td>
<td id="file-mainactivity_onpause-cs-LC9" class="blob-code blob-code-inner js-file-line">{</td>
</tr>
<tr>
<td id="file-mainactivity_onpause-cs-L10" class="blob-num js-line-number js-blob-rnum" data-line-number="10"></td>
<td id="file-mainactivity_onpause-cs-LC10" class="blob-code blob-code-inner js-file-line">    _btnCalculate.Click -= _btnCalculate_Click;</td>
</tr>
<tr>
<td id="file-mainactivity_onpause-cs-L11" class="blob-num js-line-number js-blob-rnum" data-line-number="11"></td>
<td id="file-mainactivity_onpause-cs-LC11" class="blob-code blob-code-inner js-file-line">}</td>
</tr>
</table>
</div></div>
</p></div>
</div></div>
<div class="gist-meta">
        <a href="https://gist.github.com/dsibinski/3c2715968ecf87822ee6f79a46a553ac/raw/7002c8439f39510b30d5a7c4d7a2a60a085d4a98/MainActivity_OnPause.cs" style="float:right" class="Link--inTextBlock">view raw</a><br />
        <a href="https://gist.github.com/dsibinski/3c2715968ecf87822ee6f79a46a553ac#file-mainactivity_onpause-cs" class="Link--inTextBlock"><br />
          MainActivity_OnPause.cs<br />
        </a><br />
        hosted with &#10084; by <a class="Link--inTextBlock" href="https://github.com">GitHub</a>
      </div>
</p></div>
</div>
<p>In <em>OnPause</em> method I need to be consistent with what I do in <em>OnResume</em> &#8211; when my app is taken to the background, I don&#8217;t need to wait for my button&#8217;s click events anymore, so let&#8217;s detach from it (maybe button&#8217;s <em>Click</em> event is not the best example here, but it&#8217;s just to visualize the purpose of the method). When my app is <em>resumed</em>, we will subscribe to this event again. Again, if I had any persistent storage, I&#8217;d save all variables&#8217; (which are necessary for restoring Activity&#8217;s state) values here to this storage, so they are able to be retrieved back as soon as <em>OnResume</em> is called.</p>
<h3>OnStop &amp; OnDestroy</h3>
<p>I didn&#8217;t implement those two methods in my app, it&#8217;s too simple to need anything in those places.</p>
<p>I deployed the app, attached with debugger and checked the order of methods&#8217; calls &#8211; all of them were called as described in previous paragraph.</p>
<h2>Summary</h2>
<p>It&#8217;s vital to understand how Android Activities and their states work. Even though it seems to be Android-specific, I&#8217;d rather say such approach is reasonable and even required by hardware on which mobile apps run (BTW, <a href="https://developer.apple.com/library/content/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/Art/high_level_flow_2x.png" target="_blank" rel="noopener">similar states seem to exist in iOS apps</a>).</p>
<p>When building Android app we need to think about Activities, especially make sure that each Activity in our application properly implements necessary lifecycle methods.</p>
<p><em><span style="text-decoration: underline;"><strong>Do you have or know any best practices while working with Activities and managing their lifecycle?</strong></span></em> I&#8217;d appreciate if you share it in the comments <img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f642.png" alt="🙂" class="wp-smiley" style="height: 1em; max-height: 1em;" /></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>The post <a href="https://www.codejourney.net/xamarin-android-activities/">Xamarin – Android Activities</a> appeared first on <a href="https://www.codejourney.net">CodeJourney.net</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.codejourney.net/xamarin-android-activities/feed/</wfw:commentRss>
			<slash:comments>3</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">405</post-id>	</item>
		<item>
		<title>Hello Xamarin World &#8211; first steps</title>
		<link>https://www.codejourney.net/hello-xamarin-world-first-steps/</link>
					<comments>https://www.codejourney.net/hello-xamarin-world-first-steps/#respond</comments>
		
		<dc:creator><![CDATA[Dawid Sibiński]]></dc:creator>
		<pubDate>Sat, 04 Mar 2017 23:12:14 +0000</pubDate>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[android]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[dajsiepoznac2017]]></category>
		<category><![CDATA[xamarin]]></category>
		<guid isPermaLink="false">http://www.dsibinski.pl/?p=244</guid>

					<description><![CDATA[<p>This time I want to say “Hello” to Xamarin world. First thing that needs to be done before starting Xamarin development, is obviously the installation of all necessary components. In this post I want to share my feelings about the installation (not without issues of course), configuration of my Xamarin Android solution and deployment process to&#8230;</p>
<p>The post <a href="https://www.codejourney.net/hello-xamarin-world-first-steps/">Hello Xamarin World &#8211; first steps</a> appeared first on <a href="https://www.codejourney.net">CodeJourney.net</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p style="text-align: left;">This time I want to say “Hello” to Xamarin world.</p>
<p style="text-align: left;">First thing that needs to be done before starting Xamarin development, is obviously the installation of all necessary components.</p>
<p style="text-align: left;">In this post I want to share my feelings about the installation (not without issues of course), configuration of my Xamarin Android solution and deployment process to the device.<br />
<span id="more-244"></span></p>
<h2>Xamarin installation into Visual Studio 2015</h2>
<p style="text-align: left;">I’ve created my account at <a href="http://www.xamarin.com/" target="_blank" rel="noopener">xamarin.com</a>, logged in and chose <em>Download Xamarin for free</em> to download the installation package. There are generally two IDEs that can be used for Xamarin development: Visual Studio or Xamarin Studio. I’ve already had VS 2015 installed and decided I don’t want to explore a new IDE, so I downloaded installer for Visual Studio. What’s more, following Xamarin’s website, “Xamarin Studio is no longer included” in the Windows installer and they “encourage Windows developers to move to Visual Studio”. Well, that&#8217;s understandable, Microsoft acquired Xamarin, didn&#8217;t they? 😉</p>
<p style="text-align: left;"><em>BTW, when <a href="https://www.xamarin.com/download" target="_blank" rel="noopener">downloading Xamarin</a> I was obliged to fill the “Company” field – does anyone know why is that?</em></p>
<h2 style="text-align: left;"> Android SDK and emulator images size</h2>
<p style="text-align: left;">Interesting parts of the installation (if there could by any at all?) are Android Emulator installation which is then integrated into Visual Studio as well as Android SDK installation – fortunately it’s possible to change the location of Android SDK installation, because right after the setup it takes an enormous amount of disk space (with mandatory tools mentioned in the installation guide and two Android APIs):</p>
<figure id="attachment_323" aria-describedby="caption-attachment-323" style="width: 300px" class="wp-caption aligncenter"><a href="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/android_sdk_size.png?ssl=1" target="_blank" rel="noopener"><img data-recalc-dims="1" loading="lazy" decoding="async" data-attachment-id="323" data-permalink="https://www.codejourney.net/hello-xamarin-world-first-steps/android_sdk_size/" data-orig-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/android_sdk_size.png?fit=348%2C243&amp;ssl=1" data-orig-size="348,243" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="android_sdk_size" data-image-description="&lt;p&gt;Android SDK size&lt;/p&gt;
" data-image-caption="&lt;p&gt;Android SDK size&lt;/p&gt;
" data-large-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/android_sdk_size.png?fit=348%2C243&amp;ssl=1" class="wp-image-323 size-medium" src="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/android_sdk_size.png?resize=300%2C209&#038;ssl=1" alt="Android SDK size - 41.6 GBs" width="300" height="209" srcset="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/android_sdk_size.png?resize=300%2C209&amp;ssl=1 300w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/android_sdk_size.png?w=348&amp;ssl=1 348w" sizes="auto, (max-width: 300px) 100vw, 300px" /></a><figcaption id="caption-attachment-323" class="wp-caption-text"><span style="font-size: 8pt;">Android SDK size</span></figcaption></figure>
<p style="text-align: left;">I’ve examined a bit more and it turns out that <strong>system images</strong> take the most of this space. Those are used only by emulators to be able to create a virtual device and debug on a simulator instead of deploying the app to a physical device every rime.</p>
<p style="text-align: left;">When I used to write some Android apps in Java and Android Studio long time ago, I found it very hard and complex to debug/test anything using emulator – it was simply very, very slow to load and work. This time I&#8217;ll see if emulator built in Visual Studio will do the job – if yes, why not using it ? I will of course also deploy directly to the device for tests, but it also takes time. I remember that when I wanted to test some small adjustments done “on the fly” (e.g. UI modifications/alignments) I dreamt about doing it quicker then deploying app to the phone every time. We’ll see, if emulator won’t do the job – I will clean up those folders.</p>
<h2 style="text-align: left;"> First issue in DSP</h2>
<p style="text-align: left;">I had to create a separate paragraph for that 🙂 Of course, it must have finally happened – first issue on my DSP way! Installation error, of course &#8211; <em>&#8220;Installation of &#8216;Xamarin&#8217; failed with more then one exception (attempt 3). It was not possible to complete an automatic installation.&#8221;</p>
<p></em></p>
<p style="text-align: left;">I expected the installation to terminate and evening spent on looking for a solution, exploring StackOverflow threads, but to my surprise a quite familiar-looking screen appeared explaining what to do next, i.e. how to install all the components manually. I had to download and install Java JDK, Android SDK and Xamarin.</p>
<p style="text-align: left;">After the next 30 minutes everything seemed to be installed. Just two last configuration steps in Visual Studio <a href="https://developer.xamarin.com/guides/android/getting_started/installation/windows/manual_installation/" target="_blank" rel="noopener">as described here.</a> Finally, to be able to run Android emulator Android Virtual Device Manager needs to be configured, <a href="https://developer.xamarin.com/guides/android/deployment,_testing,_and_metrics/debug-on-emulator/android-sdk-emulator/#Configuring_Virtual_Devices" target="_blank" rel="noopener">as this tutorial describes</a>.</p>
<h2 style="text-align: left;">Android Solution Creation</h2>
<p style="text-align: left;">I cloned my <a href="https://github.com/dsibinski/MoneyBack" target="_blank" rel="noopener">Git repository</a>, opened Visual Studio and created <em>MoneyBack</em> solution 😉 I chose the project of type <em>Blank App (Android). </em>Here’s what VS produced:</p>
<figure id="attachment_358" aria-describedby="caption-attachment-358" style="width: 207px" class="wp-caption aligncenter"><a href="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/VS_Android_Xamarin_Solution.png?ssl=1"><img data-recalc-dims="1" loading="lazy" decoding="async" data-attachment-id="358" data-permalink="https://www.codejourney.net/hello-xamarin-world-first-steps/vs_android_xamarin_solution/" data-orig-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/VS_Android_Xamarin_Solution.png?fit=202%2C310&amp;ssl=1" data-orig-size="202,310" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="VS_Android_Xamarin_Solution" data-image-description="&lt;p&gt;VS Android Xamarin Solution&lt;/p&gt;
" data-image-caption="&lt;p&gt;VS Android Xamarin Solution&lt;/p&gt;
" data-large-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/VS_Android_Xamarin_Solution.png?fit=202%2C310&amp;ssl=1" class=" wp-image-358" src="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/VS_Android_Xamarin_Solution.png?resize=207%2C318&#038;ssl=1" alt="VS Android Xamarin Solution" width="207" height="318" srcset="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/VS_Android_Xamarin_Solution.png?resize=195%2C300&amp;ssl=1 195w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/VS_Android_Xamarin_Solution.png?w=202&amp;ssl=1 202w" sizes="auto, (max-width: 207px) 100vw, 207px" /></a><figcaption id="caption-attachment-358" class="wp-caption-text"><span style="font-size: 8pt;">VS Android Xamarin Solution</span></figcaption></figure>
<p style="text-align: left;">Android Xamarin solution contains the following elements out-of-the-box:</p>
<ul>
<li><em>Properties<b> </b></em>– here <em>AssemblyInfo.cs</em> is probably well-known to all .NET developers (for the others: this file is .NET assembly’s metadata file, containing basic data about our application, like its name, version, company etc.), but there is also <em>AndroidManifest.xml, </em>which contains details and requirements for Android application, e.g. app’s name, supported SDKs versions numbers and required permissions for which the end user is asked when installing the app</li>
<li><em>References</em> – contains other assemblies required for the application to build; in case of Xamarin Android solution, it references both .NET assemblies like <em>System</em> or <em>System.Core</em> and <em>Mono.Android </em>assembly</li>
<li><em>Components</em> – stores Xamarin development packages that can be retrieved from <a href="https://components.xamarin.com/" target="_blank" rel="noopener">Components Store</a> (something like Xamarin-specific <em>Nuget</em>, I guess 😉 )</li>
<li><em>Assets</em> – allows to store additional files needed by the app (e.g. text files) available easily from the code</li>
<li><em>Resources</em><strong> – </strong>contains strings, images and layouts of the application</li>
</ul>
<h2>MainActivity</h2>
<p style="text-align: left;">Apart from above-mentioned folders, solution contains an <em>Activity </em>class (<em>MainActivity.cs</em>) which is decorated with <em>ActivityAttribute</em>:</p>
<pre><pre class="brush: csharp; title: ; notranslate">&#x5B;Activity(Label = &quot;MoneyBack&quot;, MainLauncher = true, Icon = &quot;@drawable/icon&quot;)]</pre>
<p style="text-align: left;">We&#8217;ll get into details of <em>activities</em> soon. For now, let&#8217;s just assume that:</p>
<pre><pre class="brush: csharp; title: ; notranslate">MainLauncher = true</pre>
<p style="text-align: left;">means that this class is the starting point of the application. It contains only one method:</p>
<pre><pre class="brush: csharp; title: ; notranslate">
protected override void OnCreate(Bundle bundle)
{
   base.OnCreate(bundle);

   // Set our view from the &quot;main&quot; layout resource
   SetContentView (Resource.Layout.Main);

}</pre>
<p style="text-align: left;">Again, we’ll dive into <a href="https://developer.xamarin.com/guides/android/application_fundamentals/activity_lifecycle/" target="_blank" rel="noopener">Android activity’s lifecycle</a> very soon, but we can already imagine that “OnCreate” method is called when the activity is created.</p>
<h2>MoneyBack on the phone</h2>
<p style="text-align: left;">I plugged my Huawei P8 to the laptop, hit F5 and hoped to see my app running on the device. Instead, two components were installed first as separate apps &#8211; <em>Mono Shared Runtime</em> and <em>Xamarin.Android API-25</em>. Those two are used in debug build mode to allow debugging stuff. It would be fine if I didn&#8217;t have to re-plug my phone after installation of each of these two, as phone was doing nothing after.</p>
<p style="text-align: left;"> Finally,  <em>MoneyBack</em> appeared on Huawei&#8217;s screen with sad, black empty canvas. I added some well-known sentence to become a real Xamarin-newbie:</p>
<figure id="attachment_384" aria-describedby="caption-attachment-384" style="width: 182px" class="wp-caption aligncenter"><a href="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/MoneyBack_HelloWorld_Xamarin.png?ssl=1" target="_blank" rel="noopener"><img data-recalc-dims="1" loading="lazy" decoding="async" data-attachment-id="384" data-permalink="https://www.codejourney.net/hello-xamarin-world-first-steps/moneyback_helloworld_xamarin/" data-orig-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/MoneyBack_HelloWorld_Xamarin.png?fit=201%2C354&amp;ssl=1" data-orig-size="201,354" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="MoneyBack_HelloWorld_Xamarin" data-image-description="&lt;p&gt;MoneyBack &amp;#8211; Hello world deployed to the phone&lt;/p&gt;
" data-image-caption="&lt;p&gt;MoneyBack &amp;#8211; Hello world deployed to the phone&lt;/p&gt;
" data-large-file="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/MoneyBack_HelloWorld_Xamarin.png?fit=201%2C354&amp;ssl=1" class="wp-image-384" src="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/MoneyBack_HelloWorld_Xamarin.png?resize=182%2C321&#038;ssl=1" alt="MoneyBack - Hello world deployed to the phone" width="182" height="321" srcset="https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/MoneyBack_HelloWorld_Xamarin.png?resize=170%2C300&amp;ssl=1 170w, https://i0.wp.com/www.codejourney.net/wp-content/uploads/2017/03/MoneyBack_HelloWorld_Xamarin.png?w=201&amp;ssl=1 201w" sizes="auto, (max-width: 182px) 100vw, 182px" /></a><figcaption id="caption-attachment-384" class="wp-caption-text"><span style="font-size: 8pt;">MoneyBack &#8211; Hello world deployed to the phone</span></figcaption></figure>
<h2>MoneyBack on the emulator</h2>
<p style="text-align: left;">I couldn’t initially manage to deploy my application to Android Emulator device. I tried creating few emulator devices – firstly I had issues with very strange resolution on the emulated device, then I created another one and when I tried to deploy on it I got an error saying “2&gt;Emulator is not ready to be used”. What I came up to is creating new Android Emulator Device, trying to start it (without deployment) and having “android” text on the device’s screen for the last 20 minutes. Then I found <a href="https://developer.xamarin.com/guides/android/getting_started/installation/accelerating_android_emulators/" target="_blank" rel="noopener">this emulation acceleration guide</a>, so I installed HAXM and it helped <strong>A LOT</strong>. Emulator is now starting within 30 seconds and I managed to deploy my app on it. Cool.</p>
<h2 style="text-align: left;">Summary</h2>
<p style="text-align: left;">Automatic installation of Xamarin on Windows with Visual Studio didn’t work, so I had to install all the packages manually, however it wasn’t problematic. Deployment to the phone was OK, but the installation of two additional components (<em>Mono Shared Runtime</em> and <em>Xamarin.Android API</em>) forced me to re-plug the device twice. I hope I won’t have this case very often, because if every deployment looks like that I’ll never finish this app…</p>
<p style="text-align: left;">I recommend everyone who wants to work with Android device emulator <a href="https://developer.xamarin.com/guides/android/getting_started/installation/accelerating_android_emulators/" target="_blank" rel="noopener">installing HAXM</a> &#8211; it really boosts the emulation.</p>
<div class="post">
<div class="body">
<div id="c4c4c9b5-cfa2-4848-a5d1-af794b4279f7" class="postBody" style="margin: 4px 0px 0px; border-width: 0px; padding: 0px;" contenteditable="true">
<p style="text-align: left;">Get ready for a deep dive into Xamarin soon 😎</p>
</div>
</div>
</div>
<p>&nbsp;</p>
<p>The post <a href="https://www.codejourney.net/hello-xamarin-world-first-steps/">Hello Xamarin World &#8211; first steps</a> appeared first on <a href="https://www.codejourney.net">CodeJourney.net</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.codejourney.net/hello-xamarin-world-first-steps/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">244</post-id>	</item>
		<item>
		<title>MoneyBack – requirements, functionalities and technologies</title>
		<link>https://www.codejourney.net/moneyback-requirements-functionalities-and-technologies/</link>
					<comments>https://www.codejourney.net/moneyback-requirements-functionalities-and-technologies/#comments</comments>
		
		<dc:creator><![CDATA[Dawid Sibiński]]></dc:creator>
		<pubDate>Fri, 03 Mar 2017 22:30:51 +0000</pubDate>
				<category><![CDATA[Others]]></category>
		<category><![CDATA[dajsiepoznac2017]]></category>
		<guid isPermaLink="false">http://www.dsibinski.pl/?p=269</guid>

					<description><![CDATA[<p>Hello again 🙂 It’s been a short while, WROC# conference was held in the meantime (it was great, by the way), but it’s time to write again. Write about DSP. More precisely: about MoneyBack, my project for the competition. Today I’d like to share with you my idea for the application &#8211; what I require&#8230;</p>
<p>The post <a href="https://www.codejourney.net/moneyback-requirements-functionalities-and-technologies/">MoneyBack – requirements, functionalities and technologies</a> appeared first on <a href="https://www.codejourney.net">CodeJourney.net</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p style="text-align: left;">Hello again <img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f642.png" alt="🙂" class="wp-smiley" style="height: 1em; max-height: 1em;" /> It’s been a short while, <a href="http://wrocsharp.com/" target="_blank" rel="noopener">WROC#</a> conference was held in the meantime (it was great, by the way), but it’s time to write again. Write about DSP. More precisely: about <em>MoneyBack</em>, my project for the competition.<br />
<span id="more-269"></span></p>
<p style="text-align: left;">Today I’d like to share with you my idea for the application &#8211; what I require from it, what functionalities I imagine it to have and what technologies I want to use. This is going to be rather short post, I don’t want to spend too much time on imagining the functionalities (I rather prefer to start working on it). It won’t be much detailed also, just a high-level overview of what I imagine my project to look like.</p>
<h2>A need</h2>
<p style="text-align: left;">As I already described in my <a href="https://www.codejourney.net/2017/02/hello-dajsiepoznac2017/" target="_blank" rel="noopener">DSP introduction post</a>, the idea for <em>MoneyBack</em> came from <strong>a need</strong>. I just need a kind of system, which would allow me to make splitting the money spent on a group’s needs easier. Currently I perform such tasks quite often and I do it manually. Those include any types of activities/things you paid for, whilst being used also by the others: food ordered with your workmates, beer you paid for in the pub with your friends, shopping made with your girlfriend, sports event you attended with a group of others or any other types of activities you can imagine.</p>
<p style="text-align: left;">I know there are many mobile/web applications doing that job, however <em>MoneyBack</em> will rather focus on the person who is the <em>payer</em> – it will help him/her firstly just to properly and easily split the costs and secondly – what is maybe more important – to keep the <em>others</em> informed/reminded (if necessary) about the money they owe.</p>
<h2 style="text-align: left;">Requirements and functionalities</h2>
<p style="text-align: left;">I will divide the requirements that <em>MoneyBack</em> application is going to meet into two groups: <em>must-haves</em> and <em>nice-to-haves</em>. By a <em>must-have</em> I understand something I essentially want the application to help me (and the people using it, hopefully <img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f642.png" alt="🙂" class="wp-smiley" style="height: 1em; max-height: 1em;" /> ) with, like the core and basic functionalities without which I can’t imagine it finished. Like the minimum requirements for my DSP project. On the other hand, by a <em>nice-to-have</em> I see a part of the system I’d love to have, but is not essential for the project being.</p>
<h5 style="text-align: left;">Must-haves:</h5>
<ul>
<li style="text-align: left;"><em>[Android]</em> Adding people (that are meant to be included in money splitting) by email (+ other personal details)</li>
<li style="text-align: left;"><em>[Android]</em> Creating one-time events/expenses with amount paid, people assigned, payment due date, bank account details, attachments (e.g. invoice/receipt PDF)</li>
<li style="text-align: left;"><em>[Android]</em> Automatic calculation of costs split per person</li>
<li style="text-align: left;"><em>[Android]</em> Generating one-time event’s/expense’s summary email to be sent to all participants with all the details</li>
<li style="text-align: left;"><em>[Android]</em> Marking particular event’s participants as “paid” (to indicate that person has already paid what he/she owes)</li>
<li style="text-align: left;"><em>[Android]</em> Notifications about a possibility to generate and send a reminder email to people who haven’t paid yet if the due date is coming</li>
<li style="text-align: left;"><em>[Android]</em> Creating recurring events (e.g. once per week, once per month etc.) + notifications about the summary emails to send when the recurring event’s date is coming</li>
<li style="text-align: left;"><em>[Android]</em> Possibility to export application’s data backup to GoogleDrive / file</li>
</ul>
<h5>Nice-to-haves:</h5>
<ul>
<li><em>[Android]</em> Adding people (that are meant to be included in money splitting) by phone number</li>
<li><em>[Android]</em> Possibility to connect person added with the Contact (integration with phonebook)</li>
<li><em>[Android/Web]</em> Possibility of account creation in the application for synchronization of application’s data to the web service</li>
<li><em>[Web]</em> Web interface allowing to login and see the details of events created in the mobile app</li>
<li><em>[Web]</em> Possibility to share a link to the event’s summary that can be given to all participants (so there is no need to send summary email)</li>
<li><em>[Web]</em> Managing the expenses/events in the web application</li>
<li><em>[Web]</em> Possibility of account creation on the web app</li>
<li><em>[Web]</em> Possibility to mark events as “monitored” so the reminder emails about payments are sent automatically to the participants from the server</li>
<li><em>[Android]</em> Support of multiple currencies (manual exchange rates definition) so that some people can pay in PLN, some in EUR for the same event</li>
<li><em>[Android]</em> Defining groups of people</li>
<li><em>[Android]</em> Possibility to download exchange rates from the Internet</li>
<li><em>[Android]</em> Defining expenses’ categories</li>
<li><em>[Android/Web]</em> Logging with social media (Fb, Google)</li>
<li><em>[Android/Web]</em> Charts/statistics for the payments/events/expenses
</li>
</ul>
<p style="text-align: left;">Those are just general requirements which came to my mind and they may change during the project’s development. <em><strong>Maybe you have some other ideas for such application’s functionalities that you’d find useful</strong></em> ? If yes, let me know in the comments.</p>
<h2>Technologies</h2>
<p style="text-align: left;">Above all, <em>MoneyBack</em> is going to be an <strong>Android</strong> application written in <strong>C#</strong> language using <strong>Xamarin</strong> platform. I will also need some good, but tiny local database on the device. I don’t know what are the best ones to use in Android/Xamarin (<em><strong>maybe some of you can advise me something</strong></em>?), but I suppose it could be for instance <strong>SQLite.</strong> I will mostly focus on the mobile app. In the worst case, as the very minimum, I’d like to finish mobile application so it meets the minimal requirements and is possible to be used by the others.</p>
<p style="text-align: left;">The second and very interesting part of <em>MoneyBack</em> project would be to have a <strong>web service</strong> with which the application would synchronize. It would require the replication of device’s local database structures on the server side and exposing some <strong>API</strong> after (maybe <strong>JSON</strong>?). Then it would be perfect to have a possibility to at least see created events/expenses details in the <strong>web app</strong>, which would require adding some web UI to the application. If I ever manage to get to this part, I would like to use <strong>ASP.NET Core</strong> for creating a simple server-side web app, maybe hosting it on some <strong>Linux</strong> machine. I’d also need some simple, but reliable database system, for example <strong>MySQL</strong> which could also be easily hosted on Linux server.</p>
<h2 style="text-align: left;">Summary</h2>
<p style="text-align: left;"><em>MoneyBack</em> will primarily be an Android app. If I manage to create web app it’s great. No more declarations for now, let’s start working. The next post in the scope of DSP will cover Xamarin installation into Visual Studio, configuration, first pieces of code and deployment of the application to the mobile phone.</p>
<p style="text-align: left;"><em><strong>I encourage you to give your feedback in the comments <img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f642.png" alt="🙂" class="wp-smiley" style="height: 1em; max-height: 1em;" /></p>
<p></strong></em></p>
<p style="text-align: left;">PS: I need to make a small disclaimer here: I have to admin – what I didn’t mention <a href="https://www.codejourney.net/2017/02/hello-dajsiepoznac2017/" target="_blank" rel="noopener">in my previous post</a> – that it was my creative girlfriend who came up with the name of the project <em>(MoneyBack,</em> initially <em>GiveMyMoneyBack)</em> who I’m cordially greeting from this place <img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f642.png" alt="🙂" class="wp-smiley" style="height: 1em; max-height: 1em;" /> I hope she will be supportive enough so I don’t arrive to the end of DSP with <em>MoneyBack,</em> but no girlfriend <img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f600.png" alt="😀" class="wp-smiley" style="height: 1em; max-height: 1em;" /> Plus as I’ve just made the disclaimer, she won’t have any claims to the app when it already makes millions of dollars <img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f609.png" alt="😉" class="wp-smiley" style="height: 1em; max-height: 1em;" /></p>
<p>The post <a href="https://www.codejourney.net/moneyback-requirements-functionalities-and-technologies/">MoneyBack – requirements, functionalities and technologies</a> appeared first on <a href="https://www.codejourney.net">CodeJourney.net</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.codejourney.net/moneyback-requirements-functionalities-and-technologies/feed/</wfw:commentRss>
			<slash:comments>16</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">269</post-id>	</item>
		<item>
		<title>Hello DajSiePoznac2017 !</title>
		<link>https://www.codejourney.net/hello-dajsiepoznac2017/</link>
					<comments>https://www.codejourney.net/hello-dajsiepoznac2017/#comments</comments>
		
		<dc:creator><![CDATA[Dawid Sibiński]]></dc:creator>
		<pubDate>Sat, 25 Feb 2017 16:36:55 +0000</pubDate>
				<category><![CDATA[Others]]></category>
		<category><![CDATA[dajsiepoznac2017]]></category>
		<guid isPermaLink="false">http://www.dsibinski.pl/?p=187</guid>

					<description><![CDATA[<p>Today I&#8217;d like to say &#8220;hello&#8221; to the programming competition Daj Sie Poznac 2017 (en. Get Noticed)  which I decided to take part in. For those who don&#8217;t know, DSP is organized by Maciej Aniserowicz, the owner of devstyle.pl blog, and it&#8217;s already its third edition this year. Basic concept of DSP Long story short, the&#8230;</p>
<p>The post <a href="https://www.codejourney.net/hello-dajsiepoznac2017/">Hello DajSiePoznac2017 !</a> appeared first on <a href="https://www.codejourney.net">CodeJourney.net</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p style="text-align: left;">Today I&#8217;d like to say &#8220;hello&#8221; to the programming competition <em>Daj Sie Poznac 2017 (</em>en. <em>Get Noticed)  </em>which I decided to take part in. For those who don&#8217;t know, DSP is organized by Maciej Aniserowicz, the owner of <a href="http://devstyle.pl/">devstyle.pl</a> blog, and it&#8217;s already its third edition this year.<br />
<span id="more-187"></span></p>
<h2>Basic concept of DSP</h2>
<p style="text-align: left;">Long story short, the main concept behind DSP is to develop an <strong>open-source project</strong> of any kind, in any technology, in the same time sharing your knowledge and project&#8217;s development processes by <strong>blogging about it</strong>. The competition lasts for <strong>3 months</strong> &#8211; from March to May &#8211; during which at least 10 weeks must be spent on project&#8217;s development and blogging. At least <strong>2 blog posts per week</strong> must be written, from which one must be about the project itself, and the other may be on any IT-related topic. As the project is open-source, <strong>source code is stored on public Git repository</strong> on GitHub.</p>
<h2 style="text-align: left;">My way for DajSiePoznac</h2>
<p style="text-align: left;">When the competition was held last year I regretted I finally didn&#8217;t take part. I was sure I must try the next year, so now it&#8217;s happening <img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f642.png" alt="🙂" class="wp-smiley" style="height: 1em; max-height: 1em;" /></p>
<p style="text-align: left;">Normally I have not much time for programming or developing pet projects after work, as I&#8217;m still finishing my Master&#8217;s studies on weekends, but this time I decided to take part in the competition as I think it may be (actually it already is!) very motivating to develop myself, broaden my horizons by exploring new technologies and finally to open for the programming community by blogging. I&#8217;m very excited, so let&#8217;s see how it goes!</p>
<h2 style="text-align: left;">Looking for a project&#8217;s idea</h2>
<p style="text-align: left;">I spent few weeks trying to find an idea for the project to do for DSP&#8217;17. I had two assumptions looking for it:</p>
<ul style="text-align: left;">
<li>technology must be .NET-related</li>
<li>the app/framework/solution to develop should solve a real life problem
</li>
</ul>
<p style="text-align: left;">Apart from those two, I&#8217;ve always wanted to develop an Android application using Xamarin, writing C# code. During my engineering studies I&#8217;ve had a chance to take part in a great project in which I was responsible for back-end development of an Android application, but it was written in Java. I also had almost no programming experience that time, so the quality of this product wasn&#8217;t the best (it was however very good project in the end).</p>
<p style="text-align: left;">I even installed Xamarin last year, but it wasn&#8217;t free for use yet that time &#8211; I had some student license, but I had that feeling that even if I create an app using it, after my license expires I would need to stop developing it or pay quite much for it. Now, as Xamarin was acquired by Microsoft and it&#8217;s free, it&#8217;s even more motivating to use it.</p>
<p style="text-align: left;">Apart from that, I&#8217;ve never finally programmed using Xamarin, so <strong>it&#8217;s totally new technology for me</strong> which is also the advantage I can learn it.</p>
<p style="text-align: left;">So I&#8217;ve had my technology chosen. Then, I considered many different ideas for the project, each time realizing that something like that already exists, which made me very demotivated&#8230; And then I realized that actually <strong>it doesn&#8217;t matter what idea or project I choose</strong>, if it already exists or not &#8211; it should be something I&#8217;d like to do and what seems interesting to myself. In the end that would be me developing that product*, right? <img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f609.png" alt="😉" class="wp-smiley" style="height: 1em; max-height: 1em;" /></p>
<p style="text-align: left;"><span style="font-size: 10pt;">* I used word &#8220;product&#8221; above, which means something that may be really used by the other people, but for me this may only be a &#8220;side effect&#8221; of DSP&#8217;s contribution. If I manage to create something useful for the others &#8211; that&#8217;d be great. If I don&#8217;t &#8211;  it&#8217;s still cool. The most important is to take a part in the competition, survive <img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f642.png" alt="🙂" class="wp-smiley" style="height: 1em; max-height: 1em;" /> to the end and be proud.</span></p>
<h2 style="text-align: left;"><em>MoneyBack</em> &#8211; my project for DSP&#8217;17</h2>
<p style="text-align: left;">Finally I decided to create an <strong>Android</strong> mobile application, written in <strong>Xamarin</strong> using <strong>C#</strong>, which purpose is to help <strong>settling the money between group of people</strong> (friends, family, workmates etc.).</p>
<p style="text-align: left;">Many times I&#8217;ve personally been in the situations when I pay for some activity in which a group of people take part. After, the money needs to be split between all participants. First of all, I&#8217;ve always done it manually, creating some Excel file which counted how much money does the particular person owns and to whom. Secondly, sometimes there are cumbersome situations when someone owns you the money, but just forgets about it (even you reminded him/her few times already) &#8211; you don&#8217;t want to be rude coming to the person all the time asking &#8220;give my money back, *****!&#8221; <img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f642.png" alt="🙂" class="wp-smiley" style="height: 1em; max-height: 1em;" /> ), so the app will do that for you. That&#8217;s why I called the project <em>MoneyBack</em> (wanted it to be <em>GiveMyMoneyBack</em> initially, but I consider it too long!) &#8211; there are already many costs-splitting applications, but this one will rather focus on the person who pays for the others. Of course its other purposes are just to split the amounts between the people, calculate who owns how much to whom, send notifications to the participants etc. so you don&#8217;t need to use Excel or contact everyone separately to tell them how much they owe you and for what.</p>
<p style="text-align: left;">More details to come. I&#8217;ll focus on the mobile app first. I&#8217;d like to create also some kind of web service (e.g. using ASP.NET Core, which would also be the technology I&#8217;ve not used so far), with which the app would synchronize (e.g. to present the summary and current state of settlements on the web page visible to all participants or keep the history and backups), but I don&#8217;t want to make any declarations. First, let&#8217;s focus on the Android side, then we&#8217;ll see <img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f642.png" alt="🙂" class="wp-smiley" style="height: 1em; max-height: 1em;" /></p>
<p style="text-align: left;">You will be able to find <em>MoneyBack</em>&#8216;s source code on <a href="https://github.com/dsibinski/MoneyBack">GitHub</a>.</p>
<h2 style="text-align: left;">Summary</h2>
<p style="text-align: left;">Next weeks and months (hopefully!) are going to be intensive. I hope I&#8217;ll arrive to the end of DSP&#8217;17. I wish all the participants good luck and all the best in your daily works on your projects <img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f642.png" alt="🙂" class="wp-smiley" style="height: 1em; max-height: 1em;" /> See you soon!</p>
<p>The post <a href="https://www.codejourney.net/hello-dajsiepoznac2017/">Hello DajSiePoznac2017 !</a> appeared first on <a href="https://www.codejourney.net">CodeJourney.net</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.codejourney.net/hello-dajsiepoznac2017/feed/</wfw:commentRss>
			<slash:comments>9</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">187</post-id>	</item>
	</channel>
</rss>
