Skip to content

Instantly share code, notes, and snippets.

View Mercandj's full-sized avatar
😀
Working on Android Apps

Jonathan Mercandalli Mercandj

😀
Working on Android Apps
View GitHub Profile

Swift 4 - List of listeners

Note: I'm an Android developer that trying to create iOS apps. So I may be missing some notions. Sorry for that.

Problem

In many managers and buisness classes, we could want to have a listeners mechanism (sometimes called events) with some notions to register (or addListener), unregister (or removeListener) and notify (or broadcast) all the listeners registered.

So the problem is the following: "How to create an implementation of the following contract bellow".

@Mercandj
Mercandj / android-view-pager.md
Last active April 19, 2019 09:02
Android ViewPager: listen displayed step

ViewPager

Track ViewPager position


drawing drawing

#!/usr/bin/env bash
ANDROID_SERIAL_NUMBER=$1
if [[ "$ANDROID_SERIAL_NUMBER" = "" ]] ; then
printf "Missing android serial number after the command.
To get it -> adb devices: \n"
adb devices
exit 0
fi
@Mercandj
Mercandj / open-url.sh
Last active September 20, 2019 08:35
#!/usr/bin/env bash
DEVICE=$1
URL=$2
if [[ "$DEVICE" = "" ]] ; then
printf "Missing device arg\n"
printf "First arg should be the device\n"
printf "Second arg should be the url\n"
adb devices
#!/bin/bash
# Parameters: nothing
# Required `$ANDROID_NDK` in your path. For example /Users/jonathan/Library/Android/sdk/ndk-bundle
# Script to generate pre-build opus files
BASE_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
if [ -z "$ANDROID_NDK" ]; then
echo "Please set ANDROID_NDK to the Android NDK folder"

Android: Application initialization

On Android, there is a common issue that developers must solve: Deal with heavy load at application start.

1. Application.onCreate()

The easier solution is to put the initialization on the Application

class MainApplication: Application() {

Immutable lists

Introduction

Immutable lists can be misleading. Here I will use Kotlin. This snippet is viable on Java, C#, Swift... too.

I'm assuming you understand why immutable objects are "more robust" to manipulate data.

Here a "book" with "pages".

Android: Activity restoration

When you user click Home on any of your activity, the system will save the state of the activity stack and the state of your top-activity.

Then, when your user go back to your application, this activity and the activities stack will be restored on a new JVM.

How to test it?

  • Open your app
  • Go to the activity you want to test
@Mercandj
Mercandj / android_upload_aab.md
Last active August 10, 2020 18:41
Android: Upload AppBundle on the PlayStore via CLI

Android: Upload AppBundle on PlayStore

Goal:

Upload AppBundle on the PlayStore via the termial. Based on the Google API Publisher v3.

Process:

  • Be sure to have Java installed
  • Be sure to have your AppBundle file .aab
@Mercandj
Mercandj / android_livedata.md
Last active August 30, 2020 15:57
LiveData: Pros, Cons, Conclusion.

Android: LiveData

Pros, Cons, Conclusion. TLDR; More Cons than Pros.

class Timer {

   private val timeLeftMillis = MutableLiveData(5_000L)
   
 fun getTimeLeftMillis(): LiveData {