XCalc for Android

Phew, I am finally publishing this one. It has been in my drafts for more than a year(!!!) now.

Table Of Contents

  1. What's XCalc?
  2. Why for Android?
  3. How did it go?

#What's XCalc?

For those of you, who doesn’t know: XCalc is a calculator app which provides a few functions that a pre-installed calculator app doesn’t.
For example, the isPrime function checks whether the given number is a prime number. And the primeFactorize function factorizes a given number into primes.

The idea of building an app like XCalc has been in back of my head for a long time. I ultimately initiated the project around January 2021.

To learn about the development of XCalc, see Building XCalc.

#Why for Android?

XCalc was first developed as a Progressive Web App — a web app that can run offline. The app can also be installed on the user's device as well. By making a few minor changes, a PWA can be published to the Google Play Store as well (learn how here).

That's really a lot to get from just developing a web app. Why did I develop a native Android app for XCalc then?

#Discoverability

XCalc is a niche app. It's target audience is already very narrow. I have put a lot of time and effort into the development XCalc. I want to maximize the number of people benefitting from it.

I thought a web app, would be the way to achieve that. Web apps run on browsers which majority of devices can run. And web apps are just a URL away. Users don't have to install anything (other than a web browser).
However, discoverability is an issue on the web.

Android and other platforms have a dedicated app store. These app stores function as a place for users to find apps. The web doesn’t have anything like that.

To overcome this issue, I published XCalc on Google Play Store after bundling it as a TWA. That lead to the next issue.

#Bad User Experience

Let's say a user installs XCalc (the bundled PWA) from Play Store. Installation succeeds. On their first visit, the app fails to load, showing the "No Internet" error page from Chrome.

The TWA required internet connectivity to load the app on first visit. There was nothing I could do to avoid this requirement.

There are two bad experiences in the mentioned example.

  • An installed app, which, in theory, can work offline, shouldn't require internet connectivity on first load.
  • When an app's requirement of internet connection isn't met, it should show a fallback page. (not Chrome).

After researching for a fair amount of time, I concluded that there are no easy ways to fix that. And I had two rational ways to resolve this issue.

  1. Pull out XCalc from Play Store and have it as a web app. hi
  2. Build XCalc as a native Android app from scratch.

The latter seemed the best one. Hence, I went with it.

#How did it go?

#Learning a new language

Native Android apps are developed using Java and/or Kotlin. I had to learn either of those to get started with native Android app development. As Kotlin is the new in the wild, I chose Kotlin. Learning Kotlin was not as easy as I initially thought; but it wasn't that hard either. The basics were very easy to grab.

#Kotlin had no "eval"

As XCalc is basically a calculator, it needs a parser and an evaluator, to evaluate the given expressions.

I have never implemented such programs before. I had no idea about where to start. And I wanted to get XCalc working as soon as I can. Developing a parser would cost me a huge amount of time. I thought to myself: "I could simply use the eval function to achieve the same". And that's what I did.

Unfortunately, Kotlin didn't have an eval-alternative. I don't think there will ever be one. I had no choices but to build my own parser.

Fortunately, I found a few write-ups on how to build a mathematical expression evaluator. Building them was very fun, to be honest. Fun, not easy. I learned a lot from building them.
Recently, I implemented a parser for XCalc Web as well. And stopped using the eval function. I should have done it earlier.