<?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 Ramkumar N on Medium]]></title>
        <description><![CDATA[Stories by Ramkumar N on Medium]]></description>
        <link>https://medium.com/@ramkumarVR46?source=rss-7a890577a00f------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*rU9Pz9PFQ7iWiyJ_9E12HA.jpeg</url>
            <title>Stories by Ramkumar N on Medium</title>
            <link>https://medium.com/@ramkumarVR46?source=rss-7a890577a00f------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 17:42:18 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ramkumarVR46/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[ Android WebView]]></title>
            <link>https://medium.com/@ramkumarVR46/android-webview-75fddf4d6a97?source=rss-7a890577a00f------2</link>
            <guid isPermaLink="false">https://medium.com/p/75fddf4d6a97</guid>
            <category><![CDATA[androiddev]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[android-apps]]></category>
            <dc:creator><![CDATA[Ramkumar N]]></dc:creator>
            <pubDate>Mon, 31 Jul 2017 19:13:17 GMT</pubDate>
            <atom:updated>2017-07-31T19:13:17.928Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Display Web Pages as a part of your Activity Layout.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*WwN78iOX-HC74T9AHGxjOg.png" /><figcaption><strong>Android WebView</strong></figcaption></figure><h3><strong>What is Android WebView ?</strong></h3><p><strong>WebView</strong> is an Android provided View like <strong>TextView,EditText,Button</strong> etc. using this WebView we can<strong> load HTML pages</strong> as a part of your activity layout and it uses <strong>Webkit rendering engine</strong> to display web pages and includes methods to navigate<strong> forward</strong> and <strong>backward</strong> through a <strong>history</strong>, <strong>zoom in</strong> and <strong>out</strong>, perform <strong>text searches </strong>and more. by default WebView does not enable <strong>JavaScript</strong> so we can manually enable it by using <strong>WebSettings</strong> and can bind JavaScript code to client side android code.it’s easier to build WebView in your android application rather than <strong>performing a network request</strong> and then parsing the respond data and rendering it an android layout.if you want full fledged web browser then you probably want to invoke the browser application with a URL intent rather than show it with a WebView.</p><pre>Uri <strong>uri </strong>= Uri.<em>parse</em>(<strong>&quot;https://www.developer.android.com&quot;</strong>);<br>Intent <strong>intent </strong>= <strong>new </strong>Intent(Intent.ACTION_VIEW, <strong>uri</strong>);<br>startActivity(<strong>intent</strong>);</pre><blockquote><strong><em>In this post we will understand and work with the basic things and handling methods of Android WebView.</em></strong></blockquote><p>To get Internet access, request the<strong> INTERNET</strong> permission in your manifest file</p><pre>&lt;<strong>uses-permission android:name=&quot;android.permission.INTERNET&quot;</strong>/&gt;</pre><h3><strong>Adding a WebView to Your Application</strong></h3><pre>&lt;<strong>WebView<br>    android:layout_width=&quot;match_parent&quot;<br>    android:layout_height=&quot;match_parent&quot;<br>    android:id=&quot;@+id/webView&quot; </strong>/&gt;</pre><h3>Using JavaScript in WebView</h3><p>If the web page you want to load in your WebView is using <strong>JavaScript</strong> you <strong>must enable</strong> JavaScript for your WebView using <strong>WebSettings</strong> with <strong>getSettings()</strong> method then enable JavaScript with <strong>setJavaScriptEnabled() </strong>method.</p><pre><strong>webView</strong>.getSettings().setJavaScriptEnabled(<strong>true</strong>);</pre><p><strong>WebSettings :</strong> provides access to a variety of other settings for the WebView like <strong>user agent,zoom control,file access,database settings</strong> etc.<br><strong>setJavaScriptEnabled :</strong> to enable javascript execution.</p><h3>Binding JavaScript code to Android code</h3><p>If the loaded <strong>web page events that can communicate to the android client</strong>. for example your web page’s button clicking event can call the method in your android code to displays the toast notification to the user by creating interface between your <strong>JavaScript code and client side android code</strong>.</p><p>To bind a new interface between your JavaScript and Android code, call <strong>addJavascriptInterface()</strong>, passing it a class instance to bind to your JavaScript and an interface name that your JavaScript can call to access the class.</p><pre><strong>private class </strong>WebAppInterface {<br>    Context <strong>mContext</strong>;<br>    WebAppInterface(Context c) {<br>        <strong>mContext </strong>= c;<br>    }<br>    @JavascriptInterface<br>    <strong>public void </strong>showToast(String toast) {<br>        <strong>final </strong>String string = toast;<br>        <strong>handler</strong>.post(<strong>new </strong>Runnable() {<br>            @Override<br>            <strong>public void </strong>run() {<br>                Toast.<em>makeText</em>(<strong>mContext</strong>, string, Toast.<strong><em>LENGTH_SHORT</em></strong>).show();<br>            }<br>        });<br>    }<br>}</pre><p><strong>add addJavaScriptInterface.</strong></p><pre><strong>webView</strong>.addJavascriptInterface(<strong>new </strong>WebAppInterface(<strong>this</strong>),<strong>&quot;android&quot;</strong>);</pre><p><strong>sample.html</strong></p><pre>&lt;!DOCTYPE <strong>html</strong>&gt;<br>&lt;<strong>html</strong>&gt;<br>&lt;<strong>body</strong>&gt;<br>&lt;<strong>h2</strong>&gt;Sample HTML Page&lt;/<strong>h2</strong>&gt;<br>&lt;<strong>input type=&quot;button&quot; value=&quot;Say hello&quot; onClick=&quot;showAndroidToast(&#39;Hello Android!&#39;)&quot; </strong>/&gt;<br>&lt;<strong>script type=&quot;text/javascript&quot;</strong>&gt;<br>    function showAndroidToast(toast) {<br>        android.showToast(toast);<br>    }<br>&lt;/<strong>script</strong>&gt;<br>&lt;/<strong>body</strong>&gt;<br>&lt;/<strong>html</strong>&gt;</pre><p><strong>addJavascriptInterface (Object object,String name)</strong><br>this method allows JavaScript to access the java object’s method by injecting interface object using the supplied name. JavaScript interacts with java object on a private, <strong>background thread </strong>of this WebView so <strong>thread safety</strong> is an important task here.</p><blockquote><strong>Note :</strong> you must add the <a href="http://twitter.com/JavaScriptInterface"><strong>@JavaScriptInterface</strong></a> annotation if you set your <strong>targetedSdkVersion is 17 or higher</strong>.The object that is bound to your JavaScript runs in another thread and not in the thread in which it was constructed.</blockquote><pre><strong>handler</strong>.post(<strong>new </strong>Runnable() {<br>    @Override<br>    <strong>public void </strong>run() {<br>        Toast.<em>makeText</em>(<strong>mContext</strong>, string, Toast.<strong><em>LENGTH_SHORT</em></strong>).show();<br>    }<br>});</pre><p>here i am using <strong>Handler</strong> this allows you to send and process <strong>Message</strong> and <strong>Runnable objects</strong> associated with a thread&#39;s <strong>MessageQueue</strong>. Each Handler instance is associated with a single thread and that <strong>thread&#39;s message queue</strong></p><blockquote><strong>Caution :</strong> this produce a dangerous security issue because when the loaded HTML is <strong>untrustworthy</strong> this will mislead the application depends on attacker’s choice.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jGu05E97VsqyaqKo0AHEog.jpeg" /><figcaption><strong>WebView with Load URL and Bind JavaScript to Android</strong></figcaption></figure><h3>Handling Page Navigation</h3><p>If you click the link in the web page by default it will <strong>launch the web browser </strong>and loads the appropriate URL. so we have to create a client for <strong>override this behavior </strong>to load the clicked link within your WebView and also can be navigate backward and forward through the web page history that’s maintain by your WebView. android provides 2 client systems they are,</p><p><strong>WebViewClient</strong> using <strong>setWebViewClient()</strong><br>If you won’t require too many features,<strong> rendering HTML</strong> is enough you can use <strong>WebViewClient</strong>.</p><p><strong>WebChromeClient</strong> using <strong>setWebChromeClient()</strong><br>If you want to handle<strong> javascript dialogs,favicons,titles</strong> and <strong>progress</strong> you should use <strong>WebChromeClient</strong>.</p><pre><strong>webView</strong>.setWebViewClient(<strong>new </strong>WebViewClient(){<br>    @Override<br>    <strong>public boolean </strong>shouldOverrideUrlLoading(WebView view, String url) {<br>        <strong>webView</strong>.loadUrl(url);<br>        <strong>return true</strong>;<br>    }<br><br>    @Override<br>    <strong>public void </strong>onPageStarted(WebView view, String url, Bitmap favicon) {<br>        <strong>super</strong>.onPageStarted(view, url, favicon);<br>    }<br><br>    @Override<br>    <strong>public void </strong>onPageFinished(WebView view, String url) {<br>        <strong>super</strong>.onPageFinished(view, url);<br>        progressDialog.dismiss();<br>    }<br>});</pre><p>the following are the some override methods of WebViewClient</p><p><strong>shouldOverrideUrlLoading (WebView view,String url)</strong><br>This method returns false when the current WebView handles the requested URL so no need to override the URLloading else the host application handles the URLusing Intent.<br><strong>onPageStarted (WebView view,String url,Bitmap favicon)</strong><br>This method notify the host application that a page has started loading.<br><strong>onPageFinished (WebView view,String url)</strong><br> This method notify the host application that a page has finished loading.</p><h3>Navigating Web Page History</h3><p>WebView <strong>automatically stores the history</strong> of visited web pages so we can navigate backward and forward through the history with <strong>goBack()</strong> and <strong>goForward()</strong> methods.</p><pre>@Override<br><strong>public boolean </strong>onKeyDown(<strong>int </strong>keyCode, KeyEvent event) {<br>    <strong>if </strong>((keyCode == KeyEvent.<strong><em>KEYCODE_BACK</em></strong>) &amp;&amp; <strong>webView</strong>.canGoBack()) {<br>        <strong>webView</strong>.goBack();<br>        <strong>return true</strong>;<br>    }<br>    <strong>return super</strong>.onKeyDown(keyCode, event);<br>}</pre><p><strong>goBack()</strong> goes back in the history of this WebView.<br><strong>goForward()</strong> goes forward in the history of this WebView.<br><strong>canGoBack()</strong> returns true if the web page history for the user to visit.<br><strong>canGoForward()</strong> check whether there is a forward history.</p><p>Hope you have enjoyed this post,Feel free to comment below for doubts or chat with me in <a href="https://www.facebook.com/ram.kumar.796774"><strong>Facebook</strong></a> or drop me<strong> </strong><a href="http://ramkumartcemdu@gmail.com/"><strong>E-mail</strong></a> for replies. Share is care.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=75fddf4d6a97" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ Working with Android Shared Preferences]]></title>
            <link>https://medium.com/@ramkumarVR46/working-with-android-shared-preferences-4668efa298a8?source=rss-7a890577a00f------2</link>
            <guid isPermaLink="false">https://medium.com/p/4668efa298a8</guid>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[android-apps]]></category>
            <category><![CDATA[tutorial]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[androiddev]]></category>
            <dc:creator><![CDATA[Ramkumar N]]></dc:creator>
            <pubDate>Sun, 30 Jul 2017 19:29:48 GMT</pubDate>
            <atom:updated>2017-07-30T19:32:57.547Z</atom:updated>
            <content:encoded><![CDATA[<p>Understand Basic of <strong>Android SharedPreferences</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eXEvdArhYCQSHmtngBIypg.jpeg" /><figcaption>Login App using SharedPreferences</figcaption></figure><h3><strong>What is SharedPreferences?</strong></h3><p>Android provides several <strong>storage options</strong> to store persistent data <strong>Shared Preferences</strong> are one among them. using Android Shared Preferences to <strong>store</strong> and <strong>retrieve</strong> persistent <strong>key-value</strong> pairs of <strong>primitive types of data like booleans, floats, ints, longs, and strings</strong>.here the saved data is avail persist across user sessions(even if your application is killed). stored data is <strong>lost</strong> when you remove programmatically or uninstalling the application or clearing an application data.</p><h3><strong>Initialize SharedPreferences</strong></h3><p>📌 <strong>getSharedPreferences(String name,int mode)</strong> — use this if you need <strong>multiple preferences</strong> and this method returns one instance of the SharedPreferences object by calling preferences name. when the calling preferences are <strong>unavailable</strong> the android system would <strong>create</strong> the<strong> preferences </strong>named by its calling name.</p><pre>SharedPreferences <strong>mSharedPreferences </strong>= getSharedPreferences(<strong><em>PREFERENCE</em></strong>, Context.<strong><em>MODE_PRIVATE</em></strong>);<br>SharedPreferences.Editor <strong>mEditor </strong>= <strong>mSharedPreferences</strong>.edit();</pre><p><strong>name</strong> — desired preferences file name.<br><strong>mode</strong> — operating mode.</p><p>📎 <strong><em>MODE_PRIVATE</em></strong> — the default mode, where the created file can only be accessed by the calling application.<br>📎 <strong><em>MODE_WORLD_READABLE</em></strong> — creating world-readable files is very dangerous because it allows all other applications to have read access to the created file. As of N attempting to use this mode will throw a SecurityException.<br>📎 <strong><em>MODE_WORLD_WRITEABLE</em></strong> — creating world-writable files is very dangerous because it allows all other applications to have write access to the created file. As of N attempting to use this mode will throw a SecurityException.<br>📎 <strong><em>MODE_MULTI_PROCESS</em></strong> — this mode will check for modification of preferences even if the Shared Preference instance has already been loaded.</p><p>📌 <strong>getPreferences(int mode)</strong> — use this if you need <strong>only one preferences</strong> file to retrieve a SharedPreferences object for accessing preferences that are <strong>private to this activity.</strong></p><h3><strong>Write Data to SharedPreferences</strong></h3><p>create <strong>SharedPreferences.Editor</strong> object by calling <strong>edit()</strong> method to <strong><em>modify</em></strong> values here all changes are <strong><em>batched and not copied</em></strong> back to the original SharedPreferences until you call <strong>commit() or apply()</strong></p><pre>SharedPreferences.Editor mEditor = <strong>mSharedPreferences</strong>.edit();</pre><p><strong>add values</strong> using put methods such as <strong>putBoolean(),putString()</strong> etc. this put methods has 2 arguments <strong>key</strong> and <strong>value</strong>.</p><pre>mEditor.putString(<strong><em>PREF_SKIP_LOGIN</em></strong>,<strong>&quot;skip&quot;</strong>);</pre><p><strong>commit() vs apply()</strong></p><p><strong>commit()</strong> method which writes its preferences out to persistent storage synchronously.</p><p><strong>apply()</strong> method which commits its changes to the in-memory SharedPreferences <strong>immediately</strong> but starts an <strong>asynchronous</strong> commit to disk and you don’t worry about android component <strong>life cycles</strong> and their interaction with apply() writing to disk.</p><pre>mEditor.apply();</pre><h3><strong>Read Data from SharedPreferences</strong></h3><p><strong>read values</strong> using get methods such as <strong>getBoolean(),getString()</strong> etc.this get methods has 2 arguments <strong>key</strong> and <strong>default value.</strong> here default value returns only when the <strong>preference does not exist the value may be null</strong>.</p><p>check whether the preference is available​ or not using <strong>contains()</strong> method and this method takes <strong>preference name</strong> as an argument.</p><pre><strong>if</strong>(<strong>mSharedPreferences</strong>.contains(<strong><em>PREF_SKIP_LOGIN</em></strong>)){<br>    Intent intent = <strong>new </strong>Intent(LoginActivity.<strong>this</strong>,HomeActivity.<strong>class</strong>);<br>    startActivity(intent);<br>    finish();<br>}</pre><h3><strong>Sample Application</strong></h3><p>here is an sample <strong>Login Application</strong> which contains 3 activities that are <strong>Login, Register and Home Activities</strong> and using <strong>SharedPreferences</strong> to manage login behavior.</p><p>activity_login.xml</p><pre><em>&lt;?</em><strong>xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;</strong><em>?&gt;<br></em>&lt;<strong>LinearLayout<br>    xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;<br>    android:layout_width=&quot;match_parent&quot;<br>    android:layout_height=&quot;match_parent&quot;<br>    android:padding=&quot;20dp&quot;<br>    android:background=&quot;@color/colorPrimary&quot;<br>    android:orientation=&quot;vertical&quot;</strong>&gt;<br><br>    &lt;<strong>TextView<br>        android:text=&quot;@string/app_name&quot;<br>        android:textColor=&quot;#FFFFFF&quot;<br>        android:textAllCaps=&quot;true&quot;<br>        android:textSize=&quot;20sp&quot;<br>        android:gravity=&quot;center&quot;<br>        android:textStyle=&quot;bold&quot;<br>        android:layout_marginTop=&quot;150dp&quot;<br>        android:layout_marginBottom=&quot;20dp&quot;<br>        android:layout_width=&quot;match_parent&quot;<br>        android:layout_height=&quot;wrap_content&quot; </strong>/&gt;<br>    &lt;<strong>EditText<br>        android:id=&quot;@+id/user_name&quot;<br>        android:inputType=&quot;text&quot;<br>        android:padding=&quot;10dp&quot;<br>        android:layout_marginBottom=&quot;10dp&quot;<br>        android:background=&quot;@drawable/textbox&quot;<br>        android:hint=&quot;@string/user_name&quot;<br>        android:layout_width=&quot;match_parent&quot;<br>        android:layout_height=&quot;40dp&quot; </strong>/&gt;<br>    &lt;<strong>EditText<br>        android:inputType=&quot;textPassword&quot;<br>        android:background=&quot;@drawable/textbox&quot;<br>        android:layout_marginBottom=&quot;10dp&quot;<br>        android:padding=&quot;10dp&quot;<br>        android:id=&quot;@+id/user_passwd&quot;<br>        android:hint=&quot;@string/user_passwd&quot;<br>        android:layout_width=&quot;match_parent&quot;<br>        android:layout_height=&quot;40dp&quot; </strong>/&gt;<br>    &lt;<strong>Button<br>        android:id=&quot;@+id/loginBtn&quot;<br>        android:text=&quot;@string/login_button&quot;<br>        android:textAllCaps=&quot;false&quot;<br>        android:layout_width=&quot;match_parent&quot;<br>        android:layout_height=&quot;wrap_content&quot; </strong>/&gt;<br>    &lt;<strong>TextView<br>        android:id=&quot;@+id/register&quot;<br>        android:autoLink=&quot;none&quot;<br>        android:textColor=&quot;#FFFFFF&quot;<br>        android:layout_marginBottom=&quot;10dp&quot;<br>        android:text=&quot;@string/register&quot;<br>        android:layout_gravity=&quot;center&quot;<br>        android:layout_width=&quot;wrap_content&quot;<br>        android:layout_height=&quot;wrap_content&quot; </strong>/&gt;<br>&lt;/<strong>LinearLayout</strong>&gt;</pre><p>activity_register.xml</p><pre><em>&lt;?</em><strong>xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;</strong><em>?&gt;<br></em>&lt;<strong>LinearLayout<br>    xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;<br>    android:orientation=&quot;vertical&quot;<br>    android:padding=&quot;20dp&quot;<br>    android:background=&quot;@color/colorPrimary&quot;<br>    android:layout_width=&quot;match_parent&quot;<br>    android:layout_height=&quot;match_parent&quot;</strong>&gt;<br><br>    &lt;<strong>TextView<br>        android:text=&quot;@string/register_page&quot;<br>        android:textColor=&quot;#FFFFFF&quot;<br>        android:textAllCaps=&quot;true&quot;<br>        android:textSize=&quot;20sp&quot;<br>        android:gravity=&quot;center&quot;<br>        android:textStyle=&quot;bold&quot;<br>        android:layout_marginTop=&quot;150dp&quot;<br>        android:layout_marginBottom=&quot;20dp&quot;<br>        android:layout_width=&quot;match_parent&quot;<br>        android:layout_height=&quot;wrap_content&quot; </strong>/&gt;<br>    &lt;<strong>EditText<br>        android:id=&quot;@+id/name&quot;<br>        android:inputType=&quot;text&quot;<br>        android:padding=&quot;10dp&quot;<br>        android:layout_marginBottom=&quot;10dp&quot;<br>        android:background=&quot;@drawable/textbox&quot;<br>        android:hint=&quot;@string/user_name&quot;<br>        android:layout_width=&quot;match_parent&quot;<br>        android:layout_height=&quot;40dp&quot; </strong>/&gt;<br>    &lt;<strong>EditText<br>        android:inputType=&quot;textPassword&quot;<br>        android:background=&quot;@drawable/textbox&quot;<br>        android:layout_marginBottom=&quot;10dp&quot;<br>        android:padding=&quot;10dp&quot;<br>        android:id=&quot;@+id/passwd&quot;<br>        android:hint=&quot;@string/user_passwd&quot;<br>        android:layout_width=&quot;match_parent&quot;<br>        android:layout_height=&quot;40dp&quot; </strong>/&gt;<br>    &lt;<strong>Button<br>        android:id=&quot;@+id/registerBtn&quot;<br>        android:text=&quot;@string/register_page&quot;<br>        android:textAllCaps=&quot;false&quot;<br>        android:layout_width=&quot;match_parent&quot;<br>        android:layout_height=&quot;wrap_content&quot; </strong>/&gt;<br><br>&lt;/<strong>LinearLayout</strong>&gt;</pre><p>activity_home.xml</p><pre><em>&lt;?</em><strong>xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;</strong><em>?&gt;<br></em>&lt;<strong>RelativeLayout<br>    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>    tools:context=&quot;com.sharedpreferences.HomeActivity&quot;</strong>&gt;<br>    &lt;<strong>include<br>        layout=&quot;@layout/toolbar&quot;</strong>/&gt;<br>    &lt;<strong>TextView<br>        android:text=&quot;@string/welcome&quot;<br>        android:layout_centerInParent=&quot;true&quot;<br>        android:layout_width=&quot;wrap_content&quot;<br>        android:layout_height=&quot;wrap_content&quot; </strong>/&gt;<br><br>&lt;/<strong>RelativeLayout</strong>&gt;</pre><p>LoginActivity.java</p><pre><strong>public class </strong>LoginActivity <strong>extends </strong>AppCompatActivity {<br><br>    <strong>private </strong>EditText <strong>mUsername</strong>,<strong>mUserpasswd</strong>;<br>    <strong>private </strong>Button <strong>mLogin</strong>;<br>    <strong>private </strong>TextView <strong>mRegister</strong>;<br>    <strong>private </strong>String <strong>Name</strong>,<strong>Password</strong>;<br>    <strong>private </strong>SharedPreferences <strong>mSharedPreferences</strong>;<br>    <strong>public static final </strong>String <strong><em>PREFERENCE</em></strong>= <strong>&quot;preference&quot;</strong>;<br>    <strong>public static final </strong>String <strong><em>PREF_NAME </em></strong>= <strong>&quot;name&quot;</strong>;<br>    <strong>public static final </strong>String <strong><em>PREF_PASSWD </em></strong>= <strong>&quot;passwd&quot;</strong>;<br>    <strong>public static final </strong>String <strong><em>PREF_SKIP_LOGIN </em></strong>= <strong>&quot;skip_login&quot;</strong>;<br>    @Override<br>    <strong>protected void </strong>onCreate(Bundle savedInstanceState) {<br>        <strong>super</strong>.onCreate(savedInstanceState);<br>        setContentView(R.layout.<strong><em>activity_login</em></strong>);<br>        <strong>mSharedPreferences </strong>= getSharedPreferences(<strong><em>PREFERENCE</em></strong>, Context.<strong><em>MODE_PRIVATE</em></strong>);<br>        <strong>if</strong>(<strong>mSharedPreferences</strong>.contains(<strong><em>PREF_SKIP_LOGIN</em></strong>)){<br>            Intent intent = <strong>new </strong>Intent(LoginActivity.<strong>this</strong>,HomeActivity.<strong>class</strong>);<br>            startActivity(intent);<br>            finish();<br>        }<strong>else </strong>{<br>            <strong>mUsername </strong>= (EditText)findViewById(R.id.<strong><em>user_name</em></strong>);<br>            <strong>mUserpasswd </strong>= (EditText)findViewById(R.id.<strong><em>user_passwd</em></strong>);<br>            <strong>mLogin </strong>= (Button)findViewById(R.id.<strong><em>loginBtn</em></strong>);<br>            <strong>mRegister </strong>= (TextView)findViewById(R.id.<strong><em>register</em></strong>);<br>            <strong>mLogin</strong>.setOnClickListener(<strong>new </strong>View.OnClickListener() {<br>                @Override<br>                <strong>public void </strong>onClick(View view) {<br>                    <strong>if</strong>(validUserData()){<br>                        <strong>if</strong>(<strong>mSharedPreferences</strong>.contains(<strong><em>PREF_NAME</em></strong>) &amp;&amp; <strong>mSharedPreferences</strong>.contains(<strong><em>PREF_PASSWD</em></strong>)){<br>                            SharedPreferences.Editor mEditor = <strong>mSharedPreferences</strong>.edit();<br>                            mEditor.putString(<strong><em>PREF_SKIP_LOGIN</em></strong>,<strong>&quot;skip&quot;</strong>);<br>                            mEditor.apply();<br>                            Intent intent = <strong>new </strong>Intent(LoginActivity.<strong>this</strong>,HomeActivity.<strong>class</strong>);<br>                            startActivity(intent);<br>                            finish();<br>                        }<strong>else </strong>{<br>                            Toast.<em>makeText</em>(getApplicationContext(),<strong>&quot;Unable to Login Plz Register !!&quot;</strong>,Toast.<strong><em>LENGTH_SHORT</em></strong>).show();<br>                        }<br>                    }<strong>else </strong>{<br>                        Toast.<em>makeText</em>(getApplicationContext(),<strong>&quot;Unable to Login Plz Enter Valid Data !!&quot;</strong>,Toast.<strong><em>LENGTH_SHORT</em></strong>).show();<br>                    }<br>                }<br>            });<br>            <strong>mRegister</strong>.setOnClickListener(<strong>new </strong>View.OnClickListener() {<br>                @Override<br>                <strong>public void </strong>onClick(View view) {<br>                    Intent intent = <strong>new </strong>Intent(LoginActivity.<strong>this</strong>,RegisterActivity.<strong>class</strong>);<br>                    startActivity(intent);<br>                }<br>            });<br>        }<br>    }<br><br>    <strong>private boolean </strong>validUserData() {<br>        <strong>Name </strong>= <strong>mUsername</strong>.getText().toString().trim();<br>        <strong>Password </strong>= <strong>mUserpasswd</strong>.getText().toString().trim();<br>        <strong>return </strong>!(<strong>Name</strong>.isEmpty() || <strong>Password</strong>.isEmpty());<br>    }<br>}</pre><p>RegisterActivity.java</p><pre><strong>public class </strong>RegisterActivity <strong>extends </strong>AppCompatActivity {<br><br>    <strong>private </strong>EditText <strong>mName</strong>,<strong>mPasswd</strong>;<br>    <strong>private </strong>Button <strong>mRegisterBtn</strong>;<br>    <strong>private </strong>String <strong>Name</strong>,<strong>Password</strong>;<br>    <strong>public static final </strong>String <strong><em>PREFERENCE</em></strong>= <strong>&quot;preference&quot;</strong>;<br>    <strong>public static final </strong>String <strong><em>PREF_NAME </em></strong>= <strong>&quot;name&quot;</strong>;<br>    <strong>public static final </strong>String <strong><em>PREF_PASSWD </em></strong>= <strong>&quot;passwd&quot;</strong>;<br>    @Override<br>    <strong>protected void </strong>onCreate(<strong>final </strong>Bundle savedInstanceState) {<br>        <strong>super</strong>.onCreate(savedInstanceState);<br>        setContentView(R.layout.<strong><em>activity_register</em></strong>);<br>        <strong>mName </strong>= (EditText)findViewById(R.id.<strong><em>name</em></strong>);<br>        <strong>mPasswd </strong>= (EditText)findViewById(R.id.<strong><em>passwd</em></strong>);<br>        <strong>mRegisterBtn </strong>= (Button)findViewById(R.id.<strong><em>registerBtn</em></strong>);<br>        <strong>mRegisterBtn</strong>.setOnClickListener(<strong>new </strong>View.OnClickListener() {<br>            @Override<br>            <strong>public void </strong>onClick(View view) {<br>                <strong>if</strong>(validUserData()){<br>                    SharedPreferences mSharedPreference = getSharedPreferences(<strong><em>PREFERENCE</em></strong>, Context.<strong><em>MODE_PRIVATE</em></strong>);<br>                    SharedPreferences.Editor mEditor = mSharedPreference.edit();<br>                    mEditor.putString(<strong><em>PREF_NAME</em></strong>,<strong>Name</strong>);<br>                    mEditor.putString(<strong><em>PREF_PASSWD</em></strong>,<strong>Password</strong>);<br>                    mEditor.apply();<br>                    finish();<br>                }<br>            }<br>        });<br>    }<br><br>    <strong>private boolean </strong>validUserData() {<br>        <strong>Name </strong>= <strong>mName</strong>.getText().toString().trim();<br>        <strong>Password </strong>= <strong>mPasswd</strong>.getText().toString().trim();<br>        <strong>return </strong>!(<strong>Name</strong>.isEmpty() || <strong>Password</strong>.isEmpty());<br>    }<br>}</pre><p>HomeActivity.java</p><pre><strong>public class </strong>HomeActivity <strong>extends </strong>AppCompatActivity {<br><br>    @Override<br>    <strong>protected void </strong>onCreate(Bundle savedInstanceState) {<br>        <strong>super</strong>.onCreate(savedInstanceState);<br>        setContentView(R.layout.<strong><em>activity_home</em></strong>);<br>        Toolbar toolbar = (Toolbar)findViewById(R.id.<strong><em>toolbar</em></strong>);<br>        setSupportActionBar(toolbar);<br>    }<br>}</pre><p>in the above application user <strong>need not to be login each and every time</strong>. this application stores the user login data to <strong>SharedPreferences</strong> so we can <strong>avoid repetitions​ of login steps every time</strong>.</p><p>Hope you have enjoyed this post,Feel free to comment below for doubts or chat with me in <a href="https://www.facebook.com/ram.kumar.796774"><strong>Facebook</strong></a> or drop me<strong> </strong><a href="http://ramkumartcemdu@gmail.com/"><strong>E-mail</strong></a> for replies. Share is care.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4668efa298a8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Using Database in an Android App.]]></title>
            <link>https://medium.com/@ramkumarVR46/using-database-in-an-android-app-5cae9a90f4b?source=rss-7a890577a00f------2</link>
            <guid isPermaLink="false">https://medium.com/p/5cae9a90f4b</guid>
            <category><![CDATA[sqlite]]></category>
            <category><![CDATA[udacity]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[androiddev]]></category>
            <dc:creator><![CDATA[Ramkumar N]]></dc:creator>
            <pubDate>Thu, 06 Jul 2017 16:17:56 GMT</pubDate>
            <atom:updated>2017-07-06T16:17:56.760Z</atom:updated>
            <content:encoded><![CDATA[<h4><strong>Udacity Data Storage Course lesson 1-Pets App.</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/477/1*gkbDlXDUJy-dIQulsKh8GA.jpeg" /></figure><blockquote>before we move on this, we should know <strong>“why we need to go for data storage”</strong>.”data” does major roles in android application.traditionally applications are storing data into type specific variables so this leads to application’s data loss because of “variables are alive is still the activities are alive” in the application.for example “if you store some applications data into variables and working with it.after some time user may move on to other apps and gets back to this application.the user gets nothing because the stored data are destroyed when the app no longer visible”.Android provides several storage options to store data for storing persistent data.the following are the android provide storage options <br> Shared Preferences <br> Internal and External Storage<br> SQLite Database<br> Network Connection</blockquote><h3><strong>SQLite Database</strong></h3><p>Android provides full support for <strong>SQLite database</strong> which is ideal for store repeating or structured data such as contact information,parsed JSON data etc. SQLite is a <strong>lite weight</strong> database for android system and it stores data into <strong>Tables(rows&amp;columns)</strong> so it grows <strong>table size</strong> and <strong>searching data</strong> in the table is easily.all the stored data in the SQLite database is private for its own application we can’t access this outside of the application.we can download the database into text file through the applications file structure.it provides the CRUD functions and Constraints to the Tables.and also it provides the following data types to store the applications data they are <strong>NULL,INTEGER,REAL,Text,BLOB</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/335/1*G84mopQ21FNaefzWVF21Pw.png" /><figcaption><strong>Android SQLite</strong></figcaption></figure><p><strong>Steps to Create Database </strong><br><strong> </strong>📎 Define a Schema and Contract.<br><strong> </strong>📎 Create a Database using a SQL Helper.</p><h3><strong>Define a Schema and Contract</strong></h3><p>Schema is a formal declaration of <strong>how the database is organized</strong> and it reflects in the SQL statement that you use to create your database.”<strong>Contract class</strong>” is a container contains <strong>constants</strong> to define names for your database URIs,Tables and Columns and this allows to use Contract class constants across all other classes in the same package.the following are the key features of “Contract class”</p><blockquote>Define schema and have a convention for where to find database constants.<br>Remove the possibility of introducing spelling errors.<br>Ease of updating database schema.</blockquote><pre><strong>public final class </strong>PetContract {<br><br>    <strong>private </strong>PetContract() {<br>    }<br><br>    <strong>public static final class </strong>PetEntry <strong>implements </strong>BaseColumns {<br><br>        <strong>public static final </strong>String <strong><em>TABLE_NAME </em></strong>= <strong>&quot;pets&quot;</strong>;<br><br>        <strong>public static final </strong>String <strong><em>_ID </em></strong>= BaseColumns.<strong><em>_ID</em></strong>;<br>        <strong>public static final </strong>String <strong><em>COLUMN_NAME </em></strong>= <strong>&quot;name&quot;</strong>;<br>        <strong>public static final </strong>String <strong><em>COLUMN_BREED </em></strong>= <strong>&quot;breed&quot;</strong>;<br>        <strong>public static final </strong>String <strong><em>COLUMN_GENDER </em></strong>= <strong>&quot;gender&quot;</strong>;<br>        <strong>public static final </strong>String <strong><em>COLUMN_WEIGHT </em></strong>= <strong>&quot;weight&quot;</strong>;<br><br>        <strong>public static final int <em>GENDER_UNKNOWN </em></strong>= 0;<br>        <strong>public static final int <em>GENDER_MALE </em></strong>= 1;<br>        <strong>public static final int <em>GENDER_FEMALE </em></strong>= 2;<br><br>    }<br>}</pre><p><strong><em>You should consider the following 3 points to define your “Contract class”</em></strong></p><p>📌 Outer class named =&gt; “BlankContract” which defines that are <strong>global to your whole database</strong>.<br>📌 Inner class named =&gt; “BlankEntry” which defines your each table in the database.each inner class should implement a class called “<strong>BaseColumns</strong>”.<br>📌 String constants for <strong>table name</strong> and each of the <strong>table column headings</strong>.</p><blockquote><em>Note: By implementing the </em><strong><em>BaseColumns</em></strong><em> interface, your inner class can inherit a primary key field called _ID that some Android classes such as cursor adapters will expect it to have. It’s not required, but this can help your database work harmoniously with the Android framework.</em></blockquote><h3><strong>Create a Database using a SQL Helper</strong></h3><p>Android provides a useful set of APIs is available in the <strong>SQLiteOpenHelper </strong>class.that helps us to <strong>create</strong>,<strong>open</strong> and <strong>manage database connections</strong> by obtain references to your database.when your app needs to perform long running operations of creating and updating the database to call <strong>getWritableDatabase()</strong> or <strong>getReadableDatabase()</strong> methods.</p><p>To use SQLiteOpenHelper, create a subclass that overrides the <strong>onCreate()</strong>, <strong>onUpgrade()</strong> and <strong>onOpen()</strong> callback methods. You may also want to implement <strong>onDowngrade()</strong>, but it’s not required.</p><p><strong>onCreate()</strong> — Called when the database is created for the first time. This is where the creation of tables and the initial population of the tables should happen.<br><strong>onUpgrade()</strong> — Called when the database needs to be upgraded. The implementation should use this method to drop tables, add tables, or do anything else it needs to upgrade to the new schema version.</p><p><strong><em>“you must upgrade your application database by increment the database version when your application gets upgrade to avoid unwanted crashes”</em></strong></p><p><strong>onOpen()</strong> — Called when the database has been opened. The implementation should check <strong>isReadOnly()</strong> before updating the database.<br><strong>onDowngrade()</strong> — Called when the database needs to be downgraded.This is strictly similar to onUpgrade() method.</p><h3><strong>Implement SQLiteOpenHelper</strong></h3><p><strong>Create a class that extends from SQLiteOpenHelper.</strong></p><pre><strong>public class </strong>PetDbHelper <strong>extends </strong>SQLiteOpenHelper</pre><p><strong>Create constants for database name and database version.</strong></p><pre><strong>private static final </strong>String <strong><em>DATABASE_NAME </em></strong>= <strong>&quot;shelter.db&quot;</strong>;<br><strong>private static final int <em>DATABASE_VERSION </em></strong>= 1;</pre><p><strong>Create a constructor.</strong></p><pre><strong>public </strong>PetDbHelper(Context context) {<br>    <strong>super</strong>(context,<strong><em>DATABASE_NAME</em></strong>,<strong>null</strong>,<strong><em>DATABASE_VERSION</em></strong>);<br>}</pre><p><strong>Implement onCreate().</strong></p><pre><strong>private static final </strong>String <strong><em>SQL_CREATE_ENTRIES </em></strong>= <strong>&quot;CREATE TABLE &quot;</strong>+ PetEntry.<strong><em>TABLE_NAME </em></strong>+<strong>&quot; (&quot;<br>        </strong>+PetEntry.<strong><em>_ID</em></strong>+<strong>&quot; INTEGER PRIMARY KEY AUTOINCREMENT, &quot;<br>        </strong>+PetEntry.<strong><em>COLUMN_NAME </em></strong>+ <strong>&quot; TEXT NOT NULL, &quot;<br>        </strong>+PetEntry.<strong><em>COLUMN_BREED </em></strong>+ <strong>&quot; TEXT, &quot;<br>        </strong>+PetEntry.<strong><em>COLUMN_GENDER </em></strong>+ <strong>&quot; INTEGER NOT NULL, &quot;<br>        </strong>+PetEntry.<strong><em>COLUMN_WEIGHT </em></strong>+ <strong>&quot; INTEGER NOT NULL DEFAULT 0);&quot;</strong>;</pre><pre>@Override<br><strong>public void </strong>onCreate(SQLiteDatabase sqLiteDatabase) {<br>    Log.<em>v</em>(<strong><em>LOG_TAG</em></strong>,<strong><em>SQL_CREATE_ENTRIES</em></strong>);<br>    sqLiteDatabase.execSQL(<strong><em>SQL_CREATE_ENTRIES</em></strong>);<br>}</pre><p><strong>Implement onUpgrade().</strong></p><pre>@Override<br><strong>public void </strong>onUpgrade(SQLiteDatabase sqLiteDatabase, <strong>int </strong>i, <strong>int </strong>i1) {<br>    sqLiteDatabase.execSQL(SQL_DELETE_ENTRIES);<br>    onCreate(sqLiteDatabase);<br>}</pre><p><strong>execSQL()</strong> — it executes SQL statement in the database helper class and <strong>does’t return any actual data</strong>.so that is “NOT a SELECT or any other SQL statement” that return data.</p><p><strong>To access your database, instantiate your subclass of SQLiteOpenHelper.</strong></p><pre>PetDbHelper mDbHelper = <strong>new </strong>PetDbHelper(<strong>this</strong>);</pre><h3><strong>Insert data into a Database</strong></h3><p>Insert data into the database by passing a<strong> ContentValues object</strong> to the <strong>insert()</strong> method.</p><h4><strong>ContentValues class</strong></h4><p>this class is used for store set of <strong>key value pairs</strong> to store the data into database by simply pass this to insert() method.here key is a column name and the values are its column specified values.</p><p><strong>insert()</strong> — Convenience method for inserting a row into the database and this method <strong>return ID </strong>for newly inserted row if any <strong>error</strong> during insertion it <strong>returns -1</strong>.it takes 3 arguments they are</p><p><strong>table name</strong> — String: to insert the row into.<br><strong>nullColumnHack</strong> — String: this provides the name of nullable column name to explicitly insert a NULL into in the case where your values is empty.<br><strong>values</strong> — ContentValues: this map contains the initial column values for the row. The keys should be the column names and the values the column values.</p><pre>SQLiteDatabase database = <strong>mDbHelper</strong>.getWritableDatabase();<br><br>ContentValues contentValues = <strong>new </strong>ContentValues();<br>contentValues.put(PetEntry.<strong><em>COLUMN_NAME</em></strong>,<strong>&quot;Toto&quot;</strong>);<br>contentValues.put(PetEntry.<strong><em>COLUMN_BREED</em></strong>,<strong>&quot;Terrier&quot;</strong>);<br>contentValues.put(PetEntry.<strong><em>COLUMN_GENDER</em></strong>,PetEntry.<strong><em>GENDER_MALE</em></strong>);<br>contentValues.put(PetEntry.<strong><em>COLUMN_WEIGHT</em></strong>,7);<br><br><strong>long </strong>rowID = database.insert(PetEntry.<strong><em>TABLE_NAME</em></strong>,<strong>null</strong>,contentValues);</pre><h3><strong>Read data from a Database</strong></h3><p>To read from a database, use the <strong>query()</strong> method, passing it your selection criteria and desired columns.The results of the query are returned to you in a <strong>Cursor object</strong>.</p><h4><strong>query() vs rawQuery()</strong></h4><p><strong>rawQuery()</strong> is a traditional SQL query method and queries are specified in the form of String.raw queries may cause <strong>performance issue</strong> and have a major security issue of <strong>SQL Injection</strong>.</p><p><strong>query()</strong> method is to <strong>prevent</strong> your application database from SQL Injection attack by using <strong>PlaceHolders</strong> to assign the data from <strong>selectionArgs</strong> at run time in to query <strong>WHERE clause selection</strong>.the following are arguments which are passed into query() method.</p><p><strong>table name </strong>— the table to query.<br><strong>projection[]</strong> — a list of column to return.passing null will return all columns.<br><strong>selection</strong> — the column for WHERE clause.<br><strong>selectionArgs[]</strong> — You may include <strong>“?”</strong>s in selection, which will be replaced by the values from selectionArgs, in order that they appear in the selection. The values will be bound as Strings.<br><strong>groupBy </strong>— a filter declaring how to group rows.<br><strong>having</strong> — a filter declare which row gropus include in the cursors.<br><strong>orderBy </strong>— how to order the rows<br><strong>limit</strong> — limits the number of rows returned by the query.</p><pre>PetDbHelper mDbHelper = <strong>new </strong>PetDbHelper(<strong>this</strong>);<br>SQLiteDatabase sqLiteDatabase = mDbHelper.getReadableDatabase();<br><br>String[] projecton = {PetEntry.<strong><em>_ID</em></strong>,PetEntry.<strong><em>COLUMN_NAME</em></strong>,<br>        PetEntry.<strong><em>COLUMN_BREED</em></strong>,<br>        PetEntry.<strong><em>COLUMN_GENDER</em></strong>,<br>        PetEntry.<strong><em>COLUMN_WEIGHT</em></strong>};<br><br>Cursor cursor = sqLiteDatabase.query(PetEntry.<strong><em>TABLE_NAME</em></strong>,<br>        projecton,<br>        <strong>null</strong>,<br>        <strong>null</strong>,<br>        <strong>null</strong>,<br>        <strong>null</strong>,<br>        <strong>null</strong>);</pre><p>here the above case it just retrieve all the columns in a Pets Table without any specified order.</p><h4><strong>Cursor class</strong></h4><p>Cursor class provides a<strong> random read and write access</strong> to the <strong>result set </strong>returned by a database query() method.you must always call before you begin reading values.it starts at<strong> position -1</strong>.<strong>finally</strong> you should call <strong>close()</strong> on the cursor to release the resources.the following are the important methods which are provided by the Cursor class.<br><strong>moveToFirst()</strong> — Move the cursor to the first row.<br><strong>moveToLast()</strong> — Move the cursor to the last row.<br><strong>moveToNext()</strong> — Move the cursor to the next row.<br><strong>moveToPosition(int position)</strong> — Move the cursor to an absolute position.<br><strong>getColumnIndex(String columnName)</strong> — Returns the zero-based index for the given column name, or -1 if the column doesn’t exist.<br><strong>getCount()</strong> — Returns the numbers of rows in the cursor.<br><strong>getInt(int columnIndex)</strong> — Returns the value of the requested column as an int.<br><strong>getString(int columnIndex)</strong> — Returns the value of the requested column as a String.</p><pre><strong>int </strong>idColumnIndex = cursor.getColumnIndex(PetEntry.<strong><em>_ID</em></strong>);<br><strong>int </strong>nameColumnIndex = cursor.getColumnIndex(PetEntry.<strong><em>COLUMN_NAME</em></strong>);<br><strong>int </strong>breedColumnIndex = cursor.getColumnIndex(PetEntry.<strong><em>COLUMN_BREED</em></strong>);<br><strong>int </strong>genderColumnIndex = cursor.getColumnIndex(PetEntry.<strong><em>COLUMN_GENDER</em></strong>);<br><strong>int </strong>weightColumnIndex = cursor.getColumnIndex(PetEntry.<strong><em>COLUMN_WEIGHT</em></strong>);<br><br><strong>while</strong>(cursor.moveToNext()) {<br>    <strong>int </strong>curId = cursor.getInt(idColumnIndex);<br>    String name = cursor.getString(nameColumnIndex);<br>    String breed = cursor.getString(breedColumnIndex);<br>    <strong>int </strong>gender = cursor.getInt(genderColumnIndex);<br>    <strong>int </strong>weight = cursor.getInt(weightColumnIndex);<br>    textView.append(<strong>&quot;\n&quot; </strong>+ curId +<strong>&quot; - &quot; </strong>+ name + <strong>&quot; - &quot; </strong>+ breed + <strong>&quot; -  &quot; </strong>+ gender + <strong>&quot; - &quot; </strong>+ weight );<br>}</pre><p>here the above case all the retrieved data from cursor are just display in a TextView.</p><h3><strong>Update data in a Database</strong></h3><p>When you need to <strong>modify a subset of your database values</strong>, use the <strong>update()</strong> method.Updating the table combines the content values syntax of insert() with the where syntax of delete().it returns the <strong>no of rows updated</strong>.the following are the update() method arguments<br><strong>table name</strong> — table to be updated.<br><strong>values</strong> — contentvalues from columnames to new column values.<br><strong>whereClause</strong> — optional WHERE clause to apply when updating. Passing null will update all rows.<br><strong>whereArgs</strong> — You may include ?s in the where clause, which will be replaced by the values from whereArgs. The values will be bound as Strings.</p><pre>SQLiteDatabase <strong>db </strong>= <strong>mDbHelper</strong>.getReadableDatabase();<br><br>ContentValues <strong>values </strong>= <strong>new </strong>ContentValues();<br>values.put(PetEntry.<strong><em>COLUMN_NAME</em></strong>, mNewName);<br><br>String <strong>selection </strong>= PetEntry.<strong><em>COLUMN_NAME </em></strong>+ <strong>&quot; LIKE ?&quot;</strong>;<br>String[] <strong>selectionArgs </strong>= { <strong>&quot;Toto&quot; </strong>};<br><br><strong>int count </strong>= <strong>db</strong>.update(<br>        PetEntry.<strong><em>TABLE_NAME</em></strong>,<br>        <strong>values</strong>,<br>        <strong>selection</strong>,<br>        <strong>selectionArgs</strong>);</pre><h3><strong>Delete data from a Database</strong></h3><p>To delete rows from a table, you need to provide <strong>selection criteria that identify the rows</strong>. The database API provides a mechanism for creating selection criteria that <strong>protects against SQL injection</strong>. The mechanism divides the selection specification into a selection clause and selection arguments.<strong>it returns the no of rows affected</strong>.the following are the delete() method arguments<br><strong>table name</strong> — table to be deleted<br><strong>whereClause</strong> — the optional WHERE clause to apply when deleting. Passing null will delete all rows.<br><strong>whereArgs</strong> — You may include ?s in the where clause, which will be replaced by the values from whereArgs. The values will be bound as Strings.</p><pre>String selection = PetEntry.<strong><em>COLUMN_NAME </em></strong>+ <strong>&quot; LIKE ?&quot;</strong>;<br>String[] selectionArgs = { <strong>&quot;Toto&quot; </strong>};<br>sqLiteDatabase.delete(PetEntry.<strong><em>TABLE_NAME</em></strong>, selection, selectionArgs);</pre><h4><strong>Persisting Database Connection</strong></h4><p><strong>getWritableDatabase()</strong> and <strong>getReadableDatabase()</strong> are expensive to call when the database is closed, you should leave your database connection open for as long as you possibly need to access it. Typically, it is optimal to close the database in the <strong>onDestroy()</strong> of the calling Activity.</p><pre>@Override<br><strong>protected void </strong>onDestroy() {<br>    <strong>mDbHelper</strong>.close();<br>    <strong>super</strong>.onDestroy();<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/932/1*-ekVsCHAfm9LkDyMIqdCeA.png" /><figcaption><strong>Android SQLite Structure</strong></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*gP3rs4DO6X6nyMoyhm2GxA.jpeg" /><figcaption><strong>Pets App</strong></figcaption></figure><p>Hope you have enjoyed this post,Feel free to comment below for doubts or chat with me in <a href="https://www.facebook.com/ram.kumar.796774"><strong>Facebook</strong></a> or drop me<strong> </strong><a href="http://ramkumartcemdu@gmail.com/"><strong>E-mail</strong></a> for replies. Share is care.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5cae9a90f4b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ Android N 7.0 Notification’s Inline Reply ]]></title>
            <link>https://medium.com/@ramkumarVR46/android-n-7-0-notifications-inline-reply-8b8ea6a1854f?source=rss-7a890577a00f------2</link>
            <guid isPermaLink="false">https://medium.com/p/8b8ea6a1854f</guid>
            <category><![CDATA[androiddev]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[android-n]]></category>
            <category><![CDATA[android-apps]]></category>
            <dc:creator><![CDATA[Ramkumar N]]></dc:creator>
            <pubDate>Sun, 02 Jul 2017 08:49:35 GMT</pubDate>
            <atom:updated>2017-07-02T08:49:35.248Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>To know how Android Notification’s inline reply works fine*</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*s79KN4u-7NzVmAeY7a-YPQ.png" /><figcaption><strong>Android Notification’s Inline Reply</strong></figcaption></figure><p><strong>What is Notification</strong></p><p>A <strong>Notification</strong> is a <strong>Message</strong> you can display to the user outside of your application’s normal <strong>UI</strong>. When you tell the system to issue a notification, it first appears as an icon in the notification area. To see the details of the notification, the user opens the notification drawer. Both the <strong>Notification Area</strong> and the <strong>Notification Drawer</strong> are system-controlled areas that the user can view at any time.</p><p><strong>Creating Notification </strong><br>📎 <strong>NotificationCompat.Builder</strong> which returns a Notification <strong>object</strong> that contains your specified UI information and actions.To issue the notification, you pass the Notification object to the system by calling <strong>NotificationManager.notify()</strong>.</p><p>📎 A <strong>Notification Object</strong> must contain the following attributes.<br> setSmallIcon()<br> setContentTitle()<br> setContentText()</p><p>📎 Inside a Notification, the action itself is defined by a <strong>PendingIntent</strong> containing an Intent that starts an Activity in your application.</p><p>📎 An <strong>Action </strong>allows users to go directly from the notification to an Activity in your application.</p><h4><strong>Inline Reply to Notifications</strong><br>In<strong> Android 7.0(API 24)</strong> user can <strong>reply directly</strong> to text messages or <strong>update task lists</strong> from within the notification dialog.On a handheld, the inline reply action appears as an additional button displayed in the notification. When a user replies via keyboard, the system <strong>attaches the text response to the intent</strong> you had specified for the notification action and sends the intent to your handheld app.</h4><p><strong>Adding Inline Reply Actions</strong></p><p><strong>i)</strong> <strong>Create</strong> an instance of <strong>RemoteInput.Builder</strong> that you can add to your notification action.this instance requires a String that is the <strong>key</strong> for the text input and it is used for <strong>retrieve</strong> the text of the input.</p><pre><strong>private static final </strong>String KEY_TEXT_REPLY = <strong>&quot;key_text_reply&quot;</strong>;<br>String reply = <strong>&quot;reply&quot;</strong>;<br>RemoteInput remoteInput = <strong>new </strong>RemoteInput.Builder(KEY_TEXT_REPLY)<br>        .setLabel(reply)<br>        .build();</pre><p><strong>ii)</strong> <strong>Attach</strong> RemoteInput object to an action using <strong>addRemoteInput()</strong>.</p><pre>Notification.Action action = <strong>new </strong>Notification.Action.Builder(R.mipmap.<strong><em>ic_launcher_round</em></strong>,<br>        reply,pendingIntent)<br>        .addRemoteInput(remoteInput)<br>        .build();</pre><p><strong>iii)Apply the action</strong> to a Notification and issue the Notification.</p><pre>Notification.Builder builder =  <strong>new </strong>Notification.Builder(getApplicationContext())<br>        .addAction(action)<br>        .setAutoCancel(<strong>true</strong>)<br>        .setSmallIcon(R.mipmap.<strong><em>ic_launcher_round</em></strong>)<br>        .setContentTitle(<strong>&quot;INLINE REPLY...&quot;</strong>)<br>        .setContentText(<strong>&quot;hello...&quot;</strong>)<br>        .setContentIntent(pendingIntent);<br><br>NotificationManager manager = (NotificationManager)getSystemService(Context.<strong><em>NOTIFICATION_SERVICE</em></strong>);<br>manager.notify(<strong>mRequestCode</strong>,builder.build());</pre><p><strong><em>Note: The system prompts the user to input a response when they trigger the notification action.</em></strong></p><p><strong>Retrieving User Input from the Inline Reply</strong><br>To receive user input from the notification interface to the activity you declared in the reply action’s intent.</p><p><strong>i) Call getResultsFromIntent()</strong> by passing the notification action’s intent as the input parameter. This method returns a Bundle that contains the text response.</p><pre>Bundle remoteInput = RemoteInput.<em>getResultsFromIntent</em>(intent);</pre><p><strong>ii)</strong> <strong>Retrieve</strong> the i<strong>nput text using the key</strong> provided in the RemoteInput object.</p><pre><strong>private </strong>CharSequence getMessageText(Intent intent) {<br>    Bundle remoteInput = RemoteInput.<em>getResultsFromIntent</em>(intent);<br>    <strong>if</strong>(remoteInput != <strong>null</strong>){<br>        <strong>return </strong>remoteInput.getCharSequence(<strong><em>KEY_TEXT_REPLY</em></strong>);<br>    }<br>    <strong>return null</strong>;<br>}</pre><p><strong>iii)</strong> <strong>Build and issue another Notification</strong>, using the<strong> same notification ID</strong> that you provided for the previous notification. The progress indicator disappears from the notification interface to inform users of a successful reply.</p><pre>NotificationCompat.Builder mBuilder =<br>        <strong>new </strong>NotificationCompat.Builder(<strong>this</strong>)<br>                .setSmallIcon(R.mipmap.<strong><em>ic_launcher_round</em></strong>)<br>                .setContentText(<strong>&quot;Received&quot;</strong>);<br><br>NotificationManager mNotificationManager =<br>        (NotificationManager) getSystemService(Context.<strong><em>NOTIFICATION_SERVICE</em></strong>);<br>mNotificationManager.notify(<strong>mRequestCode</strong>, mBuilder.build());</pre><p><strong>Sample Code </strong><br>here the application just display the notification’s inline reply text message to the <strong>TextView</strong> in the<strong> Target Activity</strong>.</p><p><strong>activity_main.xml</strong></p><pre><em>&lt;?</em><strong>xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;</strong><em>?&gt;<br></em>&lt;<strong>RelativeLayout<br>    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>    tools:context=&quot;com.example.ramkumar.inlinereply.MainActivity&quot;</strong>&gt;<br><br>    &lt;<strong>Button<br>        android:id=&quot;@+id/btn1&quot;<br>        android:text=&quot;Notify Me&quot;<br>        android:layout_centerInParent=&quot;true&quot;<br>        android:layout_width=&quot;wrap_content&quot;<br>        android:layout_height=&quot;wrap_content&quot; </strong>/&gt;<br><br>&lt;/<strong>RelativeLayout</strong>&gt;</pre><p><strong>activity_notification_reply.xml</strong></p><pre><em>&lt;?</em><strong>xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;</strong><em>?&gt;<br></em>&lt;<strong>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>    tools:context=&quot;com.example.ramkumar.inlinereply.NotificationReply&quot;</strong>&gt;<br>    &lt;<strong>TextView<br>        android:id=&quot;@+id/txt1&quot;<br>        android:textStyle=&quot;bold&quot;<br>        android:layout_centerInParent=&quot;true&quot;<br>        android:layout_width=&quot;wrap_content&quot;<br>        android:layout_height=&quot;wrap_content&quot; </strong>/&gt;<br>&lt;/<strong>RelativeLayout</strong>&gt;</pre><p><strong>MainActivity.java</strong></p><pre><strong>public class </strong>MainActivity <strong>extends </strong>AppCompatActivity {<br><br>    <strong>private static final </strong>String <strong><em>KEY_TEXT_REPLY </em></strong>= <strong>&quot;key_text_reply&quot;</strong>;<br>    <strong>int mRequestCode </strong>= 1000;<br><br>    @Override<br>    <strong>protected void </strong>onCreate(Bundle savedInstanceState) {<br>        <strong>super</strong>.onCreate(savedInstanceState);<br>        setContentView(R.layout.<strong><em>activity_main</em></strong>);<br>        Button button = (Button) findViewById(R.id.<strong><em>btn1</em></strong>);<br>        button.setOnClickListener(<strong>new </strong>View.OnClickListener() {<br>            @Override<br>            <strong>public void </strong>onClick(View v) {<br>                inlineReply();<br>            }<br>        });<br>    }<br><br>    <strong>private void </strong>inlineReply() {<br><br>        String reply = <strong>&quot;reply&quot;</strong>;<br>        RemoteInput remoteInput = <strong>new </strong>RemoteInput.Builder(<strong><em>KEY_TEXT_REPLY</em></strong>)<br>                .setLabel(reply)<br>                .build();<br><br>        Intent intent = <strong>new </strong>Intent(MainActivity.<strong>this</strong>,NotificationReply.<strong>class</strong>);<br>        TaskStackBuilder taskStack = TaskStackBuilder.<em>create</em>(<strong>this</strong>);<br>        taskStack.addParentStack(NotificationReply.<strong>class</strong>);<br>        taskStack.addNextIntent(intent);<br><br>        PendingIntent pendingIntent = taskStack.getPendingIntent(0,PendingIntent.<strong><em>FLAG_UPDATE_CURRENT</em></strong>);<br><br>        Notification.Action action = <strong>new </strong>Notification.Action.Builder(R.mipmap.<strong><em>ic_launcher_round</em></strong>,<br>                reply,pendingIntent)<br>                .addRemoteInput(remoteInput)<br>                .build();<br><br>        Notification.Builder builder =  <strong>new </strong>Notification.Builder(getApplicationContext())<br>                .addAction(action)<br>                .setAutoCancel(<strong>true</strong>)<br>                .setSmallIcon(R.mipmap.<strong><em>ic_launcher_round</em></strong>)<br>                .setContentTitle(<strong>&quot;INLINE REPLY...&quot;</strong>)<br>                .setContentText(<strong>&quot;hello...&quot;</strong>)<br>                .setContentIntent(pendingIntent);<br><br>        NotificationManager manager = (NotificationManager)getSystemService(Context.<strong><em>NOTIFICATION_SERVICE</em></strong>);<br>        manager.notify(<strong>mRequestCode</strong>,builder.build());<br>    }<br>}</pre><p><em>NotificationReply.java</em></p><pre><strong>public class </strong>NotificationReply <strong>extends </strong>AppCompatActivity {<br><br>    <strong>private static final </strong>String <strong><em>KEY_TEXT_REPLY </em></strong>= <strong>&quot;key_text_reply&quot;</strong>;<br>    <strong>int mRequestCode </strong>= 1000;<br><br>    @Override<br>    <strong>protected void </strong>onCreate(Bundle savedInstanceState) {<br>        <strong>super</strong>.onCreate(savedInstanceState);<br>        setContentView(R.layout.<strong><em>activity_notification_reply</em></strong>);<br>        TextView textView = (TextView)findViewById(R.id.<strong><em>txt1</em></strong>);<br>        textView.setText(getMessageText(getIntent()));<br><br>        NotificationCompat.Builder mBuilder =<br>                <strong>new </strong>NotificationCompat.Builder(<strong>this</strong>)<br>                        .setSmallIcon(R.mipmap.<strong><em>ic_launcher_round</em></strong>)<br>                        .setContentText(<strong>&quot;Received&quot;</strong>);<br><br>        NotificationManager mNotificationManager =<br>                (NotificationManager) getSystemService(Context.<strong><em>NOTIFICATION_SERVICE</em></strong>);<br>        mNotificationManager.notify(<strong>mRequestCode</strong>, mBuilder.build());<br>    }<br><br>    <strong>private </strong>CharSequence getMessageText(Intent intent) {<br>        Bundle remoteInput = RemoteInput.<em>getResultsFromIntent</em>(intent);<br>        <strong>if</strong>(remoteInput != <strong>null</strong>){<br>            <strong>return </strong>remoteInput.getCharSequence(<strong><em>KEY_TEXT_REPLY</em></strong>);<br>        }<br>        <strong>return null</strong>;<br>    }<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8vy32EaDbAPZUbnhD7XsrQ.jpeg" /><figcaption><strong>Inline Reply — Output</strong></figcaption></figure><p>Hope you have enjoyed this post,Feel free to comment below for doubts or chat with me in <a href="https://www.facebook.com/ram.kumar.796774"><strong>Facebook</strong></a> or drop me<strong> </strong><a href="http://ramkumartcemdu@gmail.com/"><strong>E-mail</strong></a> for replies. Share is care.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8b8ea6a1854f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Working with Android Fragments]]></title>
            <link>https://medium.com/@ramkumarVR46/working-with-android-fragments-600926ca0fdf?source=rss-7a890577a00f------2</link>
            <guid isPermaLink="false">https://medium.com/p/600926ca0fdf</guid>
            <category><![CDATA[androiddev]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[android-apps]]></category>
            <category><![CDATA[udacity]]></category>
            <dc:creator><![CDATA[Ramkumar N]]></dc:creator>
            <pubDate>Sun, 11 Jun 2017 18:17:42 GMT</pubDate>
            <atom:updated>2017-06-11T18:17:42.881Z</atom:updated>
            <content:encoded><![CDATA[<p><strong><em>Udacity - Advanced Android App Development-Fragments Android Me Application.</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6MZYexUFPJSEKaFQ7x2dvg.png" /><figcaption><strong>Android Me Application using Fragments (Tablet Preview)</strong></figcaption></figure><h3><strong>Fragments</strong></h3><p>Android Fragments is a <strong>“reusable self contained portions of a user interface” </strong>in an Android Activity used for creating dynamic and flexible user interface.Fragments has it’s own life cycle but it <strong>always be embedded</strong> with an activity so that the fragments life cycle is <strong>directly affected</strong> by the host activity’s life cycle and <strong>fragments receives it’s own input events</strong>.in android app we can use multiple fragments in a single activity to create <strong>Multi-Pane UI</strong>and also can able to use a single fragment in multiple activity’s.<strong>Fragment Manager</strong> is responsible for add/remove or replace fragments at run time in any where of an activity.when add a fragment in an activity it is lives in a <strong>ViewGroup</strong> in side the activity’s view hierarchy and fragment defines its own view layout by declaring the fragment in the activity’s layout file as a <strong>&lt;fragment&gt;</strong> element or from application code by adding it to an existing ViewGroup.</p><h3><strong><em>Why need Android Fragments ?</em></strong></h3><p><em>Android introduced fragments in </em><strong><em>Android 3.0(API level 11)</em></strong><em> for supporting </em><strong><em>dynamic</em></strong><em> and </em><strong><em>flexible UI</em></strong><em> designs on</em><strong><em> larger screens</em></strong><em>,such as </em><strong><em>tablets</em></strong><em>.Because a tablet’s screen is much larger than handset so there’s </em><strong><em>more room to combine and interchange UI components</em></strong><em>.Fragments allow such designs without the need for you to manage complex changes to the view hierarchy.By dividing the layout of an activity into fragments,you become able to modify the activity’s appearance at run time and preserve those changes in a </em><strong><em>back stack</em></strong><em> that’s managed by the activity. When designing your application to support both tablets and handsets, you can reuse your fragments in different layout configurations to optimize the user experience based on the available screen space.</em></p><p><strong>Things which we learn here,</strong><br><strong><em> </em></strong>📌 <em>How to create a fragment.<br></em>📌 <em>How to build a flexible UI.<br></em>📌 <em>How to Communicate with other fragments.</em></p><h3><strong>Creating a Fragment</strong></h3><p><strong>Add a Fragment to an Activity using XML</strong></p><p>here is an sample layout file that add a single master fragment to an activity.</p><pre>&lt;<strong>RelativeLayout<br>    xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;<br>    android:layout_height=&quot;match_parent&quot;<br>    android:layout_width=&quot;match_parent&quot;</strong>&gt;<br>    &lt;<strong>fragment<br>        android:id=&quot;@+id/master_list_fragment&quot;<br>        android:layout_width=&quot;match_parent&quot;<br>        android:layout_height=&quot;match_parent&quot;<br>        android:name=&quot;com.example.android.android_me.MasterListFragment&quot;</strong>&gt;<br>    &lt;/<strong>fragment</strong>&gt;<br>&lt;/<strong>RelativeLayout</strong>&gt;</pre><p><strong>Apply the Layout to your Activity</strong></p><p>1)setup your project to use the <strong>v4 library</strong> To create a fragment by extend <strong>Fragment class</strong>.However,you can also include the <strong>app bar</strong> in your activity by instead using the <strong>v7 appcompat library</strong>.if you’r using v7 library then your activity should instead extend <strong>AppCompatActivity</strong>,which is a subclass of <strong>FragmentActivity</strong>.</p><p><strong>Note</strong> : <strong><em>FragmentActivity is a special activity provided in the Support Library to handle fragments on system versions older than API level 11.</em></strong></p><pre><strong>import </strong>android.support.v7.app.AppCompatActivity;<br><strong>import </strong>android.os.Bundle;<br><strong>public class </strong>MainActivity <strong>extends </strong>AppCompatActivity <strong>implements </strong>MasterListFragment.OnImageClickListener {<br>    @Override<br>    <strong>protected void </strong>onCreate(Bundle savedInstanceState) {<br>        <strong>super</strong>.onCreate(savedInstanceState);<br>        setContentView(R.layout.<strong><em>activity_main</em></strong>);<br>    }<br>}</pre><p><strong>Create a Fragment Class</strong></p><p>here’s a simple fragment that specifies its own layout.</p><pre>&lt;<strong>LinearLayout<br>    xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;<br>    android:layout_width=&quot;match_parent&quot;<br>    android:layout_height=&quot;wrap_content&quot;<br>    android:orientation=&quot;vertical&quot;<br>    android:name=&quot;com.example.android.android_me.MasterListFragment&quot;</strong>&gt;<br>    &lt;<strong>GridView<br>        xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;<br>        android:id=&quot;@+id/images_grid_view&quot;<br>        android:layout_width=&quot;match_parent&quot;<br>        android:layout_height=&quot;0dp&quot;<br>        android:layout_weight=&quot;7&quot;<br>        android:adjustViewBounds=&quot;true&quot;<br>        android:columnWidth=&quot;180dp&quot;<br>        android:gravity=&quot;center&quot;<br>        android:horizontalSpacing=&quot;8dp&quot;<br>        android:numColumns=&quot;3&quot;<br>        android:padding=&quot;16dp&quot;<br>        android:stretchMode=&quot;columnWidth&quot;<br>        android:verticalSpacing=&quot;8dp&quot;</strong>&gt;<br>    &lt;/<strong>GridView</strong>&gt;<br>    &lt;<strong>Button<br>        android:id=&quot;@+id/next_Btn&quot;<br>        android:layout_width=&quot;match_parent&quot;<br>        android:layout_height=&quot;0dp&quot;<br>        android:layout_weight=&quot;1&quot;<br>        android:layout_gravity=&quot;center_horizontal&quot;<br>        android:text=&quot;Next&quot;</strong>/&gt;<br>&lt;/<strong>LinearLayout</strong>&gt;</pre><p><strong>Create a Fragment Class</strong></p><pre><strong>import </strong>android.os.Bundle;<br><strong>import </strong>android.support.v4.app.Fragment;<br><strong>import </strong>android.view.LayoutInflater;<br><strong>import </strong>android.view.View;<br><strong>import </strong>android.view.ViewGroup;<br><strong>public class </strong>MasterListFragment <strong>extends </strong>Fragment {<br>    @Override<br>    <strong>public </strong>View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {<br>        <strong>final </strong>View rootView = inflater.inflate(R.layout.<strong><em>fragment_master_list</em></strong>, container, <strong>false</strong>);<br>        <strong>return </strong>rootView;<br>    }<br>}</pre><h3><strong>Build a Flexible UI</strong></h3><p>When designing your application to support a wide range of screen sizes, you can <strong>reuse</strong> your fragments in different layout configurations to optimize the user experience based on the available screen space.</p><p><strong>Add a Fragment to an Activity at Run Time.</strong></p><p>1)when adding fragments at run time your activity layout <strong>must include a container view</strong> in which you can insert the fragment.so by include an empty <strong>FrameLayout</strong> that acts as the fragment container.</p><p>2)If your activity allows fragments to be removed and replaced,you should add initial fragments to the activity during activity’s <strong>onCreate()</strong> method.</p><pre>&lt;<strong>FrameLayout<br>    android:id=&quot;@+id/head_container&quot;<br>    android:layout_width=&quot;match_parent&quot;<br>    android:layout_height=&quot;180dp&quot;<br>    android:scaleType=&quot;centerInside&quot;</strong>&gt;</pre><p>3)To perform a <strong>transaction</strong> such as <strong>add</strong> or <strong>remove</strong> a fragment,you must use the <strong>FragmentManager</strong> to create <strong>FragmentTransaction</strong> which provides APIs to add,remove,replace and perform other fragment transactions.</p><p>4)Call <strong>getSupportFragmentmanager()</strong> to get <strong>FragmentManager</strong> using <strong>Support Library API</strong>s.</p><p>5)Call <strong>beginTransaction()</strong> method to create a <strong>FragmentTransaction</strong> and call add() to add a fragment.</p><p>6)when you’re ready to make changes while transaction,you must call <strong>commit()</strong> method.</p><pre>BodyPart BodyPartFragment = <strong>new </strong>BodyPart();<br>BodyPartFragment.setmImageIds(AndroidImageAssets.<em>getHeads</em>());<br>BodyPartFragment.setmListIndex(1);<br><br>FragmentManager fragmentManager = getSupportFragmentManager();<br>fragmentManager.beginTransaction()<br>        .add(R.id.<strong><em>head_container</em></strong>, BodyPartFragment)<br>        .commit();</pre><p><strong>Replace One Fragment with Another</strong></p><p>1)Call <strong>replace()</strong> method to replace a fragment.</p><p>2)To allow the user to navigate backward through the fragment transactions, you must call <strong>addToBackStack()</strong> before you commit the <strong>FragmentTransaction</strong>.</p><p><strong>Note:</strong> <em>When you remove or replace a fragment and add the transaction to the back stack, the fragment that is removed is stopped (not destroyed). If the user navigates back to restore the fragment, it restarts. If you do not add the transaction to the back stack, then the fragment is destroyed when removed or replaced.</em></p><pre>bodyPart.setmImageIds(AndroidImageAssets.<em>getBodies</em>());<br>bodyPart.setmListIndex(listIndex);<br>getSupportFragmentManager().beginTransaction()<br>        .replace(R.id.<strong><em>body_container</em></strong>,bodyPart)<br>        .addToBackStack(<strong>null</strong>)<br>        .commit();</pre><p>3)The <strong>addToBackStack()</strong> method takes an optional string parameter that specifies a <strong>unique name</strong> for the transaction. The name isn’t needed unless you plan to perform advanced fragment operations using the <strong>FragmentManager.BackStackEntry</strong> APIs.</p><h3>Communicating with Other Fragments</h3><p>Fragment to Fragment communication is done through the Associated Activity.Two Fragments should never communicate directly.</p><p><strong>Define an Interface</strong></p><p>1)To allow a Fragment to communicate up to its Activity, you can define an <strong>Interface</strong> in the Fragment class and implement it within the Activity. The Fragment captures the interface implementation during its <strong>onAttach()</strong> method and can then call the Interface methods in order to communicate with the Activity.</p><pre><strong>public class </strong>MasterListFragment <strong>extends </strong>Fragment {<br><br>    OnImageClickListener <strong>mCallback</strong>;<br><br>    <strong>public interface </strong>OnImageClickListener {<br>        <strong>void </strong>onImageSelected(<strong>int </strong>position);<br>    }<br><br>    @Override<br>    <strong>public void </strong>onAttach(Context context) {<br>        <strong>super</strong>.onAttach(context);<br>        <strong>try </strong>{<br>            <strong>mCallback </strong>= (OnImageClickListener) context;<br>        } <strong>catch </strong>(ClassCastException e) {<br>            <strong>throw new </strong>RuntimeException(context.toString()<br>                    + <strong>&quot; must implement OnFragmentInteractionListener&quot;</strong>);<br>        }<br>    }<br>}</pre><p>Now the fragment can change the body parts by calling <strong>onImageSelected(int position)</strong> method.</p><p><strong>Change Body Parts</strong></p><pre>@Override<br><strong>public void </strong>onImageSelected(<strong>int </strong>position) {<br>    Toast.<em>makeText</em>(<strong>this</strong>,<strong>&quot;Position Clicked = &quot;</strong>+position,Toast.<strong><em>LENGTH_SHORT</em></strong>).show();<br>    <strong>int </strong>bodyPartNumber = position/12;<br>    <strong>int </strong>listIndex = position - 12*bodyPartNumber;<br>    <strong>if</strong>(<strong>Towpane</strong>){<br>        BodyPart bodyPart = <strong>new </strong>BodyPart();<br>        <strong>switch </strong>(bodyPartNumber){<br>            <strong>case </strong>0:<br>                bodyPart.setmImageIds(AndroidImageAssets.<em>getHeads</em>());<br>                bodyPart.setmListIndex(listIndex);<br>                getSupportFragmentManager().beginTransaction()<br>                        .replace(R.id.<strong><em>head_container</em></strong>,bodyPart)<br>                        .commit();<br>                <strong>break</strong>;<br>            <strong>case </strong>1:<br>                bodyPart.setmImageIds(AndroidImageAssets.<em>getBodies</em>());<br>                bodyPart.setmListIndex(listIndex);<br>                getSupportFragmentManager().beginTransaction()<br>                        .replace(R.id.<strong><em>body_container</em></strong>,bodyPart)<br>                        .addToBackStack(<strong>null</strong>)<br>                        .commit();<br>                <strong>break</strong>;<br>            <strong>case </strong>2:<br>                bodyPart.setmImageIds(AndroidImageAssets.<em>getLegs</em>());<br>                bodyPart.setmListIndex(listIndex);<br>                getSupportFragmentManager().beginTransaction()<br>                        .replace(R.id.<strong><em>leg_container</em></strong>,bodyPart)<br>                        .commit();<br>                <strong>break</strong>;<br>            <strong>default</strong>:<strong>break</strong>;<br>        }<br>    }<strong>else</strong>{<br>        <strong>switch </strong>(bodyPartNumber) {<br>            <strong>case </strong>0:<br>                <strong>headIndex </strong>= listIndex;<br>                <strong>break</strong>;<br>            <strong>case </strong>1:<br>                <strong>bodyIndex </strong>= listIndex;<br>                <strong>break</strong>;<br>            <strong>case </strong>2:<br>                <strong>legIndex </strong>= listIndex;<br>                <strong>break</strong>;<br>            <strong>default</strong>:<br>                <strong>break</strong>;<br>        }<br>    }<br>    Bundle b = <strong>new </strong>Bundle();<br>    b.putInt(<strong>&quot;headIndex&quot;</strong>,<strong>headIndex</strong>);<br>    b.putInt(<strong>&quot;bodyIndex&quot;</strong>,<strong>bodyIndex</strong>);<br>    b.putInt(<strong>&quot;legIndex&quot;</strong>,<strong>legIndex</strong>);<br><br>    <strong>final </strong>Intent intent = <strong>new </strong>Intent(<strong>this</strong>, AndroidMeActivity.<strong>class</strong>);<br>    intent.putExtras(b);<br><br>    Button nextBtn = (Button)findViewById(R.id.<strong><em>next_Btn</em></strong>);<br>    nextBtn.setOnClickListener(<strong>new </strong>View.OnClickListener() {<br>        @Override<br>        <strong>public void </strong>onClick(View v) {<br>            startActivity(intent);<br>        }<br>    });<br><br>}</pre><p><a href="https://github.com/raamkumr-valentino/Android-Me---Fragments-#android-me-fragments"><strong><em>click here and see full application code in GitHub</em></strong></a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uH_ZbReeSseyjw_Bv5GH1Q.jpeg" /><figcaption><strong>Android Me Application Using Fragments (Mobile Preview)</strong></figcaption></figure><p>Hope you have enjoyed this post,Feel free to comment below for doubts or chat with me in <a href="https://www.facebook.com/ram.kumar.796774"><strong>Facebook</strong></a> or drop me<strong> </strong><a href="http://ramkumartcemdu@gmail.com/"><strong>E-mail</strong></a> for replies. Share is care.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=600926ca0fdf" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Android Fragments Life Cycle]]></title>
            <link>https://medium.com/@ramkumarVR46/android-fragments-life-cycle-612e85c047dd?source=rss-7a890577a00f------2</link>
            <guid isPermaLink="false">https://medium.com/p/612e85c047dd</guid>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[android-apps]]></category>
            <category><![CDATA[androiddev]]></category>
            <dc:creator><![CDATA[Ramkumar N]]></dc:creator>
            <pubDate>Mon, 05 Jun 2017 19:49:57 GMT</pubDate>
            <atom:updated>2017-06-05T19:51:58.044Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Understand Android Fragments and it’s Life Cycle</em></p><h4><strong>What is Android Fragments</strong></h4><p>Android Fragments is a <strong>“reusable self contained portions of a user interface” </strong>in an Android Activity used for creating dynamic and flexible user interface.Fragments has it’s own life cycle but it <strong>always be embedded</strong> with an activity so that the fragments life cycle is <strong>directly affected</strong> by the host activity’s life cycle and <strong>fragments receives it’s own input events</strong>.in android app we can use multiple fragments in a single activity to create <strong>Multi-Pane UI</strong> and also can able to use a single fragment in multiple activity’s.<strong>Fragment Manager</strong> is responsible for add/remove or replace fragments at run time in any where of an activity.when add a fragment in an activity it is lives in a <strong>ViewGroup</strong> in side the activity’s view hierarchy and fragment defines its own view layout by declaring the fragment in the activity’s layout file as a <strong>&lt;fragment&gt;</strong> element or from application code by adding it to an existing ViewGroup.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/560/1*V0ivrNeBar1K0VUqwzj8Eg.jpeg" /><figcaption><strong>Android Fragment</strong></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/317/1*kbK7DckgeJiBgpGFQGbcog.png" /><figcaption><strong>Android Fragment Life Cycle</strong></figcaption></figure><h4><strong>Android Fragments Life Cycle</strong></h4><p>The following are the <strong>Android Fragments Life Cycle Callbacks</strong>.Managing the life cycle of a fragment is lot like managing the life cycle of an activity.</p><p>📌 <strong>onAttach()</strong><br>This method is called first even before <strong>onCreate()</strong> callback and after the fragment has been attached to the activity.<br>if <strong>Android SDK Version(API level&lt;23)</strong> it takes<strong> Activity</strong> as a reference that will host the fragment else it takes <strong>Context</strong> as a reference.using this reference we can able to obtain system services and initialize fragment interactive events etc.</p><p>📌 <strong>onCreate()</strong><br>This method is called when <strong>creating the fragment</strong> and it takes <strong>Bundle</strong> as a reference which is used for <strong>initialize the essential components</strong> and <strong>store</strong> its value that you want to retain when the fragment is<strong> paused or stopped</strong>,then <strong>resumed</strong>.when the fragment is implemented for the first time in the activity <strong>Bundle object is null</strong>.</p><p>📌 <strong>onCreateView()</strong><br>This method is called when the fragment is <strong>added(link the appearance)</strong> to an activity for the first time.you<strong> must return a view</strong> from this method that is the root of your fragment’s layout.you can return null if the fragment does not provide a UI.</p><p>📌 <strong>onActivityCreated()</strong><br>This method is called after<strong> Activity onCreate(</strong>) callback has completed it’s execution.this method is an <strong>indication</strong> for the activity has complete its execution before we try to<strong> freely access and modify UI elements</strong> of the activity.</p><p>📌 <strong>onStart()</strong><br>This method is called once the fragment <strong>gets visible</strong> in the activity after <strong>Activity onStart() </strong>callback.</p><p>📌 <strong>onResume()</strong><br>This method is called when the <strong>user interacting with the fragments</strong> in the activity after <strong>Activity onResume()</strong> callback.</p><p><strong><em>As a fragment is no longer being used,it goes through a reverse series of callbacks.</em></strong></p><p>📌 <strong>onPause()</strong><br>This method is called when the <strong>fragment is no longer interacting with the user</strong> either because it’s activity is being <strong>paused</strong> or a fragment operation is <strong>modifying</strong> it in the activity.</p><p>📌 <strong>onStop()</strong><br>This method is called when the<strong> fragment is no longer interacting with the user</strong> either because it’s activity is being <strong>stopped</strong> or a fragment operation is <strong>modifying</strong> it in the activity.</p><p>📌 <strong>onDestroyView()</strong><br>This method is called to allow the <strong>fragment to cleanup resources</strong> associated with it’s view in the activity.</p><p>📌<strong>onDestroy()</strong><br>This method is called to do <strong>final cleanup of the fragment’s state.</strong></p><p>📌 <strong>onDetach()</strong><br>This method is called to the <strong>fragment no longer being associated with its activity.</strong></p><h4><strong>Key Notes</strong></h4><p>🔑 Usually,you should implement at least the following life cycle callbacks<br><strong><em> onCreate()<br>onCreateView()<br>onPause()</em></strong></p><p>🔑 We can save each <strong>Fragment Transaction</strong> to a <strong>Back Stack</strong> manged by the host activity and this back stack allows the user to<strong> reverse a fragment transaction</strong>.</p><p>🔑 Whenever we have a <strong>method with a same name</strong> in both the <strong>activity</strong> and <strong>fragment</strong> during the creation phase the activity’s method runs first and the fragment’s method runs next.</p><p>🔑 <strong>onSaveInstaceState()</strong><br>This callback is called where you allowed to s<strong>ave some data regarding fragment</strong> <strong>events</strong> just <strong>before the applications is paused</strong> so that when the user comes back to the application they <strong>get the saved data</strong>.here it takes <strong>Bundle reference</strong> so we can able to store data as <strong>(key,value)</strong> pairs.</p><p><strong><em>Next : Working With Android Fragments * </em></strong>🚀</p><p>Hope you have enjoyed this post,Feel free to comment below for doubts or chat with me in <a href="https://www.facebook.com/ram.kumar.796774"><strong>Facebook</strong></a> or drop me<strong> </strong><a href="http://ramkumartcemdu@gmail.com/"><strong>E-mail</strong></a> for replies. Share is care.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=612e85c047dd" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ Android O -Permission Updates]]></title>
            <link>https://medium.com/@ramkumarVR46/android-o-permission-updates-ee783882ea0b?source=rss-7a890577a00f------2</link>
            <guid isPermaLink="false">https://medium.com/p/ee783882ea0b</guid>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[androiddev]]></category>
            <category><![CDATA[android-developers]]></category>
            <category><![CDATA[android-o]]></category>
            <dc:creator><![CDATA[Ramkumar N]]></dc:creator>
            <pubDate>Fri, 02 Jun 2017 10:11:17 GMT</pubDate>
            <atom:updated>2017-06-02T10:11:17.117Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Let’s discuss about Android O Permission Updates</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rl-vvffNXIeKT-NwSJqwow.jpeg" /><figcaption><strong>Android O</strong></figcaption></figure><p><strong>Android O Permission</strong></p><p>As we discussed earlier in <a href="https://android.i-visionblog.com/about-android-permissions-3bfa9af665f"><strong>Android Permissions</strong></a>,previous versions of android <strong>(API level 24 and below)</strong> application requests permissions for access to <strong>resources</strong> and <strong>data</strong> which are not in the application’s own <strong>sandbox</strong>. the application requests for permission to the user at <strong>run time</strong> or <strong>installation time</strong>.these permissions belongs to some permission groups like <strong>CONTACTS</strong>,<strong>CAMERA</strong> etc. if the user allows that permission at the same time the rest of the permissions which belongs to the same group are also allowed for that application.for example when your application request <strong>READ_CONTACTS</strong> permission the user may allow that particular permission.but <strong>at the same time</strong> the application also grant other permissions<strong>(WRITE_CONTACTS)</strong> which are listed in the same permission group <strong>without the user knowledge</strong>.but <strong>Android O</strong> has a slight change in the Permission Behavior. let us consider the above situation, your application request <strong>READ_CONTACTS</strong> permission which belongs to <strong>CONTACTS </strong>permission group.when the user allow that permission,the application allows only that particular permission and the rest of the permissions are not allowed at that time.but <strong>at any time</strong> when the application needs other permission in the <strong>CONTACTS permission group</strong>,the required permission will be <strong>automatically allowed by the application itself</strong>.</p><p><strong>Android O introduces new Permission related to PHONE Permission Group</strong></p><p>📌 <strong>ANSWER_PHONE_CALLS</strong></p><p><strong>“android.permission.ANSWER_PHONE_CALLS”</strong></p><p>by using this permission your app can <strong>answer incoming phone calls</strong> <strong>programatically</strong> . to handle phone calls in your application you should use <strong>acceptRingingCall()</strong> method.</p><p><strong>acceptRingingCall()<em> -</em></strong>This method accepts phone call on <strong>behalf of the user</strong>.this method requires the following permissions <strong>MODIFY_PHONE_STATE</strong>(“android.permission.MODIFY_PHONE_STATE”)or <strong>ANSWER_PHONE_CALLS</strong>(“android.permission.ANSWER_PHONE_CALLS”)</p><p>📌 <strong>READ_PHONE_NUMBERS</strong></p><p><strong>“android.permission.READ_PHONE_NUMBERS”</strong></p><p>by using this permission application can allow <strong>read access to the devices phone numbers</strong>.this is the subset of the capabilities granted by <strong>READ_PHONE_STATE</strong></p><p><strong>READ_PHONE_STATE</strong></p><p>Allows read only access to phone state, including the <strong>phone number of the device</strong>, <strong>current cellular network information</strong>, the <strong>status of any ongoing calls</strong>, and a list of any <strong>PhoneAccounts registered on the device</strong>.</p><p>here both the Permissions are classified as <strong>Dangerous Permission</strong>.</p><p>Hope you have enjoyed this post,Feel free to comment below for doubts or chat with me in <a href="https://www.facebook.com/ram.kumar.796774">Facebook</a> or drop me e-mail for replies. Share is care.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ee783882ea0b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Android  Changing Menu Items at Run Time]]></title>
            <link>https://medium.com/@ramkumarVR46/android-changing-menu-items-at-run-time-48970f0cf1b7?source=rss-7a890577a00f------2</link>
            <guid isPermaLink="false">https://medium.com/p/48970f0cf1b7</guid>
            <category><![CDATA[android-developers]]></category>
            <category><![CDATA[android-development]]></category>
            <category><![CDATA[android-studio]]></category>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[Ramkumar N]]></dc:creator>
            <pubDate>Thu, 18 May 2017 16:38:16 GMT</pubDate>
            <atom:updated>2017-05-18T16:38:16.744Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>onCreateOptionsMenu() VS onPrepareOptionsMenu()</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*OZxvGuCUiHsLnu55JOQhyQ.png" /><figcaption><strong>Android OptionsMenu</strong></figcaption></figure><p><strong>What is Android Menu</strong></p><p>Basically Menu’s are the <strong>Containers </strong>which contains some of the available things in the system or application.in Android Operating System <strong>Menus</strong> are the<strong> Common User Interface Component</strong> which contains the available <strong>“things”</strong> in the application by using <strong>Android Menu Api</strong> to present user actions in your activity.here “things” which means “settings”,”search”,”delete”,”help”,”about” features of the applications.now a days the importance of user interface in the latest android versions menu’s are placed in the <strong>app bar</strong> for the common user actions and behaves good than the earlier versions<strong>(API level 11)</strong> of android traditional<strong> 6 item menu panel</strong>.in latest versions of android menu’s design and user experience might be changed but the semantic to define a set of actions and options is still based on the <strong>Android Menu Api.</strong></p><p><strong>Types of Android Menu</strong></p><p>📎 <em>Options Menu</em><br>📎 <em>Context Menu</em><br>📎 <em>Popup Menu</em></p><p><strong>What is Options Menu</strong></p><p>Options Menu are the <strong>primary collections of menu</strong> items for an activity that are available in <strong>app bar</strong> by default android places all the menu items in the <strong>action overflow</strong> which is on the right side of the app bar.</p><h3><strong>onCreateOptionsMenu(Menu menu) VS onPrepareOptionsMenu(Menu menu)</strong></h3><p><strong><em>onCreateOptionsMenu(Menu menu)</em></strong><em> — this method is </em><strong><em>called only one once</em></strong><em> in the activity life cycle for to create a </em><strong><em>menu instance</em></strong><em> for an activity so we </em><strong><em>don’t call</em></strong><em> again unless the menu is </em><strong><em>invalidated</em></strong><em> for some reason.</em></p><p><strong>Key Factors</strong></p><p>🔑 For quick access to important actions we can <strong>place few items </strong>on the app bar by using <br><strong>android:showAsAction=”ifRoom”</strong> to the corresponding <strong>&lt;item&gt;</strong> elements in the menu resource xml.</p><p>🔑 If both activity and fragment declare items for the options menu they are <strong>combined in the UI</strong>. so that the activity’s items get appears first and then the fragments item’s get appear in this situation we should <strong>re-order</strong> the menu item’s which depends on our need by using <strong>android:orderInCategory</strong> attribute in each <strong>&lt;item&gt;</strong> elements in the menu resource xml.</p><p>🔑 In latest android versions the system calls <strong>onCreateOptionsMenu(Menu menu)</strong> when <strong>starting</strong> the activity,in order to show items to the app bar.but the earlier versions of android this method calls when the <strong>user opens the menu for the first time.</strong></p><p>🔑 If application contains <strong>multiple activities</strong> it may provide the <strong>same options menu</strong> in that situation we can<strong> inherits the menu’s behavior</strong> by simply just extends the class which implements nothing except the <strong>onCreateOptionsMenu(</strong>) and <strong>onOptionsItemSelected()</strong> methods.This way, we can manage one set of code for handling menu actions and each descendant class inherits the menu behaviors. If you want to add menu items to one of the descendant activities, override <strong>onCreateOptionsMenu()</strong> in that activity. Call <strong>super.onCreateOptionsMenu(menu)</strong> so the original menu items are created and can also <strong>override</strong> the <strong>super class’s behavior</strong> for <strong>individual menu items</strong>.</p><p><strong><em>onPrepareOptionsMenu(Menu menu)</em></strong><em> — this method is used for </em><strong><em>prepare</em></strong><em> the activities </em><strong><em>standard options menu</em></strong><em> and called this method </em><strong><em>every time</em></strong><em> the menu will get open for </em><strong><em>efficiently enable/disable items or update the menu items</em></strong><em> at run time,android </em><strong><em>Fragment </em></strong><em>also provide an </em><strong><em>onPrepareOptionsMenu(Menu menu)</em></strong><em> callback.</em></p><p><strong>Key Factors</strong></p><p>🔑 When modify the menu item at run time this <strong>onPrepareOptionsMenu(Menu menu)</strong> method simply just pass the <strong>currently exist Menu Object</strong>.</p><p>🔑 If you want to update the menu item at run time you must call <strong>invalidateOptionsMenu() </strong>to request that the system call <strong>onPrepareOptionsMenu()</strong>.<br><strong>void invalidateOptionsMenu ()</strong> — Declare that the options menu has changed, so should be recreated. The <strong>onCreateOptionsMenu(Menu)</strong> method will be called the <strong>next time it needs to be displayed</strong>.</p><p><strong>Let’s Code</strong></p><p><em>simple example, we have to modify the menu item’s when moving one activity to an another activity. here i’m using 4 menu item’s but in both the activity it just needs 3 of them based on different activity behaviors so by simply enable/disable the menu item’s to achieve this.</em></p><p><strong>Defining a Menu in XML</strong></p><p>For all Menu types,Android provides<strong> standard XML format</strong> to define menu items.</p><pre><em>&lt;?</em><strong>xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;</strong><em>?&gt;<br></em>&lt;<strong>menu xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;<br>    xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;</strong>&gt;<br>    &lt;<strong>item<br>        android:id=&quot;@+id/option1&quot;<br>        android:orderInCategory=&quot;1&quot;<br>        android:title=&quot;Setting&quot;<br>        android:icon=&quot;@drawable/ic_settings_white_24dp&quot;<br>        app:showAsAction=&quot;ifRoom&quot; </strong>/&gt;<br>    &lt;<strong>item<br>        android:id=&quot;@+id/option2&quot;<br>        android:orderInCategory=&quot;2&quot;<br>        android:title=&quot;Delete&quot;<br>        android:icon=&quot;@drawable/ic_delete_white_24dp&quot;<br>        app:showAsAction=&quot;ifRoom|collapseActionView&quot; </strong>/&gt;<br>    &lt;<strong>item android:id=&quot;@+id/option4&quot;<br>        android:title=&quot;Note&quot;<br>        android:visible=&quot;false&quot;<br>        android:orderInCategory=&quot;3&quot;<br>        android:icon=&quot;@drawable/ic_note_add_white_24dp&quot;<br>        app:showAsAction=&quot;ifRoom|collapseActionView&quot;</strong>/&gt;<br>    &lt;<strong>item<br>        android:id=&quot;@+id/option3&quot;<br>        android:title=&quot;About&quot;<br>        app:showAsAction=&quot;never&quot; </strong>/&gt;<br>&lt;/<strong>menu</strong>&gt;</pre><p><strong>Creating an Options Menu</strong></p><p>You can inflate your menu resources into the Menu provided <strong>callback(onCreateOptionsMenu(Menu menu))</strong>.</p><pre>@Override<br><strong>public boolean </strong>onCreateOptionsMenu(Menu menu) {<br>    getMenuInflater().inflate(R.menu.<strong><em>menu</em></strong>,menu);<br>    <strong>return true</strong>;<br>}</pre><p><strong>Handling Click Events</strong></p><p>When the user selects the menu item from the options menu calls your activity’s <strong>onOptionsItemSelected()</strong> method this method passes the <strong>MenuItem</strong> selected so we can get this selected item by calling <strong>getItemId()</strong>, which returns the <strong>unique ID</strong> for the menu item.</p><pre>@Override<br><strong>public boolean </strong>onOptionsItemSelected(MenuItem item) {<br>    <strong>switch </strong>(item.getItemId())<br>    {<br>        <strong>case </strong>R.id.<strong><em>option1</em></strong>:<br>            Toast.<em>makeText</em>(getApplicationContext(),<strong>&quot;Settings Option Selected&quot;</strong>,Toast.<strong><em>LENGTH_SHORT</em></strong>).show();<br>            <strong>return true</strong>;<br>        <strong>case </strong>R.id.<strong><em>option2</em></strong>:<br>            Toast.<em>makeText</em>(getApplicationContext(),<strong>&quot;Delete Option Selected&quot;</strong>,Toast.<strong><em>LENGTH_SHORT</em></strong>).show();<br>            <strong>return true</strong>;<br>        <strong>case </strong>R.id.<strong><em>option3</em></strong>:<br>            Toast.<em>makeText</em>(getApplicationContext(),<strong>&quot;About Option Selected&quot;</strong>,Toast.<strong><em>LENGTH_SHORT</em></strong>).show();<br>            <strong>return true</strong>;<br>        <strong>case </strong>R.id.<strong><em>option4</em></strong>:<br>            Toast.<em>makeText</em>(getApplicationContext(),<strong>&quot;Note Option Selected&quot;</strong>,Toast.<strong><em>LENGTH_SHORT</em></strong>).show();<br>            <strong>return true</strong>;<br>        <strong>default</strong>:<br>            <strong>return super</strong>.onOptionsItemSelected(item);<br>    }<br>}</pre><p><strong>Changing Menu Items at Run Time</strong></p><p>When we changing the menu item at run time the system calls your activity’s <strong>onPrepareOptionsMenu()</strong> method.this method passes <strong>currently exist menu object</strong> for modify the menu item.</p><pre>@Override<br><strong>public boolean </strong>onPrepareOptionsMenu(Menu menu) {<br>    <strong>if</strong>(Build.VERSION.<strong><em>SDK_INT </em></strong>&gt; 11) {<br>        invalidateOptionsMenu();<br>        menu.findItem(R.id.<strong><em>option2</em></strong>).setVisible(<strong>false</strong>);<br>        menu.findItem(R.id.<strong><em>option4</em></strong>).setVisible(<strong>true</strong>);<br>    }<br>    <strong>return super</strong>.onPrepareOptionsMenu(menu);<br>}</pre><p><strong>Android 3.0 (API level 11) and higher Versions</strong>, items from the Options Menu are available in the <strong>app bar</strong> ,that’s the reason why we should check the app’s <strong>Build Version </strong>while changing menu item’s at run time.If it greater we can proceed.</p><p><strong>Output</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3J5tQKka7bT5qEHOfDwdDw.jpeg" /><figcaption><strong>Changing Menu Item @ Run Time</strong></figcaption></figure><p>Hope you have enjoyed this post,Feel free to comment below for doubts or chat with me in <a href="https://www.facebook.com/ram.kumar.796774">Facebook</a> or drop me <a href="http://ramkumartcemdu@gmail.com/">E-mail</a> for replies. Share is care.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=48970f0cf1b7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Let’s Discuss  Android Toolbar]]></title>
            <link>https://medium.com/@ramkumarVR46/lets-discuss-android-toolbar-26151b751734?source=rss-7a890577a00f------2</link>
            <guid isPermaLink="false">https://medium.com/p/26151b751734</guid>
            <category><![CDATA[material-design]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[android-app-development]]></category>
            <dc:creator><![CDATA[Ramkumar N]]></dc:creator>
            <pubDate>Wed, 10 May 2017 12:19:47 GMT</pubDate>
            <atom:updated>2017-05-10T12:19:47.237Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Setup android Toolbar to our application.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5XsrZIZJJve7a5-PyI3EzQ.jpeg" /><figcaption><strong>Android Toolbar</strong></figcaption></figure><p><strong>What is Android Toolbar</strong></p><p>Android Toolbar was introduced in <strong>Android Lollipop (API level 21)</strong> it works as an <strong>Action bar</strong> in the Android Activity and it provides the <strong>Material Design </strong>experience on devices which are running below android API level 21 or later.Toolbar is a <strong>ViewGroup</strong> so we can easily <strong>handling it’s behavior</strong> and <strong>placed anywhere</strong> in the layout screen.It can display the <strong>activity title</strong>,<strong>icons </strong>for additional actions which we want through the android <strong>options menu</strong> feature and also be used for <strong>navigation</strong> between screens in our android application.</p><p><strong>Adding Toolbar to an Activity</strong></p><p>🔑 <strong><em>Add the V7 AppCompact support library to your project.</em></strong></p><p>The support libraries provide a wide range of class for building applications. <strong>compile ‘com.android.support:appcompat-v7:25.3.1’ </strong>(for Android Nougat)</p><p>🔑 <strong><em>Make sure the activity extends AppCompatActivity</em></strong></p><p>public class MainActivity extends AppCompatActivity {<br> @Override<br> protected void onCreate(Bundle savedInstanceState) {<br> super.onCreate(savedInstanceState);<br> setContentView(R.layout.activity_main);<br> }<br> }<br><strong>AppCompatActivity</strong> — Provides <strong>Material</strong> <strong>color themes</strong>, <strong>widget tinting</strong>, and <strong>app bar</strong> support to earlier devices. Use of this class requires that you use <strong>Theme.AppCompat</strong> themes for consistent visual presentation.</p><p>🔑 <strong><em>Change Theme </em></strong>i<strong><em>n app res/style.xml</em></strong></p><p>change to appcompat’s <strong>NoActionBar</strong> theme.Using one of these themes prevents the app from using the native <strong>ActionBar</strong> class to provide the app bar. <strong>style name=”AppTheme” parent=”Theme.AppCompat.Light.NoActionBar”</strong></p><p>🔑 <strong><em>Add a Toolbar to the activity’s layout</em></strong></p><p>&lt;android.support.v7.widget.Toolbar<br> xmlns:app=”<a href="http://schemas.android.com/apk/res-auto">http://schemas.android.com/apk/res-auto</a>&quot;<br> xmlns:android=”<a href="http://schemas.android.com/apk/res/android">http://schemas.android.com/apk/res/android</a>&quot;<br> android:layout_width=”match_parent”<br> android:layout_height=”?attr/actionBarSize”<br> android:id=”@+id/toolBar”<br> android:background=”<a href="http://twitter.com/color/colorPrimary">@color/colorPrimary</a>”<br> android:elevation=”4dp”<br> android:theme=”<a href="http://twitter.com/style/ThemeOverlay">@style/ThemeOverlay</a>.AppCompat.ActionBar”<br> app:popupTheme=”<a href="http://twitter.com/style/ThemeOverlay">@style/ThemeOverlay</a>.AppCompat.Light” /&gt;</p><p>The <strong>Material Design specification</strong> recommends that app bars have an elevation of <strong>4 dp</strong>.<br>Retrieve the height of the Toolbar in XML, just use<strong> “?attr/actionBarSize”</strong> it gives <strong>(56dp)</strong> as default.</p><p>🔑 <strong><em>Reusing Toolbar</em></strong></p><p>we can use the <strong>&lt;include /&gt;</strong> tag to load the toolbar into our activity layout XML</p><p>&lt;include layout=”<a href="http://twitter.com/layout/toolbar">@layout/toolbar</a>”<br> android:layout_width=”match_parent”<br> android:layout_height=”wrap_content”/&gt;</p><p>🔑 <strong><em>Set the toolbar as the ActionBar for the Activity</em></strong></p><p>@Override<br> protected void onCreate(Bundle savedInstanceState) {<br> super.onCreate(savedInstanceState);<br> setContentView(R.layout.activity_main);<br> Toolbar toolbar = (Toolbar) findViewById(R.id.toolBar);<br> setSupportActionBar(toolbar);<br> }</p><p>call the activity’s <strong>getSupportActionBar()</strong> method.this method returns a reference to an <strong>appcompat ActionBar object</strong>.</p><p>🔑 <strong><em>Creating Action In Toolbar</em></strong></p><p>📌 <strong>create a menu resource for adding it to the toolbar.</strong></p><p>&lt;menu xmlns:android=”<a href="http://schemas.android.com/apk/res/android">http://schemas.android.com/apk/res/android</a>&quot;<br> xmlns:app=”<a href="http://schemas.android.com/apk/res-auto">http://schemas.android.com/apk/res-auto</a>&quot;&gt;<br> &lt;item android:id=”@+id/option1&quot;<br> android:orderInCategory=”1&quot;<br> android:title=”Setting”<br> android:icon=”<a href="http://twitter.com/drawable/ic_settings_white_24dp">@drawable/ic_settings_white_24dp</a>”<br> app:showAsAction=”ifRoom” /&gt;<br> &lt;item android:id=”@+id/option2&quot;<br> android:orderInCategory=”2&quot;<br> android:title=”Delete”<br> android:icon=”<a href="http://twitter.com/drawable/ic_delete_white_24dp">@drawable/ic_delete_white_24dp</a>”<br> app:showAsAction=”ifRoom|collapseActionView” /&gt;<br> &lt;item android:id=”@+id/option3&quot;<br> android:title=”About”<br> app:showAsAction=”never” &gt;<br> &lt;/menu&gt;</p><p>📌 <strong>this method is used for inflate the menu resource file to our application.</strong></p><p>@Override<br> public boolean onCreateOptionsMenu(Menu menu) {<br> getMenuInflater().inflate(R.menu.menu,menu);<br> return true;<br> }</p><p>📌 <strong>handling the actions which are trigger from the toolbar.</strong></p><p>@Override<br>public boolean onOptionsItemSelected(MenuItem item) {<br>switch (item.getItemId())<br>{<br>case R.id.option1:<br>Toast.makeText(getApplicationContext(),”Settings Option Selected”,Toast.LENGTH_SHORT).show();<br>break;<br>case R.id.option2:<br>Toast.makeText(getApplicationContext(),”Delete Option Selected”,Toast.LENGTH_SHORT).show();<br>break;<br>case R.id.option3:<br>Toast.makeText(getApplicationContext(),”About Option Selected”,Toast.LENGTH_SHORT).show();<br>break;<br>default:<br>break;<br>}<br>return true;<br>}</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*9Swx3XVHVKQ05yxN8h9yBw.jpeg" /><figcaption><strong>Android Toolbar Actions</strong></figcaption></figure><p>Hope you have enjoyed this post,Feel free to comment below for doubts or chat with me in <a href="https://www.facebook.com/ram.kumar.796774">Facebook</a> or drop me e-mail for replies. Share is care.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=26151b751734" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[About Android Permissions ]]></title>
            <link>https://medium.com/@ramkumarVR46/about-android-permissions-3bfa9af665f?source=rss-7a890577a00f------2</link>
            <guid isPermaLink="false">https://medium.com/p/3bfa9af665f</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[androiddev]]></category>
            <category><![CDATA[android-marshmallow]]></category>
            <category><![CDATA[android-app-development]]></category>
            <dc:creator><![CDATA[Ramkumar N]]></dc:creator>
            <pubDate>Sat, 29 Apr 2017 09:15:57 GMT</pubDate>
            <atom:updated>2017-04-29T09:15:57.091Z</atom:updated>
            <content:encoded><![CDATA[<blockquote><strong><em>working with android permissions,request,response..</em></strong></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*mWbq0ek0g-aUyRUFeRQvCw.jpeg" /><figcaption><strong>Android Permission at Run Time</strong></figcaption></figure><h3><strong>What is Android Permissions</strong></h3><p><strong>Android Permissions</strong> are the <strong>Token</strong> for accessing the System data or features to the apps in the android environment.for the security concern each apps request to the android system for its needed permissions like using <strong>CAMERA,CONTACT,LOCATION</strong> etc.. Android apps are operates in a <strong>Process Sandbox</strong> so the apps must <strong>explicitly request</strong> access to resources and data outside their Sandbox and they request this access by declaring permissions what they need for additional capabilities not provided by the basic Sandbox. Requesting Permissions in the Marshmallow(Android 6.0 — API level 23) devices or higher version’s <strong>at run time</strong> so the user can revoke the permission at any time and the Pre Marshmallow(Android 5.1 — API level 22) devices can requesting permissions only when the user <strong>installs the app</strong>,and the only way to revoke the permissions is by uninstalling the app.</p><p><a href="https://material.io/guidelines/patterns/permissions.html#"><strong><em>Android Permissions Design Pattern</em></strong></a></p><h3><strong>Declaring Permissions</strong></h3><p>if an app needs to use <strong>resources or data outside of its own process sandbox</strong>,the app has to request the appropriate permission. You declare that your app needs a permission by listing the permission in the <strong>App Manifest</strong>.To declare that your app needs a permission, put a <strong>&lt;uses-permission&gt;</strong> element in your app manifest, as a child of the top-level <strong>&lt;manifest&gt;</strong> element.for example an app that’s need to use <strong>CAMERA</strong> so we should add its appropriate permissions in the <strong>manifest.xml</strong></p><p><em>&lt;?xml version=”1.0&quot; encoding=”utf-8&quot;?&gt;<br> &lt;manifest xmlns:android=”</em><a href="http://schemas.android.com/apk/res/android"><em>http://schemas.android.com/apk/res/android</em></a><em>&quot; package=”com.edu.tce.androidpermissions”&gt;<br> &lt;uses-permission android:name=”android.permission.CAMERA”/&gt;<br> &lt;application&gt;<br> ….<br> &lt;activity&gt;<br> ….<br> &lt;/activity&gt;<br> &lt;/application&gt;<br> ….<br> &lt;/manifest&gt;</em></p><h3><strong>Android System Permission Types</strong></h3><p>📌 <strong><em>Normal Permissions</em></strong></p><p><strong>Normal Permissions</strong> which are <strong>no great risk to the user’s privacy</strong> or the operations of other apps for example your app request the permission to set the timezone is a normal permission.</p><p>📌 <strong><em>Dangerous Permissions</em></strong></p><p><strong>Dangerous Permissions</strong> which request the <strong>resources or a data</strong> that involves the <strong>user’s private information</strong> so it potentially <strong>affect the user’s stored data</strong> or the operations of other apps for example your app request to read user’s contact is a dangerous permission.</p><h3><strong>Permission Groups</strong></h3><p>All the dangerous android system permissions are belong to <strong>Permission Groups</strong> and following are the behaviors that are happen when you app request the dangerous permissions.</p><p>🔑 If your app <strong>currently not having any permissions</strong> in the permissions groups the system <strong>shows a dialog box</strong> to the user for approval.for example if an app request the <strong>READ_CONTACTS</strong> permission the system show a dialog box just say the app needs access to the <strong>device’s contact.</strong></p><p>🔑 If your app currently having the <strong>dangerous permission and now request another permission in the same group the system immediately grants the permission without any interaction with the user</strong>.for example if an app had previously requested and been granted the <strong>READ_CONTACTS</strong> permission, and it then requests <strong>WRITE_CONTACTS</strong>, the system immediately grants that permission.</p><p>The following are the some Dangerous Permissions and their <strong>Groups</strong></p><p><strong>CALENDAR </strong><br><em> READ_CALENDAR<br>WRITE_CALENDAR</em><br><strong> CONTACTS </strong><br> <em>READ_CONTACTS<br> WRITE_CONTACTS<br> GET_ACCOUNTS</em><br><strong> STORAGE </strong><br> <em>READ_EXTERNAL_STORAGE<br> WRITE_EXTERNAL_STORAGE</em><br><strong> PHONE </strong><br><em> READ_PHONE_STATE<br> CALL_PHONE<br> READ_CALL_LOG<br> WRITE_CALL_LOG<br> ADD_VOICEMAIL<br> USE_SIP<br> PROCESS_OUTGOING_CALLS</em></p><h3><strong>Requesting Permissions at Run Time</strong></h3><p>After <strong>Marshmallow(Android 6.0 — API level 23) devices or higher version’s </strong>users can <strong>grant the permissions while the app is running</strong>,not when they install the app.for example now your app needs CAMERA permission the following are the important factors while requesting that permission .</p><p>📌 <strong><em>Check For Permission</em></strong></p><p>If your app needs a <strong>dangerous permission</strong> you <strong>must check</strong> whether you have that permission <strong>every time you perform an operation</strong> that requires that permission <br> <br><strong>ContextCompat.checkSelfPermission()</strong> — this method returns PackageManager.PERMISSION_GRANTED if you have this permission else it returns PERMISSION_DENIED.</p><p>if(ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.CAMERA)!= PackageManager.PERMISSION_GRANTED)<br> {<br> //to do further actions..<br> }</p><p>📌 <strong><em>Explain why the app needs Permission</em></strong></p><p>If the user chose the <strong>Don’t ask again</strong> option in the <strong>permission request</strong> system dialog for a particular permission but after some time the user may want to use functionality that requires a permission but keeps turning down the permission request, that probably shows that the <strong>user doesn’t understand why the app needs the permission to provide that functionality</strong>. In a situation like that, it’s probably a good idea to show an explanation.</p><p><strong>shouldShowRequestPermissionRationale()</strong> — this method returns true if the app has requested this permission previously and the user denied the request.</p><p>if(ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.CAMERA)!= PackageManager.PERMISSION_GRANTED)<br> {<br> if(ActivityCompat.shouldShowRequestPermissionRationale(MainActivity.this,Manifest.permission.CAMERA))<br> {<br> //to do further actions..<br> }<br> }</p><p>📌 <strong><em>Request the Permission</em></strong></p><p>If your app doesn’t already have the permission it needs, the app must call one of the<strong> requestPermissions() async method</strong> to request the appropriate permissions and this method need an <strong>integer request code</strong> to identify that permission request.the system calls the app’s callback method with the results, passing the same request code that the app passed to requestPermissions().</p><p><strong>requestPermissions()</strong> — by call this method the system shows a stanard dialog box to the user.</p><p><strong>ActivityCompat.requestPermissions(MainActivity.this,new String[]{Manifest.permission.CAMERA},CAMER_PERMISSION_CODE);</strong></p><p>📌 <strong><em>Handle the Permissions request response</em></strong></p><p>When your app request permission , the system shows a <strong>dialog box</strong> to the user for response.after the user responds the system invokes your app’s <strong>onRequestPermissionsResult(</strong>) method,<strong> passing it the user response</strong>. Your app has to override that method to find out whether the permission was granted. The callback is passed the same request code you passed to <strong>requestPermissions()</strong>.</p><p><a href="http://twitter.com/Override">@Override</a><br> public void onRequestPermissionsResult(int requestCode, <a href="http://twitter.com/NonNull">@NonNull</a> String[] permissions, <a href="http://twitter.com/NonNull">@NonNull</a> int[] grantResults) {<br> super.onRequestPermissionsResult(requestCode, permissions, grantResults);<br> if(requestCode == CAMER_PERMISSION_CODE)<br> {<br> if(grantResults.length &gt; 0 &amp;&amp; grantResults[0] == PackageManager.PERMISSION_GRANTED)<br> {<br> Toast.makeText(getApplicationContext(),”CAMERA Permission Granted”,Toast.LENGTH_SHORT).show();<br> }else {<br> if(ActivityCompat.shouldShowRequestPermissionRationale(MainActivity.this,Manifest.permission.CAMERA))<br> {<br> //to do further actions..<br> }else{<br> Toast.makeText(getApplicationContext(),”Permission Request Failed”,Toast.LENGTH_SHORT).show();<br> }<br> }</p><p>The <strong>dialog box</strong> shown by the <strong>system describes the Permission Group</strong> your app needs access.it <strong>does not list the specific permission</strong>.for example if you request <strong>READ_CALENDAR</strong> permission the system dialog shows your app needs access to the device <strong>CALENDAR</strong> so the user only needs grant permission once for each permission group.if your app requests any other permission (<strong>WRITE_CALENDAR</strong>) in that group (that are listed in your app manifest), the system automatically grants them.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WXHtsnae5nmJ-wxIDbLoJQ.png" /><figcaption><strong>Android Permission System Settings</strong></figcaption></figure><p>Hope you have enjoyed this post,Feel free to comment below for doubts or chat with me in <a href="https://www.facebook.com/ram.kumar.796774">Facebook</a> or drop me e-mail for replies. Share is care.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3bfa9af665f" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>