Android

Android study path

Posted by Shi

Activity

Service

Components meant for running background tasks that do not need a visual component.

Start a service

  1. Start directly

startService() from content passing an intent as param

Lifecycle

onCreate()

onStartCommand()

Service Running

stopSelf()

onDestory()

IntentService

  1. Schedule

JobScheduler

  1. Bind

bindService()

Can cummunicate with activity back and forth

i.e. Play music and update the view to show where you are

Broadcast Receiver

Content Provider

Share data between apps

Lifecycle

Active | | onResume/onPause (i.e. Show ask for permission dialog) | Visible | | onStart/onStop (i.e. Switch app) | Background | | onDestroy | Dead

Background Task

AsyncTaskLoader

AsyncTaskLoader is tied to the activity lifecycle, is used to communicate with activity.

We use it to prevent zombie threads that caused by routate screen or switch apps. (We launch the thread in onstart() method, so when we recall onStart(), a new thread will be create.

  1. Create a loader ID
  2. Fill-in loader callbacks
  3. Init loader with LoaderManager

Ref:

Udacity Code

Udacity Video

Analytics tools

Woopra

Debug

Can not install app

 cd ~/Library/Android/sdk/platform-tools
 
./adb devices
./adb uninstall <app package name>

Log

Log.d() DEBUG, Log.i() INFO, Log.w() WARN, Log.e() ERROR private String LOG_TAG = BookingListFragment.class.getSimpleName(); Log.v(TAG, “index=” + i);

Checklist to anderstand a project

Internet request

Persistance

Multi Activity/Fragemnt

Permission handler for Android 6

Notification handler

Multi controller

Min SDK

Native SharedPreferences is used?

Model structure

Communication between Fragments

Internationalization

Async call is used?

Live Template

for - for loop

for ($INDEX$) {
    $END$
}

foreach - Create a for each loop

for ($INDEX$:$COPY_INDEX$) {
    $END$
}

fvi - findViewById with cast

($cast$) view.findViewById(R.id.$resId$);
$END$

Android studio

Shortcut

Autocomplete Alt+Enter

Android Studio HotKey

To go back and forth through the Last Edit Point ( Ctrl+Alt+Left or Ctrl+Alt+Right)

Ctrl+P 显示选中方法的参数

Return to the last edit point (Command+Shift+Delete)

Rename (Shift+F6)

Recently opened files (Ctrl+e); Recently edited files (Ctrl+Shift+e)

Surround with try/if ( Alt+Command+T)(Ctrl+Alt+T)

GetterSetter Constractor (Ctrl+Enter)

Copy one line (Command+C at the beginning of the line)

Focus to the editor (Esc)

Expect type (Ctrl+Shift+Space)

Refactor Ctrl+Alt+V

Show docs for selected API Ctrl+Q (Win) F1 (Mac)

Use Ctrl+Shift+F7 (Edit Find Highlight Usages in File) to quickly highlight usages of some variable in the current file.

Use F3 and Shift+F3 keys to navigate through highlighted usages.

Press Escape to remove highlighting.

Press Alt+Q (View Context Info) to see the declaration of the current method without the need to scroll to it.
Ctrl+E (View Recent Files) brings a popup list of the recently visited files. Choose the desired file and press Enter to open it.

Use Ctrl+Alt+Up/Ctrl+Alt+Down shortcuts to jump between compiler error messages or search operation results.

Use Ctrl+J to complete any valid Live Template abbreviation if you don’t remember it. For example, type it and press Ctrl+J to see what happens.

Ctrl+Shift+N Search by file name

Double pressing the Shift key. Search globle

Ctrl+Shift+E Recently edited file

rouiT runOnUiThread

fbc ($cast$) findViewById(R.id.$resId$);

Android/rgS

Ctrl+J Insert a live template.

Collapse all: Ctrl+Shift+NumPad +

Expand all: Ctrl+Shift+NumPad -

Format code: Ctrl+Alt+L

Show project: Alt+1

Show logcat: Alt+6

Generate Alt+ Insert

To quickly evaluate the value of any expression while debugging the program, hold Alt and click this expression to see its value and calculate it, call a method, etc.

Create strings: On any string Alt+Enter

Ctrl+B on class name, go to that class

(Ctrl+Space) within HTML, CSS and other files, for completing image file names.

quickly view the image referenced at caret by using the Quick Definition (Ctrl+Shift+I).

Extract parameter(make the variable in the function to be pass as parameter) Windows/Linux: Ctrl+Alt+P

Show parameters for selected method Ctrl+P

Delete line Ctrl+Y (Win) Cmd+Backspace (Mac)

Paste from history Ctrl+Shift+V

Select one word Ctrl+Shift+Left/Right; One Line: Shift+Up/Down; One Section MAC Alt+up/down WIN?LINUX Ctrl+w / Ctrl+Shift+w;

Close a current tab Cmd+w(Windows / Linux: trl+Shift+a)

Open a class Cmd+o (Windows/Linux Ctrl+n)

Move between tabs Cmd+Shift+[ ] (Windows / Linux : Alt+← →) Close a current tab Cmd+w (Windows / Linux: Ctrl+Shift+a)

Format your code Cmd+option+l (Windows / Linux : Ctrl+Alt+l)

Show Intention Actions (Show quick fix); Alt+ENTER

Build and run control+r (Windows/Linux shif: F10)