This is a sample app that communicates with a math engine service to perform some arithmetic (addition, subtraction, multiplication, and division between two operands). The math engine service is a background service and is responsible for executing the math equations entered by the user as scheduled tasks and notifying the app about the results.
- The default implementation code is written in Java and there is another implementation written in Kotlin, to run the kotlin implementation you have to edit the
AndroidManifest
file and replace Java class references with their corresponding kotlin classes. - The background service relies on the WorkManager for scheduling tasks.
- Delay duration won't be exact if the device enters Doze Mode, WorkManager will batch jobs during maintenance windows to optimize battery usage, if we want the tasks to be executed at exact time, we can use Alarm Manager API and call
setExactAndAllowWhileIdle()
but this practice is discouraged, as it is not good for battery performance. - The background service will be restarted after being destroyed by the OS or after device boot.
- The service does not handle persisting the operation results locally in a database (we could query the workManager and filter for the finished workers and get the outputData which has the results).
- App relies on Fused Location Provider API to get location information with High Accuracy and 10 seconds Frequency, that may cause significant battery drain but we could increase the Frequency and lower the accuracy to minimize the battery usage.
- The project is simply structured but in a real project we should consider using some well known architectures like (MVVM or MVP).
- The app UI is simple and represented by single
Activity
, but could be split into multipleFragment
s. - Unit & Instrumentation Tests code is written in Kotlin and tests java implementation, we could also replicate the tests to test the kotlin implementation.
LocationManagerTest
does not test location settings, so currently we have to enable it on the test device before running the tests.- The project is tested only on Android Versions 7.0, 8.0, and 11.0.
- Jetpack Compose Integration.
- Flutter Module Integration.
- Memory Leak caused by
MathEngineService$LocalBinder
.
- Battery profiling data files are located in
profiling/battery
directory, these files are generated by the Batterystats Tool and we can visualize/analyze them using Battery Historian. - The captured heap dump file is located in
profiling/memory
directory, we can import the HPROF (.hprof) file into the Memory Profiler.
There are two gradle custom tasks that could be used to clean, build, and install the app, one for the QA flavor and the other for the Prod flavor
- On Windows, run the following commands in a terminal window:
use
gradlew cleanBuildInstallQA
to install the QA version of the app. usegradlew cleanBuildInstallProd
to install the Prod version of the app. - On Linux or Mac, run the following commands in a terminal window:
use
./gradlew cleanBuildInstallQA
to install the QA version of the app. use./gradlew cleanBuildInstallProd
to install the Prod version of the app.
- The project could be implemented using some Jetpack libraries like (Data Binding, ViewModel, LiveData, etc..).
- We could use a dependency injection framework like Dagger.