<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Sandeep Tengale on Medium]]></title>
        <description><![CDATA[Stories by Sandeep Tengale on Medium]]></description>
        <link>https://medium.com/@stengale?source=rss-30f1144e0198------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*YoHuRmT4KzdPH6iMdQ6QIQ.png</url>
            <title>Stories by Sandeep Tengale on Medium</title>
            <link>https://medium.com/@stengale?source=rss-30f1144e0198------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 14:47:50 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@stengale/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Creating an EC2 Instance in AWS and SSHing to it]]></title>
            <link>https://stengale.medium.com/creating-an-ec2-instance-in-aws-and-sshing-to-it-a34d858631fa?source=rss-30f1144e0198------2</link>
            <guid isPermaLink="false">https://medium.com/p/a34d858631fa</guid>
            <category><![CDATA[ssh]]></category>
            <category><![CDATA[putty]]></category>
            <category><![CDATA[ec2]]></category>
            <category><![CDATA[cloud-computing]]></category>
            <category><![CDATA[aws]]></category>
            <dc:creator><![CDATA[Sandeep Tengale]]></dc:creator>
            <pubDate>Fri, 19 Apr 2019 11:49:56 GMT</pubDate>
            <atom:updated>2019-04-19T11:49:56.271Z</atom:updated>
            <content:encoded><![CDATA[<p>Today was my first experience with Amazon Web Server. I know its very late first experience story since AWS popularity is considered. But I was happy with free Heroku all these days.</p><p>So it will be a very beginner article you may also get it done by reading AWS docs easily, but you can also refer my steps if you get stuck somewhere or maybe we together have faced the same misunderstanding.</p><p>I got to know that in AWS in there is the concept of EC2 (Elastic Cloud computing) instance which follow IAAS concept of cloud computing. It has to be experienced first. Here is AWS doc says</p><blockquote>AWS is a web service that provides secure, resizable compute capacity in the cloud. It is designed to make web-scale cloud computing easier for developers. Amazon EC2’s simple web service interface allows you to obtain and configure capacity with minimal friction.</blockquote><p>Let&#39;s start with what title says instead of giving a well-known intro. All I wanted to do in this article is to create</p><ul><li>EC2 instance</li><li>SSH into it using Putty</li></ul><p>We may need the following tools for this task to complete. Please download the version suitable for your OS and system version.</p><ul><li>PuttyGen from <a href="https://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html">here</a></li><li>Putty from <a href="https://www.putty.org/">here</a></li></ul><p>When you select the services, we will get so many services to see. I can capture only a few in with my Snipper tool</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*93-sykXR0BRaHWKqOEZS3g.png" /><figcaption>Console Home of AWS services</figcaption></figure><p>In the compute section, we can see EC2, the one which we want to use now. Once you select it you will be given an option to Launch an instance</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/835/1*kiqsrLhGfIK6iZT-dHExLA.png" /><figcaption>Creation of new instance</figcaption></figure><p>Once you say Launch Instance, AWS provides you with a list of images of a different operating system which includes a lot of Linux distros such as Ubuntu, SUSE, RedHat, Amazon Linux, and many Windows flavors. You can select anyone. I always select Ubuntu because am more familiar with the Ubuntu command line and its keywords.</p><p>If you are using free tier account like me, select the default option here</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vv0zwxE__li1deuhLJ_37Q.png" /></figure><p>This configuration means</p><pre>t2.micro (Variable ECUs, 1 vCPUs, 2.5 GHz, Intel Xeon Family, 1 GiB memory, EBS only)</pre><p>Next, in configuration steps, keep default options</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*R2vMUlwhucxX-g-CgBDLIQ.png" /></figure><p>Next step is to define storage, change it if you need otherwise default 8GB would be sufficient</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gh_g3PaRj9mcE2ClT2HGjw.png" /></figure><p>Next step will ask you to add tags which are not important at this stage, you can skip it. Next step is important which is about configuring the Security groups. It is at this step you can decide which port you want to open to the outside world at what IP range. You can set both inbound and outbound rules with this step. General practice is outbound traffic is allowed for all traffic and all port. Inbound traffic is restricted so that only limited traffic can able to enter our system. By default, AWS allows only Port 22 for any IP as inbound traffic. Meaning we can use our system with Port 22 with the help of SSH, we can open other ports depending on our requirement. For now, I will keep only Port 22 open on my system. But you can add custom ports like shown below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WdZkckkeJMchYdBvVSxHMg.png" /><figcaption>TCP Port 22 open for all IP</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/420/1*ezLIDhBOJeYA9laCGaFRGg.png" /><figcaption>Custom configuration for security groups</figcaption></figure><p>This the last step once you say <strong>Review and Launch. </strong>Your instance is ready to use. Before we can use it, AWS provides an important dialog asking to create custom keys. Select <strong>create custom keys </strong>and say <strong>Download key Pair. </strong>This will get &lt;provided_key_name&gt;.pem.</p><p>Since am running on windows I need to get .pem to converted into .ppk file. We need to use PuttyGen for this task.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/637/1*EezjlKqhMuiQiLyRoYeoqQ.png" /><figcaption>Load .pem file and save the private key</figcaption></figure><p>Putty needs a private key to SSH into the instance. The key we downloaded is in .pem format. We can load the .pem file into PuttyGen using <strong>Load, </strong>once it gets successfully loaded, we can ask to <strong>Save private key(.ppk).</strong></p><blockquote><strong>Important: </strong>Try to keep these two files in a safe repository as AWS allows them to save only once. If these files get lost or corrupted it not possible to generate again and gets difficult to SSH into that instance again.</blockquote><p>Now we have .ppk file, open Putty.exe</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*HIfgRcHIZOk-2En266LEag.png" /></figure><p>Load .ppk file in the highlighted area. On left panel it should be in Connection -&gt; SSH -&gt; Auth.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*WX1FMHxquDhviAyEc_uBDw.png" /></figure><p>Next step, go to Sessions, enter you <strong>ec2 </strong>instance Public IP address and Port 22. Remember we kept Port 22 open from any IP, so it will allow you. If you say <strong>Open</strong>, you should see a cute and powerful Unix terminal. It will ask for username, enter <strong>ubuntu </strong>if its a ubuntu instance and you are good to go.</p><p>We finally SSHed into an EC2 instance, it is as good as Ubuntu terminal, we can do anything with it.</p><p>Happy learning :-)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a34d858631fa" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Deploy Angular APP on AWS EC2 instance]]></title>
            <link>https://stengale.medium.com/deploy-angular-app-on-aws-ec2-instance-20749f17b33e?source=rss-30f1144e0198------2</link>
            <guid isPermaLink="false">https://medium.com/p/20749f17b33e</guid>
            <category><![CDATA[deployment]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[ec2]]></category>
            <dc:creator><![CDATA[Sandeep Tengale]]></dc:creator>
            <pubDate>Fri, 19 Apr 2019 10:20:27 GMT</pubDate>
            <atom:updated>2019-04-19T10:24:21.352Z</atom:updated>
            <content:encoded><![CDATA[<h3>Deploy Angular App on AWS EC2 instance</h3><p>In this article, we are going to look at how we can deploy an Angular App developed using Angular 6 or 7 (Angular 2 onwards) on Amazon web server EC2 instance.</p><p>TL;DR this is written for beginners(just like me) who are new to EC2 and Angular who want to deploy simple Angular App on AWS.</p><p>I assume that you are familiar with basic AWS terms such as EC2 instance, security group, etc. In simple words…</p><p>An EC2 instance is just like a remote system running with Ubuntu (or any other Linux flavor provided by AWS), on which we can install required servers, software, plugins, etc. I will soon write an article on how to create an ec2 instance and use it.</p><h4><strong>1. Create an Angular App</strong></h4><p>First, create a Simple Angular App using basic Angular CLI commands.</p><p>Install Angular CLI first locally</p><pre>npm install -g @angular/cli</pre><p>Create a demo app</p><pre>ng new my-demo-app</pre><p>Get into your app and run it</p><pre>cd my-demo-app<br>ng serve --open</pre><p>Now we can see App running in localhost:4200. A simple App which any Angular beginner starts with. Read more from <a href="https://angular.io/guide/quickstart">here</a>. Now its time to deploy this App on AWS.</p><h4>2. Deploy to EC2 instance</h4><p>Since we already have an App ready we are all set to deploy it. Hope you have EC2 instance ready and SSHed in it with Putty or your terminal. If you don’t know this process, will explain it in my next article.</p><p>Once you SSHed in it. You will be having a blank terminal with very basic software in it. Next, we will start with the installation of a few importance packages such as a server, git, vim, etc.</p><h4>2.1 Installations</h4><p>Update your Ubuntu packages</p><pre>sudo apt-get update</pre><p>Install git to pull your code</p><pre>sudo apt-get install -y git</pre><p>Install npm and nodejs</p><pre>sudo apt-get install -y npm<br>sudo apt-get install -y nodejs</pre><p>We will use Ngnix server for this setup</p><pre>sudo apt-get install -y nginx</pre><p>If everything is fine, if you hit &lt;public_ip&gt;:8080, you will see NGNIX running page. Meaning your server is running on the given port.</p><p>Next, install Angular CLI, needed to run Angular services.</p><pre>sudo npm install -g @angular/cli</pre><h4>2.2 Configure Ngnix</h4><pre>cd /etc/nginx/sites-available</pre><p>create a file your with the site name</p><pre>sudo vim &lt;your-site-name&gt;</pre><p>Update File with below content</p><pre>server {     <br>    listen 80;      <br>    listen [::]:80;      <br>    server_name http://your-site-name.com;      <br>    root /var/www/my-demo-app/dist;   <br>    server_tokens off;   <br>    index index.html index.htm;     <br> <br>    location / {         <br>        # First attempt to server request as file, then         <br>        # as directory, then fall back to displaying a 404.          <br>        try_files $uri $uri/ /index.html =404;      <br>    }<br>}</pre><p>In the above file, change ‘your-site-name.co’ with your site name and `root` details to your app-name.</p><blockquote>Quick background whenever any webserver want to show a home page, it will look for index.html, when we build an Angular App it will create bunch of files (htmls, assets, css, js) which will be used to show the content of the site. Here root should be such that it point to the directory where index.html should be present.</blockquote><p>Let&#39;s save this file and link it in another directory</p><pre>cd /etc/nginx/sites-enabled <br>sudo ln -s ../sites-available/{your-site-name} <br>ls -l<br>sudo rm default //removes default directory</pre><h4>2.3 Build</h4><p>Now its time to bring in the code and build.</p><p>Go to a directory where we want to generate the build and clone your code. Please push the app which you created in the first step to some git repository such as Github, Bitbucket, Gitlab. So that we can pull that code in here. We can pass the code using some FTP software also, but Git will be an easy and clean method.</p><pre>cd /var/www<br>sudo git clone https://my-demo-app</pre><p>Change directory to your app, and build it</p><pre>cd /var/www/my-demo-app<br>ng build --prod --build-optimizer</pre><p>If ng build throw some Angular devkit error, run below statement and try to build again</p><pre>sudo npm update</pre><p>This will generate the <strong>/dist</strong> folder inside <strong>/var/www/my-demo-app/dist</strong></p><p>Now restart Ngnix server</p><pre>service nginx restart</pre><p>Now your App should be running, try <strong>public_ip </strong>in your favorite browser.</p><p>Hope you see your page.</p><p>Thanks for reading, I followed these steps from <a href="https://joeonsoftware.com/2018/08/12/deploy-an-angular-app-in-production-with-nginx-ubuntu-on-ec2/">here</a> and got my App working in my first attempt. Keep reading and Keep coding :-)</p><p>&amp; Let me know if you stuck at some point, happy to help...</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=20749f17b33e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Writing good BaseActivity class for Android Activity]]></title>
            <link>https://stengale.medium.com/writing-good-baseactivity-class-for-android-activity-100636c81011?source=rss-30f1144e0198------2</link>
            <guid isPermaLink="false">https://medium.com/p/100636c81011</guid>
            <category><![CDATA[android-development]]></category>
            <category><![CDATA[android-design-patterns]]></category>
            <category><![CDATA[android-design]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[Sandeep Tengale]]></dc:creator>
            <pubDate>Sat, 23 Jun 2018 04:22:01 GMT</pubDate>
            <atom:updated>2018-06-23T04:22:01.525Z</atom:updated>
            <content:encoded><![CDATA[<p>We all do many activities which are common to the most of the screens. Most famous are</p><ul><li>Design on Toolbar</li><li>Set action for back button</li><li>Set Title to toolbar</li><li>Show/Dismiss ProgressDialog</li></ul><p>Many have NavigationDrawer as a common component. I don’t think its wise to write all the component each time we want to design the screen since these components need to be consistent on all screen. Even if you able to achieve it by separate implementation consistency is difficult to achieve and it’s not good idea to write this for each screen. It’s at this point where we can think of moving this implementation to the Base class/ BaseActivity and use them in the SubActivity.</p><p>Now let’s start writing the base class/activity. In my example, I want to add common Toolbar which has a back button, Screen Title, and some UI control widgets such as ProgressDialog.</p><p>Leave the ProgressDialog aside as we can implement it as the independent component. First start with the basic design of the screen where we have a back button, screen title and page content. Before that set your screen as a full screen/No Action bar in your theme</p><pre>&lt;style name=&quot;AppTheme&quot; parent=&quot;Theme.AppCompat.Light.NoActionBar&quot;&gt;<br>    &lt;!-- Customize your theme here. --&gt;<br>    &lt;item name=&quot;colorPrimary&quot;&gt;@color/color_primary&lt;/item&gt;<br>    &lt;item name=&quot;colorPrimaryDark&quot;&gt;@color/color_primary_dark&lt;/item&gt;<br>    &lt;item name=&quot;colorAccent&quot;&gt;@color/color_accent&lt;/item&gt;<br>&lt;/style&gt;</pre><p>Now you have full screen to design the your toolbar (default ActionBar won’t appear)</p><p>Lets see the layout design first activity_base.xml</p><pre>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;<br>&lt;android.support.design.widget.CoordinatorLayout<br>    xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;<br>    xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;<br>    android:layout_width=&quot;match_parent&quot;<br>    android:layout_height=&quot;match_parent&quot;&gt;<br><br>    &lt;LinearLayout<br>        android:layout_width=&quot;match_parent&quot;<br>        android:layout_height=&quot;match_parent&quot;<br>        android:orientation=&quot;vertical&quot;&gt;<br><br>        &lt;android.support.v7.widget.Toolbar<br>            app:contentInsetEnd=&quot;0dp&quot;<br>            app:contentInsetLeft=&quot;0dp&quot;<br>            app:contentInsetRight=&quot;0dp&quot;<br>            app:contentInsetStart=&quot;0dp&quot;<br>            android:layout_width=&quot;match_parent&quot;<br>            android:layout_height=&quot;56dp&quot;<br>            android:background=&quot;@color/color_primary&quot;<br>            android:contentInsetEnd=&quot;0dp&quot;<br>            android:contentInsetLeft=&quot;0dp&quot;<br>            android:contentInsetRight=&quot;0dp&quot;<br>            android:contentInsetStart=&quot;0dp&quot;&gt;<br><br>            &lt;include layout=&quot;@layout/layout_toolbar_back&quot; /&gt;<br>        &lt;/android.support.v7.widget.Toolbar&gt;<br><br>        &lt;FrameLayout<br>            android:id=&quot;@+id/layout_container&quot;<br>            android:layout_width=&quot;match_parent&quot;<br>            android:layout_height=&quot;match_parent&quot; /&gt;<br>    &lt;/LinearLayout&gt;<br><br>&lt;/android.support.design.widget.CoordinatorLayout&gt;</pre><p>layout_toolbar.xml</p><pre>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;<br>&lt;RelativeLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;<br>    xmlns:tools=&quot;http://schemas.android.com/tools&quot;<br>    android:layout_width=&quot;match_parent&quot;<br>    android:layout_height=&quot;match_parent&quot;<br>    android:background=&quot;@color/color_primary_vtu&quot;&gt;<br><br>    &lt;ImageButton<br>        android:id=&quot;@+id/image_back_button&quot;<br>        android:layout_width=&quot;wrap_content&quot;<br>        android:layout_height=&quot;wrap_content&quot;<br>        android:layout_centerVertical=&quot;true&quot;<br>        android:layout_marginStart=&quot;16dp&quot;<br>        android:background=&quot;@android:color/transparent&quot;<br>        android:src=&quot;@drawable/baseline_arrow_back_white_24&quot; /&gt;<br><br>    &lt;TextView<br>        android:id=&quot;@+id/text_screen_title&quot;<br>        style=&quot;@style/TextStyle16Sp&quot;<br>        fontPath=&quot;fonts/Roboto-Light.ttf&quot;<br>        android:layout_width=&quot;wrap_content&quot;<br>        android:layout_height=&quot;wrap_content&quot;<br>        android:layout_centerVertical=&quot;true&quot;<br>        android:layout_marginStart=&quot;24dp&quot;<br>        android:layout_toEndOf=&quot;@id/image_back_button&quot;<br>        android:fontFamily=&quot;@font/roboto_light&quot;<br>        android:textSize=&quot;20sp&quot;<br>        tools:text=&quot;Screen Title&quot; /&gt;<br>&lt;/RelativeLayout&gt;</pre><p>layout_toolbar.xml will create a screen with the common toolbar with screen title and back button. It is included to the activity_bar.xml inside Toolbar. FrameLayout “layout_container” is going to be the container for the screen content.</p><p>Now its time to create the BaseActivity as override the setContentView()</p><pre>override fun setContentView(layoutResID: Int) {<br>    var coordinatorLayout: CoordinatorLayout = <em>layoutInflater</em>.inflate(R.layout.<em>activity_back_base</em>, null) as CoordinatorLayout<br>    var activityContainer: FrameLayout = coordinatorLayout.findViewById(R.id.<em>layout_container</em>)<br>    mTextViewScreenTitle = coordinatorLayout.findViewById(R.id.<em>text_screen_title</em>) as TextView<br>    mImageButtonBack = coordinatorLayout.findViewById(R.id.<em>image_back_button</em>)<br><br>    <em>layoutInflater</em>.inflate(layoutResID, activityContainer, true)<br><br>    super.setContentView(coordinatorLayout)<br>}</pre><p>You can see first we create the instance of CoordinatorLayout from which we tool instance of FrameLayout, screen title TextView and back button ImageView. Later put your layout on the given FrameLayout using inflater.</p><p>Once you have the instances of TextView and ImageView for screen title and back button respectively. You can write some public methods to expose it to the Base class.</p><pre>fun setScreenTitle(resId: Int) {<br>    mTextViewScreenTitle.<em>text </em>= getString(resId)<br>}<br><br>fun setScreenTitle(title: String) {<br>    mTextViewScreenTitle.<em>text </em>= title<br>}<br><br>fun getBackButton(): ImageButton {<br>    return mImageButtonBack;<br>}</pre><p>Let see the typical Activity which extend this Base class and use it.</p><pre>public class MainActivity: BackBaseActivity() {<br>    override fun onCreate(savedInstanceState: Bundle?) {<br>        super.onCreate(savedInstanceState)<br>        setContentView(R.layout.<em>activity_main</em>)<br><br>        setScreenTitle(R.string.<em>title_home</em>)<br>        getBackButton().setImageDrawable(ContextCompat.getDrawable(this, R.drawable.<em>ic_done_black</em>))<br>getBackButton().setOnClickListener <strong>{ <br>    </strong>finish()<br><strong>}</strong></pre><pre>    }<br><br>}</pre><p>So we can set the Title, change back button image and set listeners (many more..)</p><p>You can do same by including NavigationDrawer, BottomNavigationView etc</p><p>You can also add some UI component like ProgressDialog which you want to use across all the Activities.</p><p>BaseActivity.java</p><pre>override fun onCreate(savedInstanceState: Bundle?) {<br>    super.onCreate(savedInstanceState)<br><br>    mProgressDialog = ProgressDialog(this)<br>    mProgressDialog.setMessage(&quot;Loading&quot;)<br>    mProgressDialog.setCancelable(false)<br>    mProgressDialog.<em>isIndeterminate </em>= true<br>}</pre><pre>fun showProgressDialog() {<br>    if(!mProgressDialog.<em>isShowing</em>) {<br>        mProgressDialog.show()<br>    }<br>}<br><br>fun dismissProgressDialog() {<br>    if (mProgressDialog.<em>isShowing</em>) {<br>        mProgressDialog.dismiss()<br>    }<br>}</pre><p>You can refer showProgressDialog() and dismissProgressDialog() in all your Activity. You can do many such things.</p><p>Its just a simple tutorials hope most of you know this concept. I am just trying to present the practice here.</p><p>Check the code on <a href="https://gist.github.com/sandeeptengale/c7249f67d56c9b51cef881b3b8fb724f">gist</a></p><p>Happy coding..</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=100636c81011" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Gradle Sync on Corporate Network/Secure Network/Proxy Network]]></title>
            <link>https://stengale.medium.com/gradle-sync-on-corporate-network-secure-network-proxy-network-486b0cccd079?source=rss-30f1144e0198------2</link>
            <guid isPermaLink="false">https://medium.com/p/486b0cccd079</guid>
            <category><![CDATA[proxy-server]]></category>
            <category><![CDATA[android-development]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[gradle]]></category>
            <category><![CDATA[android-gradle]]></category>
            <dc:creator><![CDATA[Sandeep Tengale]]></dc:creator>
            <pubDate>Thu, 21 Jun 2018 04:35:03 GMT</pubDate>
            <atom:updated>2018-06-21T04:35:03.045Z</atom:updated>
            <content:encoded><![CDATA[<p>Am writing this today because I just spent my whole working day doing this (gradle sync) in my office. Isn’t it waste of productivity?? Frustrating??</p><p>I think most of the Android developer who works for Big companies where security is at highest priority face the issues with Gradle sync. It’s because your organisation won’t let you download directly from outside network. It has to pass through your organisation’s proxy server, while doing so there are many security reasons because of which Gradle sync unable to complete successfully and also there are gradle configurations which we miss to do as a developers which take us hours of stackoverflow and trial &amp; error methods before we can successfully able to sync it.</p><p>I am working in similar network from past 3 years as an Android developer during which I came across different problems and experiences with Gradle. Here am sharing my hard earned experience with successful syncs.</p><p><strong>Problem</strong>: Unable to sync Gradle whenever we import the new project with some libraries/dependencies, adding new dependencies or upgrade existing dependencies</p><p>Before jumping into solution, we need to understand how gradle <strong>works </strong>for Android projects in short.</p><p>There is basically 2 <strong>build.gradle</strong> files in the typical Android project(can be more depending on your modules).</p><ul><li><strong>project level gradle</strong> — where we add dependencies which are required across all the modules like build tool, retrolamba etc</li><li><strong>module level gradle</strong> — where we add dependecies which will be used with the given module like butterknief, retrofit etc etc etc</li></ul><p>All the dependencies we download are hosted on different repos such as maven, bintray, maven2 and now on google().</p><p>Now understand the basic structure of the project level gradle in a standard App</p><pre><em>buildscript {<br>    repositories {<br>        google() <br>        jcenter()<br>    }<br>    dependencies {<br>        classpath &#39;com.android.tools.build:gradle:3.1.2&#39;<br>      <br>    }<br>}</em></pre><pre>allprojects {<br>    repositories {<br>        google()<br>        jcenter()<br>    }<br>}</pre><p>Look at the first part of above code(in italic font). repositories{} list all the repositories address from where below dependencies to be searched.</p><blockquote>Always double check the dependencies you have mentioned in dependencies {} should be present in above listed repository, if not find the repository name and add it to the list</blockquote><p>Now what repositories{} in allprojects{} is doing there??</p><blockquote>It will list all the repository from where Gradle should fetch your dependencies and favorite libraries. So all your module level dependencies will be referred from this list of repositories.</blockquote><p>You will always find the repository name along with dependency name in respective github pages. Here is my list where you will find most of the popular dependencies and almost never encounter library not found error</p><p>project level — build.gradle</p><pre>repositories {<br>    google()<br>    jcenter()<br>    mavenCentral()<br><br>    jcenter { url &quot;http://jcenter.bintray.com/&quot; }<br>    maven { url &quot;http://jcenter.bintray.com&quot;}<br>    maven { url &quot;https://plugins.gradle.org/m2/&quot; }<br>    maven { url &quot;http://repo1.maven.org/maven2&quot; }<br>    maven { url &quot;https://jitpack.io&quot; }<br>}</pre><p>module level — build.gradle</p><pre>repositories {<br>    google()<br>    jcenter()   <br>    mavenCentral()<br><br>    jcenter { url &quot;http://jcenter.bintray.com/&quot; }<br>    maven { url &quot;https://plugins.gradle.org/m2/&quot; }<br>    maven { url &quot;http://repo1.maven.org/maven2&quot; }<br>    maven { url &quot;https://jitpack.io&quot; }<br>    maven { url &quot;https://maven.google.com&quot; }<br><br>    flatDir {<br>        dirs &#39;libs&#39;<br>    }<br>}</pre><p>Some libraries need special repository to be referred, best example <a href="https://github.com/pardom-zz/ActiveAndroid">Active Android</a> or your own Nexus repository to fetch your own libraries</p><p><strong>Suggestion 1:</strong> Always check if you are using the correct version of the library and correct repository name to fetch your library. Adding above list of repo helps few times as most libraries are hosted on maven or bintray</p><p><strong>Suggestion 2</strong>: check if the proxy settings of your organisation are added to your gradle.properties present in your root directory of the project</p><pre>systemProp.http.proxyPort=<br>systemProp.http.proxyUser=<br>systemProp.http.proxyPassword=<br>systemProp.https.proxyPassword<br>systemProp.https.proxyHost=<br>systemProp.http.proxyHost=<br>systemProp.https.proxyPort=<br>systemProp.https.proxyUser=</pre><p>enter for both http and https, username and password are system username and password, host and port number you should get from system admin in your org.</p><p>You can also do this in Android studio</p><p>File -&gt; settings -&gt; Appearance &amp; Behavior -&gt; System Settings -&gt; HTTP Proxy -&gt; Manual Proxy configuration</p><p><strong>Suggestion 3</strong>: Change https to http in gradle-wrapper.properties</p><pre>distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip</pre><p>to</p><pre>distributionUrl=http\://services.gradle.org/distributions/gradle-4.4-all.zip</pre><p>make sure you are using correct version of gardle distribution that is compatible with the build tool version you specified in project level gradle. This information is specified in developer page for reference with the increase in build tool version, distribution version number also increases. see <a href="https://services.gradle.org/distributions/">here</a></p><p><strong>Suggestions 4</strong>: Look for your private user directory which usually present in <strong>c:/users/user_id/</strong></p><p>this directory will have a hidden directory called .gradle (make a hidden folder visible). It should contain gradle.properties (if not add it). It should also specify proxy settings just as specified in <strong>Suggestion 2</strong></p><p><strong>Suggestion 5</strong>: Enable maven repository in Android studio</p><p>File -&gt; Settings -&gt; search “maven” in search bar -&gt; check “Enable embedded Maven repository”</p><p><strong>Suggestion 6</strong>: This works like charm sometimes, but we need old SDK manager to do it. Sometime gradle sync shows the error because of SDK components and SDK is not passing proxy connection. Old SDK manager won’t appear in new SDK manager embedded in Android studio. Download SDKManager.exe manually by search. Enter into “option” tab and enter your proxy settings which will download SDK components smoothly</p><p><strong>Suggestion 6</strong>: Try to use updated the library for your projects. Sometimes library or SDK component you are using are dependent on gradle plugin or API level. i.e some dependencies version need a particular version of gradle plugin to run or particular Android API level to function.</p><p>So always try to update SDK to the latest API level and use the most updated build tool.</p><p>Example:</p><p>If you are trying to use firebase-messaging-17.0.0 with build tool</p><pre>classpath &#39;com.android.tools.build:gradle:2.3.0&#39;<br>classpath &#39;com.google.gms:google-services:3.3.1&#39;</pre><p>Gradle sync fail to execute and it never says the reason. But this works perfectly fine when I updated everything and SDK till API level 28 with Firebase to latest version</p><pre>classpath &#39;com.android.tools.build:gradle:3.1.3&#39;<br>classpath &#39;com.google.gms:google-services:4.0.1&#39;</pre><p>Its always good to use latest version of libraries if they are stable</p><blockquote>Sometimes we may face the certificate based issue</blockquote><p><strong>Suggestion 7</strong>: Android studio got an option to allow non-trusted certificates</p><p>File -&gt; Settings -&gt; search “certificates” -&gt; check “Accept non-trusted certificates automatically” -&gt; Apply -&gt; ok ;)</p><p><strong>Suggestion 8</strong>: There are cases where certificate issue won’t get resolved easily we have to manually add the certificate. will explain the steps to do this in my next article</p><p><strong>Suggestion 9</strong>: Always run the App directly keeping “Gradle online” before making “Gradle offline”, until you don’t get one successful build (.apk). Don’t just sync or rebuild project and assume that gradle build is successful.</p><p><strong>Suggestion 10</strong>: This is one of the worst suggestion I can give as it takes a lot of bandwidth and time later. But sometimes we have to do this since we are not left with any options</p><blockquote>Delete all cached dependencies from your private space and let the gradle to sync again from the beginning</blockquote><p>Basically, you have to delete .gradle, .androistudio, .m2 from you user directory and let the project to sync again. so that it can download all dependencies fresh again since all old dependencies are erased from the cache</p><p><strong>Suggestion 11</strong>: Whenever you update the Android studio take care to update build tools and version of SDK components, design libraries etc. Visit android developer page and look for new updates along with IDE</p><p><strong>Suggestion 12</strong>: Try clean and rebuild the project whenever you make any changes in libraries specially .aar files (updating .aar file). Always “gradle sync” again and “invalidate and restart” your Android studio to reflect the library classes.</p><p><strong>Suggestion 13</strong>: last but never the least</p><blockquote>Never update your Android Studio IDE before the import releases, you don’t know Gradle Sync can take any amount of time ;)</blockquote><p>That’s it guys hope you found it helpful, please let me know if you are facing any issues with gradle sync (if I can help) and also share me if you know any other methods to handle the sync issues in the comments (we can update suggestion list).</p><p>Thanks for reading. Happy coding :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=486b0cccd079" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Problem Solved 3: Android Full Screen View + Translucent + ScrollView + AdjustResize + Keyboard]]></title>
            <link>https://stengale.medium.com/problem-solved-3-android-full-screen-view-translucent-scrollview-adjustresize-keyboard-b0547c7ced32?source=rss-30f1144e0198------2</link>
            <guid isPermaLink="false">https://medium.com/p/b0547c7ced32</guid>
            <category><![CDATA[android-development]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[android-ui]]></category>
            <dc:creator><![CDATA[Sandeep Tengale]]></dc:creator>
            <pubDate>Mon, 21 May 2018 11:47:59 GMT</pubDate>
            <atom:updated>2018-09-17T09:20:05.648Z</atom:updated>
            <content:encoded><![CDATA[<p>A few days back I encountered with the requirement of designing full-screen view in Android. Meaning the screen should not have any color for status bar (i.e transparent), only icon should be made visible. Making this possible took sufficient time for me.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/523/1*est4hkmyvo8q0igdEnaQYg.png" /><figcaption>Screen shot of Uber App</figcaption></figure><p>In the context of Android, it is called Translucent. Basically, I want to make the screen Translucent but there are some added complexities in doing so such Scollview/NestScrollView and Keyboard are part of the screen.</p><p>Then I started looking on web what best I can do for this, found so many solutions and advises from Stackoverflow such as</p><ul><li>Make status bar color transparent i.e primaryDark color</li><li>Use Theme.AppCompat.Light.NoActionBar theme</li><li>set container Layout as android:fitsSystemWindows=”true”</li><li>Use android:windowSoftInputMode=”adjustResize”</li></ul><p>etc etc</p><p>Most of them worked for me, but I always encounter one or another blocker. My requirements are</p><ul><li>screen should be Translucent</li><li>have form items such as EditText, Button</li><li>Screen should resize when Keyboard opens up</li></ul><p>Making the screen Translucent worked for me easily but making this screen auto adjust when keyboard opens up was a bit tricky as I was using NestedScrollview to handle it. So the when keyboard opens up the top part of the screen become Scrollable to allow the user to use EditText efficiently keeping soft-keyboard open.</p><p>I will not talk about what all I tried, it better to see some the code which worked for me ultimately.</p><p>First edit your Theme in style.xml and make screen Translucent</p><pre>&lt;style name=&quot;ThemeFullSCreen&quot; parent=&quot;Theme.AppCompat.Light.NoActionBar&quot;&gt;<br>    &lt;item name=&quot;colorPrimary&quot;&gt;@color/primary_v2&lt;/item&gt;<br>    &lt;item name=&quot;colorPrimaryDark&quot;&gt;@color/primarydark_v2&lt;/item&gt;<br>    &lt;item name=&quot;colorAccent&quot;&gt;@color/accent_v2&lt;/item&gt;<br>    &lt;item name=&quot;android:statusBarColor&quot; tools:targetApi=&quot;lollipop&quot;&gt;@android:color/transparent&lt;/item&gt;<br>    &lt;item name=&quot;android:windowEnableSplitTouch&quot;&gt;false&lt;/item&gt;<br>    &lt;item name=&quot;android:windowTranslucentStatus&quot; tools:targetApi=&quot;kitkat&quot;&gt;true&lt;/item&gt;<br>    &lt;item name=&quot;android:windowTranslucentNavigation&quot; tools:targetApi=&quot;kitkat&quot;&gt;true&lt;/item&gt;<br>&lt;/style&gt;</pre><p>Make activity adjustResize in Manifest and also apply the created theme</p><pre>&lt;activity<br>    android:name=&quot;.views.MyActivity&quot;<br>    android:screenOrientation=&quot;portrait&quot;<br>    android:theme=&quot;@style/ThemeFullSCreen&quot;<br>    android:windowSoftInputMode=&quot;adjustResize&quot; /&gt;</pre><p>Now make some adjustment in your layout, keep NestedScrollView/ScrollView inside a container like LinearLayout or RelativeLayout and set android:fitsSystemWindows=”true” like</p><pre>&lt;RelativeLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;<br>    xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;<br>    xmlns:tools=&quot;http://schemas.android.com/tools&quot;<br>    android:layout_width=&quot;match_parent&quot;<br>    android:layout_height=&quot;match_parent&quot;<br>    tools:ignore=&quot;MissingPrefix&quot;&gt;</pre><pre>&lt;RelativeLayout<br>    android:layout_width=&quot;match_parent&quot;<br>    android:layout_height=&quot;match_parent&quot;<br>    android:layout_below=&quot;@id/image_header_movebw&quot;<br>    android:fitsSystemWindows=&quot;true&quot;&gt;<br><br>    &lt;android.support.v4.widget.NestedScrollView<br>        android:layout_width=&quot;match_parent&quot;<br>        android:layout_height=&quot;match_parent&quot;<br>        android:scrollbars=&quot;none&quot;&gt;</pre><p>Once all this done, some more work in your Activity to ajust window properties</p><pre>if (Build.VERSION.<em>SDK_INT </em>&gt;= Build.VERSION_CODES.<em>LOLLIPOP</em>) {<br>    Window window = getWindow();<br>    window.addFlags(WindowManager.LayoutParams.<em>FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS</em>);<br>    window.clearFlags(WindowManager.LayoutParams.<em>FLAG_TRANSLUCENT_STATUS</em>);<br>    window.setStatusBarColor(Color.<em>TRANSPARENT</em>);<br>}</pre><p>So here it is, the screen is called Full screen/Translucent with ScrollView containing keyboard. May be guessed it already, it works only for API level 21 and above.</p><p>I tried almost a day to achieve this implementation. If you are trying for a particular behavior and got stuck please comment below, will try my best to answer it. If this blog helped you, please hit the clap ;-)</p><p>References:</p><ul><li><a href="https://stackoverflow.com/questions/30882429/using-windowtranslucentstatus-with-collapsingtoolbarlayout">Using windowTranslucentStatus with CollapsingToolbarLayout</a></li><li><a href="https://medium.com/google-developers/why-would-i-want-to-fitssystemwindows-4e26d9ce1eec">Why would I want to fitsSystemWindows?</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b0547c7ced32" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Problem Solved 2: Access Token refresh with Okhttp Authenticator]]></title>
            <link>https://stengale.medium.com/problem-solved-2-access-token-refresh-with-okhttp-authenticator-5ccb798ede70?source=rss-30f1144e0198------2</link>
            <guid isPermaLink="false">https://medium.com/p/5ccb798ede70</guid>
            <category><![CDATA[android-security]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[retrofit2]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[okhttp]]></category>
            <dc:creator><![CDATA[Sandeep Tengale]]></dc:creator>
            <pubDate>Sun, 06 May 2018 17:24:04 GMT</pubDate>
            <atom:updated>2018-05-06T17:24:04.169Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Problem</strong>: Access Token Refresh mechanism — It’s a feature in most of the App that we use. We want to keep the user logged-in to our App until user voluntarily wants to Log out from the App. Do you like to login to your favorite App like Instagram, Twitter etc every time you open it. Not really….isn’t it..</p><p>Then how such Apps are handling this scenario. Do they really keep their single access-token/JWT (Json Web Token) active for so long, like Years? Not a good idea. Every access token/JWT has a short period of validity after that it will be expired. This is considered as a good security practice. Access keys will be expired after some time say 1–2 hours (in most of the projects I worked till now).</p><p>Next question, how to get the new access token if the existing access-token gets expired, it is not wise to make a user to log in again to generate the new key. It is at this stage we have an extra key with us called <strong>Refresh-Token</strong>.</p><p>Note: The standard practice that everyone follows in their Auth system is <strong>OAuth</strong>. Please check <a href="https://auth0.com/learn/refresh-tokens/">this</a> for more details on OAuth.</p><p>In short, the user will be provided with 2 keys namely <strong>Access-token</strong> and <strong>Refresh-token</strong>. <strong>Access-token</strong> is used to access the resources to which user is authorized to. <strong>Refresh-token</strong> is used to renew his access-token.</p><p>Long story short. The user can get access to his resource using Access-token, after some hours if his Access-token gets expired (401 UnAuthorized), Refresh-token can be used to get the new Access-token and continue the access to the resources (so no login needed)</p><h3>tl;dr</h3><p><strong>Android Perspective:</strong> If your backend is supporting OAuth, then your Access-token will be JWT (Json Web Token), which backend must send you on successful login to use your resource. Now you can check the validity of this JWT a.k.a Access-token by putting this whole key string <a href="https://jwt.io/">here</a>. You will get a lot of details out of it, but the most interesting thing is expiry date. It is after this expiry date, the JWT will not be valid anymore. So if you call your endpoint with this JWT, backend should respond with the 401 UnAuthorized response. This behavior is applicable for all the endpoint where valid JWT is needed to access it.</p><p>Now its time use another key which we have Refresh-token. Backend should provide another rest API which accepts Refresh-token and provides a new set of Access-token/JWT and Refresh-token. Now App should continue working with these new set of JWT and Refresh-token just like before.</p><p>Now as a App user this whole process looks seamless..</p><p>BUT how to handle this in our Android App development perspective. We don’t like to check everytime 401 UnAuthorised is returned for the endpoint. Get the JWT refreshed using refresh-token and remember the endpoint which got failed and call it again with the new JWT.</p><p>Doing this manually for each endpoint is really painful and I think it’s difficult to manage the code if this pattern has to be followed everywhere.</p><p>It’s at this time Okhttp networking library for Android will come for the support. If you are using Retrofit 2.0 with Okhttp this step can be handled in a more elegant way.</p><p>Okhttp has a concept of <a href="https://github.com/square/okhttp/wiki/Interceptors">Interceptor</a> which helps to monitor, rewrite, and retry calls. I have performed the operations like reading cookie values with the help of Interceptors. But in our problem, we want to read the response and perform retry based on the response. Before Okhttp 2+ we performed this whole task using this Interceptor. Now in Okhttp 2.0, we have Authenticaor described <a href="https://github.com/square/okhttp/blob/master/samples/guide/src/main/java/okhttp3/recipes/Authenticate.java">here</a></p><pre>public class TokenAuthenticator implements Authenticator {<br>    @Override<br>    public Request authenticate(Route route, Response response) throws IOException {<br>        if (response.code() == 401) {<br>            Call&lt;Void&gt; refreshCall = refereshAccessToken(refereshToken);<br><br>            //make it as retrofit synchronous call<br>            Response&lt;Void&gt; refreshResponse = refreshCall.execute();<br>            if (refreshResponse != null &amp;&amp; refreshResponse.code() == 200) {<br>                //read new JWT value from response body or interceptor depending upon your JWT availability logic<br>                newCookieValue = readNewJwtValue();<br>                return response.request().newBuilder()<br>                        .header(&quot;basic-auth&quot;, newCookieValue)<br>                        .build();<br>            } else {<br>                return null;<br>            }<br>        }<br>    }<br>}</pre><p>The Code looks self-explanatory, check response code if it is 401, call your refresh-token endpoint. It will provide the new JWT. Please make sure that refresh-token endpoint call is Synchronous (blocking type), otherwise, there are good chances that execution continues with a NULL value of response and authenticate will return a NULL value for Request Object which indicates 401 response.</p><p>Add this class while creating Okhttp client object</p><pre>mHttpClient.authenticator(new TokenAuthenticator());</pre><p>Now whenever 401 appears for any web request, control comes directly to authenticate() callsback. Calls refresh-token endpoint with refresh-token, create a new Request object with the update access-token/JWT and returns it. Thereafter API which got failed because of 401 will be triggered again and it works correctly this time since access-token is updated.</p><p>Hope the information is helpful :-)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5ccb798ede70" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Problem Solved 1: TransactionTooLargeException in Nougat]]></title>
            <link>https://stengale.medium.com/problem-solved-1-transactiontoolargeexception-in-nougat-18da99805e63?source=rss-30f1144e0198------2</link>
            <guid isPermaLink="false">https://medium.com/p/18da99805e63</guid>
            <category><![CDATA[android-nougat]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[android-sdk]]></category>
            <category><![CDATA[androiddev]]></category>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[Sandeep Tengale]]></dc:creator>
            <pubDate>Fri, 20 Apr 2018 07:07:18 GMT</pubDate>
            <atom:updated>2018-04-20T07:07:18.324Z</atom:updated>
            <content:encoded><![CDATA[<p>Hello, welcome to my new series where I like to talk about something about the specific problem and solution I ultimately satisfied with.</p><p>Today, we will be looking at TransactionTooLargeException which appears when we load heavy data in particular activity/fragment(specially the bitmap or image hex-string) and pass it from one activity to another activity or heavy data used on some activity and leave it and expect it to be there when returned by back-press. Interesting part is this exception only appears on the Nougat devices and more interesting we will not get to know where this exception has occurred(No line number info).</p><p>It is already discussed in <a href="https://stackoverflow.com/questions/43937166/transactiontoolargeexception-in-nougat?utm_medium=organic&amp;utm_source=google_rich_qa&amp;utm_campaign=google_rich_qa">this</a> stackoverflow thread.</p><p>Many commented like Android Intent has limitation on the capacity of the data being transferred from one Activity to another Activity i.e 1 MB or 500 KB depending on Android version. But limitation on transferring of the data was exist from before, but why TransactionTooLargeException is thrown only on the Nougat device but not on older version??</p><p>After going through more about this problem I got to know that Nougat has some breaking changes that’s way Saved Instances work. When Activity or Fragment get onto background or moved to backstack Android use to save that data however large it is, now Nougat has put the restriction of 1 MB on it. If the data gets more then this 1 MB limit, it will throw TransactionTooLargeException.</p><p>So I found this <strong>solution</strong></p><p>First create a view-less fragment as following with helper functions like pushData() and PopData() to store and restore data respectively into Bundle.</p><pre>public class SavedInstanceFragment extends Fragment {<br><br>    private static final String <em>TAG </em>= &quot;SavedInstanceFragment&quot;;<br>    private Bundle mInstanceBundle = null;<br><br>    public SavedInstanceFragment() { <br>        super();<br>        setRetainInstance( true );<br>    }<br><br>    public SavedInstanceFragment pushData( Bundle instanceState )<br>    {<br>        if ( this.mInstanceBundle == null ) {<br>            this.mInstanceBundle = instanceState;<br>        }<br>        else<br>        {<br>            this.mInstanceBundle.putAll( instanceState );<br>        }<br>        return this;<br>    }<br><br>    public Bundle popData()<br>    {<br>        Bundle out = this.mInstanceBundle;<br>        this.mInstanceBundle = null;<br>        return out;<br>    }<br><br>    public static final SavedInstanceFragment getInstance(FragmentManager fragmentManager )<br>    {<br>        SavedInstanceFragment out = (SavedInstanceFragment) fragmentManager.findFragmentByTag( <em>TAG </em>);<br><br>        if ( out == null )<br>        {<br>            out = new SavedInstanceFragment();<br>            fragmentManager.beginTransaction().add( out, <em>TAG </em>).commit();<br>        }<br>        return out;<br>    }<br>}</pre><blockquote><em>The containing activity should implement</em> onSaveInstanceState</blockquote><pre>@Override<br>protected void onSaveInstanceState(Bundle outState) {<br>    if (outState != null) {<br>        super.onSaveInstanceState(outState);<br><br>        SavedInstanceFragment.<em>getInstance</em>(getFragmentManager()).pushData((Bundle) outState.clone());<br>        outState.clear(); <br>    }<br>}</pre><p>means we are trying to save the data available from the onSavedInstanceState(Bundle) into the Bundle which we created in SavedInstanceFragment. Once it is not required i.e once we come back to the same screen we would like to take it back and use it again(i.e restore).</p><pre>@Override<br>protected void onRestoreInstanceState(Bundle savedInstanceState) {<br>    if (savedInstanceState != null) {<br>        super.onRestoreInstanceState(SavedInstanceFragment.<em>getInstance</em>(getFragmentManager()).popData());<br>    }<br>}</pre><pre>@Override<br>protected void onCreate(@Nullable Bundle savedInstanceState) {<br>    super.onCreate(SavedInstanceFragment.<em>getInstance</em>(getFragmentManager()).popData());<br>    setContentView(R.layout.<em>activity_dashboard</em>);<br>    //ButterKnife.<em>bind</em>(this);<br><br>}</pre><p>So basically it is like saving the state of screen to Bundle when we leave the screen and restoring once we come back, so that the system should not try to save huge data (bitmap or hexstring) and throw <a href="https://stackoverflow.com/questions/43937166/transactiontoolargeexception-in-nougat">T</a>ransactionTooLargeException.</p><p>I found this solution <a href="https://www.devsbedevin.com/avoiding-transactiontoolargeexception-on-android-nougat-and-up/">here</a>, I found it better compared to others which suggests to store data on the File etc</p><p>Thanks for reading, please leave comment if you find something incorrect in the solution. Will be happy to think and adopt it.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=18da99805e63" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Integrate SonarQube for Android Application Development]]></title>
            <link>https://stengale.medium.com/integrate-sonarqube-for-android-application-development-8e40ec28e343?source=rss-30f1144e0198------2</link>
            <guid isPermaLink="false">https://medium.com/p/8e40ec28e343</guid>
            <category><![CDATA[sonarqube]]></category>
            <category><![CDATA[clean-code]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[Sandeep Tengale]]></dc:creator>
            <pubDate>Sun, 16 Jul 2017 06:40:35 GMT</pubDate>
            <atom:updated>2017-07-16T06:44:40.024Z</atom:updated>
            <content:encoded><![CDATA[<p>Hello Android developers,</p><p>We all want our code to be of good quality so that it will be easy to maintain for a longer time. How much ever we try to write the best possible code still we find the scope of improvement. So we end up using code quality check tools like <strong>SoarQube</strong>, <strong>SonarLint</strong>, <strong>AndroidLint </strong>etc.</p><p>Android Studio already come with AndroidLint which can check the code quality and allow developers to improve them. Even there is a plugin for <a href="https://plugins.jetbrains.com/plugin/7238-sonarqube-community-plugin">SonarQube </a>which can suggest possible improvement per class straight in Development environment. I was happy using this plugin until my Project Manager started asking for the report which will list critical, major and trivial issues in the code to keep track for which I thought to generate the SonarQube report by installing on our server.</p><p>Here I am trying to explain how to generate SonarQube report using SonarQube</p><ol><li>Download SonarQube from <a href="https://www.sonarqube.org/downloads/">https://www.sonarqube.org/downloads/</a></li><li>Downloaded version will come in Zip, just unzip it</li><li>Goto /sonarcube/bin/&lt;platform-folder&gt;</li><li>Hit startsonar.bat to start running SonarQube on server</li><li>Now open <a href="http://localhost:8080/">http://localhost:</a>9000 to see admin panel of SonarQube</li><li>Login to user panel using “admin” for username and password</li></ol><p>YAy!! SonarQube server is successfully running on your machine. Next step is to make some changes in build.gradle files on your Android Project</p><p><strong>Step 1</strong>:</p><p>Open your project level build.gradle file. Add classpath dependencies just below your build path just like this</p><pre>buildscript {<br>    repositories {<br>        jcenter()<br>    }<br>    <strong>dependencies </strong>{<br>        classpath &quot;<strong>com.android.tools.build:gradle:2.3.3&quot;<br>        </strong>classpath &quot;<strong>org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:2.0.1</strong>&quot;<em><br>    </em>}<br>}</pre><p>Hit “Sync Now”</p><p><strong>Step 2</strong>:</p><p>Make some changes to build.gradle to module level gradle i.e the one present in /app folder</p><p>Add sonar plugins at the top of file just below android plugin</p><pre>apply plugin: <strong>&#39;com.android.application&#39;<br></strong>apply plugin<strong>: &#39;org.sonarqube&#39;<br></strong>apply plugin<strong>: &#39;jacoco-android&#39;</strong></pre><p>It’s Android version of jacoco, read more about jacoco <a href="http://www.eclemma.org/jacoco/">here</a></p><p>Now Project is ready to accept SonarQube Configuration. Now just pass the configuration and sync project</p><pre>sonarqube {<br>    properties {<br>        def libraries = project.android.sdkDirectory.getPath() + &quot;/platforms/android-23/android.jar&quot;/* + &quot;, build/intermediates/exploded-aar*//**//*classes.jar&quot;*/</pre><pre>    property &quot;sonar.sources&quot;, &quot;src/main/java&quot;<br>    property &quot;sonar.binaries&quot;, &quot;build/intermediates/classes/debug&quot;<br>    property &quot;sonar.libraries&quot;, libraries<br>    property &quot;sonar.tests&quot;, &quot;src/test/java, src/androidTest/java&quot;<br>    property &quot;sonar.java.test.binaries&quot;, &quot;build/intermediates/class/debug&quot;<br>    property &quot;sonar.java.test.libraries&quot;, libraries</pre><pre>    property &quot;sonar.jacoco.reportPath&quot;, &quot;build/jacoco/testDebugUnitTest.exec&quot;<br>    property &quot;sonar.java.coveragePlugin&quot;, &quot;jacoco&quot;<br>    property &quot;sonar.junit.reportsPath&quot;, &quot;build/test-results/debug&quot;<br>    property &quot;sonar.android.lint.report&quot;, &quot;build/outputs/lint-results&quot;</pre><pre>    }<br>    <br>}</pre><p>just copy -paste above code to bottom of build.gralde(app) and sync project. Hope it sync without any problem :P :D</p><p>AND you are done..Congratulations!! Now all the best for the Sonar Report, hope you get less count :D</p><p>Now run the gradle command to generate the report. If you using gradle wrapper, hope you are using we can use gradlew</p><p>Now run</p><p>$gradlew clean test jacocoTestReport sonarqube -Dsonar.host.url=http://localhost:9000 — info -stacktrace</p><p>It will run that gradle command and take couple of minutes and generate a report for you.</p><p>Finally, you can view the report by entering</p><p>http://localhost:9000/dashboard/index/&lt;project_name&gt;/&lt;module_name&gt;</p><p>Hope URL is self explanatory..</p><p>Please comment if you have any doubts..Till then</p><p>Keep your code clean :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8e40ec28e343" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>