Skip to content

Instantly share code, notes, and snippets.

View getsadzeg's full-sized avatar

Guri Getsadze getsadzeg

  • AzRy
  • Tbilisi, GE
View GitHub Profile
@getsadzeg
getsadzeg / lilfragmentnote.md
Last active April 19, 2019 18:46
Fragment + Activity = <3

Basic outline of Resources/Activity/Fragment connection:

First, we make SettingsActivity. Then, we create SettingsFragment, in which we write addPreferencesFromResource(R.xml.pref_settings); to connect it with a resource we created in xml resource directory.

Finally, we make root layout of activity_settings.xml a fragment, specifically SettingsFragment, with android:name="com.example.android.myapp.SettingsFragment"

Important note: Must not forget adding a style in styles.xml. Otherwise, app will crash.

@getsadzeg
getsadzeg / sqlite.md
Last active May 15, 2019 09:52
SQL, SQLite: notes and commands

So, I dived into SQLite.

Showing tables: .tables

Showing a command which was used to create a table: .schema <table_name>

Showing an actual structure/info about table: PRAGMA TABLE_INFO(<table_name>); - note that this is a SQL command.

The most human-readable mode of output, I think, is done by this:

@getsadzeg
getsadzeg / androidsqlite.md
Last active April 25, 2019 12:45
Using SQLite in Android

First, we define our schema, which means that we have name of the table(s), columns and their data types organized; on paper.

Then, in the code, we make Contract class, say BlankContract and make entry (nested, static) classes in them, say SomeEntry(which is, well, a table)

import android.provider.BaseColumns; //BaseColumns interface provides _id and _count

public final class BlankContract {

    public static final class SomeEntry implements BaseColumns {
@getsadzeg
getsadzeg / contentproviders.md
Last active May 3, 2019 12:56
Content Providers - A layer between the database and Activity

Yes. Another middleman!

UI code-> (Content Resolver) -> Content Provider -> Database

Content Providers are (seemingly) good abstraction layer between data source and UI. Some advantages of this include data validation.

They enable you to decouple your application layers from the underlying data layers, making your application data-source agnostic by abstracting the underlying data source.

Content URIs

@getsadzeg
getsadzeg / archcomponents.md
Last active May 12, 2019 16:56
Android Architecture Components

Android architecture components include:

  • Lifecycle-aware components

  • LiveData is used to "build data objects that notify views when the underlying database changes".

  • ViewModel - surviving configuration changes, such as rotation. Managing UI data in a lifecycle-aware way.

  • Room - SQLite object mapping library. So it converts SQLite table data to Java objects easily. plus, "Room provides compile time checks of SQLite statements and can return RxJava, Flowable and LiveData observables."

@getsadzeg
getsadzeg / backgroundtasks.md
Last active May 12, 2019 17:47
Background Tasks

Services

A Service is an application component that can perform long-running operations in the background, and it doesn't provide a user interface.

A Service:

  • is decoupled from the user interface
  • exists even when there is no user interface