Tuesday, July 2, 2019

Updated our Motivational Quotes App to include "Night Mode" feature and to add Author Links.

I have released new version (versions 1.11) of our Motivational Quotes App  with below features.

  • Added Night Mode /Dark Mode Option.
  • Added Clickable Links to Author Names.
  • Optimized the Code to reduce file size.

A lot of people downloaded our Quotes App from Google play store. It is good to know that more than 20K people installed it in their mobile devices. But the DAU (Daily Active Users) and Active Installations are very low.
Based on the users' feedback, I thought adding Night Mode option can fix this user retention problem.

I had provided navigation buttons, shuffle button and Rate button at bottom of the screen for this App. Since there is no space available for adding any additional button, I decided to add Tool bar / Action bar menu for including Night Mode feature.

I added the Toolbar by including below piece of code in the layout xml file of the main activity.


Then changed the Apptheme as Theme.AppCompat.DayNight.NoActionBar

And, then called setSupportActionBar at the starting of the onCreate in the main activity.

//for showing Toolsbar/Action bar
Toolbar my_toolbar = findViewById(R.id.my_toolbar);

Then I created, menu.xml to include the menu items.  I added few other menu items in addtion to the Night Mode menu.

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">

android:title="Change Night Mode" />

android:title="Quotes Books" />

android:title="Quotes Video" />
android:title="Privacy" />

Added below function for creating the menu by populating the menu items.

//For showing Tool bar menu
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater menuInflater = getMenuInflater();
menuInflater.inflate(R.menu.menu, menu);
return true;

For implementing the menu action, I added below piece of code.

public boolean onOptionsItemSelected(MenuItem item) {

case R.id.menuNightMode:
if (AppCompatDelegate.getDefaultNightMode()==AppCompatDelegate.MODE_NIGHT_YES) {
else {


case R.id.menuBooks:

case R.id.menuVideo:
case R.id.menuPrivacy:

return true;

I used AppCompatDelegate for setting the Night Mode option. I came to know that the Night mode change will come into the effect only after restarting the Activity. I spent a lot of time in adding code for restarting the activity without losing the state.
Finally, I found that it can be done by just using recreate() method.

It was working properly. i-e The current page was brought back while restarting the activity. But I found a problem when using Shuffle button. It was not keeping the shuffled order after the restart. So, I included the suffled data into the savedInstanceState bundle by overriding onSaveInstanceState.

protected void onSaveInstanceState(Bundle savedInstanceState) {

savedInstanceState.putStringArray("pagedata", pageData);

And, within onCreate(), I included below piece of code the load the shuffled quotes when restarting the Activity.

//Get the data to be swiped through
if (savedInstanceState != null) { //reload the quotes to keep the same order when restarting the activity
else //load data first time only
pageData = getResources().getStringArray(R.array.quotes);
Now I hope everthing is working fine. Let me know if you find any error.

As I explained in my previous post, I added clickable links to the Authors. It will help the App Users to know more about the Author of the Quote and read more Quotes of that Author.

I had to work really hard to add the Author links to around 900 Quotes. Let me know if you find any incorrect or broken links.

And, I optimized the code to reduce the file size as explained in my previous post. I replaced the Android support libraries with equivalent AndroidX libraries

You can install/update the app from Google Play Store here

Let me know if you have find any error when using this App. And, if you like this app, Review/Rate it and refer this to your Friends.

I am planning to add the Night Mode feature to my other apps also.

No comments:

Search This Blog