Skip to content

Instantly share code, notes, and snippets.

View OrenBochman's full-sized avatar
🏠
Working from home

Oren Bochman OrenBochman

🏠
Working from home
  • WMF
  • 15:36 (UTC +03:00)
View GitHub Profile
@OrenBochman
OrenBochman / !!readme.md
Last active September 14, 2018 19:03
All about Android Notifications

Notifications

  • depend on: implementation "com.android.support:support-compat:27.1.1"
@OrenBochman
OrenBochman / !!readme.md
Last active September 12, 2018 04:18
Migrate AsyncTask to AsyncTaskLoader in Android

AsyncTaskLoader in Android

an AsyncTaskLoader based on a Loader

When to use this threading primitive ?

  • They encapsulate the process of data loading.
  • They survive configuration changes, preventing unnecessarily reloading data.

HowTo access the data once loaded

@OrenBochman
OrenBochman / !!readme.md
Created September 10, 2018 21:12
ThreadPoolExecutor in Android

ThreadPoolExecutor

ThreadPoolExecutor executes parallelized tasks across multiple different threads of a thread pool. To execute work concurrently and retain control over how the work is executed, this is the tool for the job.

Using ThreadPoolExecutor

  1. constructing a new instance
  2. confgure the many arguments of the thread pool
  3. if initializing ThreadPoolExecutor in a service, ensure to create it within onStartCommand() not onCreate()
@OrenBochman
OrenBochman / !!readme.md
Last active September 10, 2018 20:20
HandlerThread in Android

HandlerThread in Android

The HandlerThread is a convenience class that initiates a Looper within a Thread to process Runnable or Message objects. The Handler is used to handle the insertion of the Runnable or Message objects into the looper's queue: The Handler class supports several other ways to schedule a Message to be processed at a future time:

Queueing tasks

  • sendMessage - Pushes a message onto the end of the message queue.
  • sendMessageDelayed - Pushes a message onto the end of the message queue.
@OrenBochman
OrenBochman / !!readme.md
Last active September 10, 2018 14:44
Treads Android

Threads - in Android

UI and Worker thread access

Android does not allow to access the UI from a worker tread.

This shows how to access the UI thread from a Worker thread. The following are some methods to access the UI.thread:

  • Activity.runOnUiThread(Runnable)
@OrenBochman
OrenBochman / !!readme.md
Last active September 10, 2018 08:45
AsyncTask how-to in Android

AsyncTask

When to use this threading primitive?

  1. for short (say up to 3 seconds) background tasks that would otherwise block the UI thread
  2. thread abstraction
  3. easy implimentation
  4. easy ui communication

Caveats:

  1. not lifecycle aware
@OrenBochman
OrenBochman / !!readme.md
Last active September 10, 2018 16:43
Handler - schedule periodic tasks in Android

Handler - Stub

Use a Handler to run code on a given thread after a delay or repeat tasks periodically on a thread.

  1. constructing a Handler and then
  2. "posting" Runnable code to the event message queue on the thread to be processed

Handler can communicate with UI-thread

handler.post(); handler.postAtFrontOfQueue();

@OrenBochman
OrenBochman / !!AdaptiveFragmentUI.md
Last active September 9, 2018 15:04
Android Master Detail

Advanced Fragment Example - Master/Detail with a Strategy Factory

Implementing Master/Detail with:

  • adaptive master_detail with a handset breakpoint
  • a controller factory.
  • Interface based contract between fragment/activity/controller whie keeping them decoupled

    • main activity with implements the intererface for
@OrenBochman
OrenBochman / !!adding_swipe_to_dismiss.md
Last active September 9, 2018 15:22
Recycler - adding swipe to dismiss/accept

RecyclerView - Swipe to dismiss/accept