Skip to content

Instantly share code, notes, and snippets.

🎯
Focusing

Guri Getsadze getsadzeg

🎯
Focusing
Block or report user

Report or block getsadzeg

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View backgroundtasks.md

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
@getsadzeg
getsadzeg / archcomponents.md
Last active May 12, 2019
Android Architecture Components
View archcomponents.md

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 / contentproviders.md
Last active May 3, 2019
Content Providers - A layer between the database and Activity
View contentproviders.md

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 / androidsqlite.md
Last active Apr 25, 2019
Using SQLite in Android
View androidsqlite.md

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 / sqlite.md
Last active May 15, 2019
SQL, SQLite: notes and commands
View sqlite.md

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 / lilfragmentnote.md
Last active Apr 19, 2019
Fragment + Activity = <3
View lilfragmentnote.md

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 / SingleTop.md
Created Apr 19, 2019
Launchmode: SingleTop
View SingleTop.md

If you configured the activity with singleTop launch mode, when you send an intent to android os to get a new instance of such activity, android os will first check the top activity in the back stack, if it is the requested activity type, it will return it, otherwise it will create a new instance of requested activity and return.

Yeah. Just sayin'.

View Preferences.md

So, let's imagine that we're making Preferences as Settings.

First, we make SettingsActivity, of course, which is the plain activity we all know of. Its XML must actually be a fragment, referring to SettingsFragment(which we'll make; extends PreferenceFragmentCompat) with android:name.

Second, we make SettingsFragment with its XML preference xml(<PreferenceScreen and nested preferences in it) in res/xml directory. And we bond the resource to a Fragment with addPreferencesFromResource method.

Then, we must not forget to add preference theme(@style/PreferenceThemeOverlay) to styles.xml, otherwise our app will crash.

@getsadzeg
getsadzeg / Lifecycle.md
Last active Mar 29, 2019
Understanding Android Lifecycle
View Lifecycle.md
  • onCreate -> Builds UI. Activity is created.

  • onStart -> Activity is visible.

  • onResume -> Becomes active foreground app.

In reverse:

  • onPause -> Activity has lost focus(for example, if it's partially obscured: a dialog pops up or whatever).
@getsadzeg
getsadzeg / Adapter.md
Last active Sep 12, 2018
What does Adapter do? Understanding RecyclerView
View Adapter.md

Adapter class is a helper to RecyclerView. It has three responsibilities: To return how many items should be in RecyclerView, inflate item views from XML and return new ViewHolder instance(object). and populate them with appropriate data(Basically, everything is in this order). So, it has (constructor and) three methods:

Constructor:

public MyAdapter(int numberOfItems, ListItemClickListener onClickListener)

where ListItemClickListener is an interface, which has one void methoid defined, onListItemClick.

You can’t perform that action at this time.