Android Roadmap Question and Answers

Luyen Ninh
Culi Tech Viet
Published in
5 min readNov 14, 2019

Programming languages

1. Compare Java and Kotlin (Pros and Cons) ?

  • What is Java ?

// write here

  • Pros of Java ?

//write here

  • Cons of Java ?

//Write here

What is Kotlin ?

// write here

  • Pros of Kotlin ?

//write here

  • Cons of Kotlin ?

//Write here

Android Studio

1. File và cấu trúc thư mục(mục đích - các loại file trong folder): Cấu trúc folder resources ?

Folder:

  • Manifest: chứa file manifest
  • App: java: chứa code java ///more @
  • res: chứa resources
  • Gradle: chứa file gradle

File:

  • Android manifest: file đăng ký application, activity, permission,…
  • Res: drawable: image not resize, mipmap: image resize due to screen resolution, layout: contains file layout for view class, values: contains value color, string, dimen, style use for app.
  • Gradle: file register library
  • Setting.gradle: project setting
  • Proguard-rules.pro: rules for encrypt

2. Một số hotkey thường dùng trong Android Studio ?

  • CTRL-Z, CTRL-SHIFT-Z: undo
  • CTRL-X, CTRL-L: cut
  • CTRL-ALT-L: Auto format code
  • CTRL-Q: view introduce of function, parameter,..
  • CTRL-F4: Close tab present
  • CTRL-S: Save
  • ALT-F7: Find usages
  • F4: Find initialize
  • Shift-F6: Refactor, rename
  • (F11 —Agree kick — Deprecated)

3. Tips Debug ?

Cách đọc và sử dụng filter log :

  • Đọc lỗi đầu tiên throw ra, có đường dẫn chỗ lỗi (tên class + số dòng) thì bấm vô coi.
  • Đặt breakpoint function nghi là lỗi để xem nó có những param nào
  • Đặt log.d(TAG,…) để dễ theo dõi log

//@todo : sử dụng filter và regex để filter nhanh được thông tin cần sử dụng.

Android Manifest

  1. Cấu trúc file manifest ?

Cần dùng để đăng ký package name, application ID, các component như activity services receiver, permission và device compability

2. Implement backup — data ?

3. Permission ?

Why the application need define permission ?

Every Android app runs in a limited-access sandbox. If an app needs to use resources or information outside of its own sandbox, the app has to request the appropriate permission. You declare that your app needs a permission by listing the permission in the app manifest and then requesting that the user approve each permission at runtime (on Android 6.0 and higher).

How many protection level of the permission in android system ?

  • Normal Permission :

//Todo: write here

  • Signature Permission :

//Todo: write here

  • Dangeros Permission:

//Todo: write here

What is Deeplink ? implement như nào trong manifest

Thêm intent filter và action trong component đăng ký activity

Xuân Lộc Lê cụ thể, thêm example code

Intent filter là gì ?

Là phễu lọc intent, khi gặp trường hợp gọi nào match thì lấy intent có thể nhất ra trong list intent.

Sự khác biệt của Intent Implicit và Intent Explicit ?

Explicit intent, dịch thẳng ra nghĩa đen là “ý định rõ ràng”, nghe quá chuối nên dịch là “intent rõ ràng” cho đỡ chuối. Explicit intent được dùng khi ta biết rõ component nào để đến trực tiếp, cũng như không muốn người dùng có lựa chọn khác tốt hơn. Ex: Có 2 activity A và B, ta muốn đến activity B từ activity A thì khai báo 1 explicit intent.

Implicit intent, không chỉ định rõ ràng component đặc biệt nào sẽ được chuyển đến trực tiếp, nó chỉ chỉ định hành động nào sẽ được thực hiện. Nếu chỉ tìm được 1 component thì android sẽ mở ngay component đó. Nếu không thì sẽ hiện ra list component để chọn.

Vd: Intent mở 1 trang web bằng URI thông qua ACTION_VIEW, lúc này android tìm thấy vài browser và show list lên.

App Component

Activity Life Cycle

-Luồng chính: onCreate, onStart, onResume, onPause, onStop, onDestroy.
-Khi đang dùng app mà có thông báo => onPause, không xem thông báo => onResume, navigate tới app khác => onStop
-Đang ở app khác mở lại app mình => onRestart & onStart
-Mở trình task control rồi end process => onDestroy

savedInstanceState: dùng để lưu trạng thái để restore vào các view sau khi destroy. Ví dụ khi xoay ngang màn hình, các giá trị của các view tạo trong onCreate,… sẽ bị mất (do android thực hiện onDestroy và quay lại onCreate).
Ta có thể dùng Bundle để lưu các giá trị và restore trong onCreate hoặc override hàm onRestoreInstanceState.

Fragment

https://medium.com/culi-tech-viet/fragment-android-9aaf67e55a22

Broad Cast Receiver

Là chức năng lắng nghe các sự kiện, trạng thái của hệ thống phát ra thông qua Intent. Broadcast có thể chạy nền (chung với service).

Changes log broadcast receiver

- Ở android 9 (api 28), the NETWORK_STATE_CHANGED_ACTION không nhận thông tin về vị trí của người dùng hoặc dữ liệu nhận dạng cá nhân.

- Ở android 8 (api 26), không thể register broadcast trong manifest. Chỉ được register trong context.

- Ở android 7 (api 24), phải đăng ký chương trình phát sóng CONNECTIVITY_ACTION bằng cách sử dụng registerReceiver, không thể register broadcast trong manifest. Chỉ được register trong context.

Tasks — Back Stack

Task là gì ?

Task là tập hợp những acitivty mà người dùng tương tác. Các activity này được sắp xếp trong stack — gọi là back stack — theo thứ tự mở trước sau. Nghĩa là khi người dùng nhấn back button thì activity hiện tại trong backstack sẽ pop và activity trước đó sẽ được reactive.
Trường hợp app được chạy trong multi thread (hỗ trợ android 7.0 trở lên), hệ thống android sẽ chia ra 2 trình quản lý stack khác nhau, mỗi màn hình sẽ có 1 trình quản lý task

Cơ chế Stack ?

Cơ chế: “last in, first out”, stack không thể sắp xếp, chỉ có thể push hoặc pop.,

A task adds an item to the back stack. When the user presses the Back button

Khi nào Task bị kill ?

Nếu người dùng rời khỏi task trong một thời gian dài, hệ thống sẽ dọn dẹp các activity trong task ngoại trừ root activity. Khi người dùng quay trở lại task, chỉ có root activity được khôi phục

--

--