Skip to content

Android development

Posted on:September 23, 2022 at 03:22 PM

adb over wifi

$adb -s devname tcpip 5555
$adb connect 100.71.253.137:5555

// This will give ip address of the device
$adb shell netcfg | grep 'wlan0'

Android Studio keyboard shortcuts

Package name in Android Studio

Android project structure

Android project structure

AndroidManifest.xml file

What is an activity

Which activity is the first activity to launch

Launcher activity

What is View and ViewGroup

Naming convention for resource ids

Creating an activity in Android studio

Definitions

Layout inflation process

What is Context in Android

Application Context

Activity context

Activity Lifecycle

Activity Lifecycle

getContext() in ContentProvider

When to use which Context?

Annotations in Android/Java

Dependency Injection

Disadvantages of not using DI

DI history

Inversion of control

Dagger architecture

Recycler View

Android application and process

Theading

AppCompatActivity

The namespace for the Android Jetpack libraries is androidx. Android Jetpack is a collection of libraries, developed by Google, that offers backward-compatible classes and helpful functions for supporting older versions of Android. Jetpack replaces and expands on the set of libraries formerly known as the Android Support Library. Classes imported from the androidx package refer to the Jetpack libraries. Dependencies to Jetpack in your build.gradle file also start with androidx.

Android apps entry point is not a main funtion but a main activity as mentioned in manifest file.

Android uses info in manifest file to launch an app.

Constraint layout

Parent of the main activity is root view, which is the entire screen.

Strings in your app should be located in resources folder.

findViewById() : Find the view(element) by id you assigned.
You should minimize the use of findViewById() as it is an expensive operation.

By default there is one module(App) in your Android project. In large project there are many modules with their own gradle files.

Generally compileSdkVersion and targetSdkVersion are kept to the most recent version of Android.

applicationId is the unique identifier which is used by both google play and Android to identify your app. Two apps on same device cannot have identical application id. Also there cannot be duplicate app id on playstore. App id matches the package of your app.

Resources are drawn using vector files for android apk21 and above, for 20 and below the png file generated by SDK is used.

After making any changes in the gradle file, you should click “sync now” to propogate the changes to the whole project.

app namespace is used for attributes that come from your custom code/libraries.

All the visual elements that make up a screen are views, and they are all children of View class.

All views have width height and background and they all can be made interactive. eg. TextView, ImageView, EditText, CheckBoxes, Sliders, Menus, ColorPickers, Button etc.

Every view has a location expressed as pair of left and top coordinates, and dimension expressed as width and height all units are in dp.

Views are organized into view groups. Having a deep view heirarchy slows down the app. Constrainedlayout is used to build app with small number of views with complex layout to avoid deep view heirarchy.

ScrollView can contain only one view as a child, it could be either a groupview(eg LinearView) or an individual view , for eg. TextView.

Data binding: Optimize the access to views by creating a class at compile time from layout and accessing its properties/methods. You need to wrap the root class (view group) in layout tag.

Binding dataclass to view

Introduction to navigation

Activity states

What is Configuration change

What is ViewModel

Implementing ViewModel

ViewModel Class

How to access ViewModwel instance

Memory leaks

What is isFinishing property of an activity

Activity/process killed by Android

On Saved Instance State

ViewModel vs Saved Instance State (Important)

Debugging

Creating a new activity

Starting an activity

What is an intent

// Creating an intent
val intent = Intent(currentActivity, activityToOpen)
startActivity(intent)

Passing data using intent

// Send intent with data from source activity
val intent = Intent(this, VideoPlayerActivity::class.java)
// VIDEO_ID is the key to identify as we can
// send many key values inside it.
intent.putExtra("VIDEO_ID", videoId)
startActivity(intent)

// Receive data and intent at receiving activity
// -1 is the default, when no data is passed with
// "VIDEO_ID" key
val videoId = intent.getIntExtra("VIDEO_ID", -1)

Explicit vs Implicit Intents

Intent filters

WorkManager

Work Manager use cases

contraint layout

virtual helper objects

Use of notification channels

Freeform windows in Android

What is multi-window

Three type of multi-window

Freeform application support on Android 10

Enabling and using Freeform Support in Android 10

Steps

Developing Freeform Android app

Specifying freeform activity attributes

<activity android:name=".MainActivity ">
 <layout android:defaultHeight="350dp"
 android:defaultWidth="450dp"
 android:gravity="start|end"
 android:minimalHeight="400dp"
 android:minimalWidth="290dp" />
</activity>

Detecting Multi-Window Mode in an Activity

if (this.isInMultiWindowMode()) {
 // Activity is running in Multi-Window mode
} else {
 // Activity is not in Multi-Window mode
}

Receiving Multi-Window Notifications

override fun onMultiWindowModeChanged(isInMultiWindowMode: Boolean,
 newConfig: Configuration?) {
 super.onMultiWindowModeChanged(isInMultiWindowMode, newConfig)

 if (isInMultiWindowMode) {
 // Activity has entered multi-window mode
 } else {
 // Activity has exited multi-window mode
 }
}

Identifying topmost resumed activity in Multi-window mode

override fun onTopResumedActivityChanged(isTopResumedActivity: Boolean) {
 super.onTopResumedActivityChanged(isTopResumedActivity)
 if (isTopResumedActivity) {
 // Activity is now topmost resumed activity
 } else {
 // Activity is no longer topmost resumed activity
 }
}

Launching and configuring Size and Position of an activity in Multi-window/Freeform mode

val i = Intent(this, SecondActivity::class.java)
i.addFlags(Intent.FLAG_ACTIVITY_LAUNCH_ADJACENT or
Intent.FLAG_ACTIVITY_MULTIPLE_TASK or
Intent.FLAG_ACTIVITY_NEW_TASK)
val rect = Rect(0, 0, 100, 100)
val options = ActivityOptions.makeBasic()
val bounds = options.setLaunchBounds(rect)
startActivity(i, bounds.toBundle())