brunch

You can make anything
by writing

C.S.Lewis

by 이승현 May 26. 2016

안드로이드 면접 질문 #02

Android interview questions

Quora


Android interview questions for 2-5 yrs experienced


https://androidquestions.quora.com/Android-interview-questions-for-2-5-yrs-experienced




Question #01

Activity life cycle - Can I save all my database updates in onStop()?

(onStop()에서 db 업데이트들을 모두 저장할 수 있나요?)

                              

   

Answer

No, because onStop() may not be called in some situations.

In case of low memory or configuration changes, there is a chance that android may force-kill your application before reaching onStop(). onPause() is the only function that will be called with out fail before killing the application. so save all persistent data like DB tables in onPause() only.

Note : We can't save all database tables in onSaveInstanceState, because that function will not be called if user presses back button.


(아니요, 몇몇 경우엔 onStop()이 호출되지 않습니다.)

(메모리 부족이나 configuration changes(화면 회전 등)인 경우, onStop()에 도달하기 전에 android가 강제로 어플리케이션을 종료할 수 있습니다. onPause()는 프로그램을 종료되기 전에 반드시 호출되는 유일한 메소드입니다. 따라서 DB 테이블 같은 모든 영구적인 데이터들은 onPause()에서 저장해야 합니다.)

(Note : 사용자가 back 버튼을 누를 경우, onSaveInstanceState가 호출되지 않기 때문에 모든 DB 테이블을 onSaveInstanceState에서 저장할 수 없습니다.)


Question #02

What is the difference between this and getApplicationContext?

(this와 getApplicationContext 차이점은?)

                              

   

Answer

this pointer always points to current class object, app context will point to entire process. there is only one app context. if you want to use some control whose life time is through out your application life time then go for app context, else use this pointer (activity context).


(this는 항상 현재 클래스 객체를 가리키고, app context는 전체 프로세스를 가리킬 것이다. 오직 하나의 app context만이 존재하므로, 만약 application life time 동안 컨트롤 하려면 app context를 쓰고 아니면 this를 이용해라.)


Question #03

What is the UI response time limit in android?

(UI 반응 제한 시간은?)

                              

   

Answer

If user touches your activity, and if your program doesn't respond to user events with in 5 seconds, android will not tolerate it and it force closes your application. this error is called as ANR (Application Not Responding).


(유저가 activity를 터치함에도 불구하고 프로그램이 5초 동안 반응이 없다면 안드로이드는 이를 용납하지 않고 강제로 어플리케이션을 종료할 것이다. 이 에러를 ANR이라 부른다.)


* 터치를 통한 사용자 입력이 5초 내에 처리되지 않았을 때

* 브로드캐스트가 10초 내에 처리되지 않았을 때

--> 처리 시간이 오래 걸리면 작업은 메인 스레드가 아닌 별도의 스레드로 처리한다.


Question #04

What is ANR?

(ANR?)

                              

   

Answer

ANR - will occur if we are doing any other heavy functionality along with UI in single Main Thread.If two heavy functionalities happen in single thread, it will delay response to user actions, which may irritate user, and hence stop your process. Solution - Run only UI components in Main Thread.


(ANR은 하나의 메인 스레드를 통해 heavy 한 작업을 수행하는 경우 발생한다. 만약 두 개의 heavy 한 작업들을 하나의 스레드에서 수행하면, action에 대한 반응이 늦춰짐에 따라 유저들을 자극하고, 결국 프로세스를 멈추게 한다.

해결책 - 메인 스레드에서는 오직 UI components만 실행한다.)


Question #05

What is Bundle? How it is different from parcel?

(Bundleparcel와 차이점은?)

                              

   

Answer

Bundle is a data holder, which holds data to be passed between activities. In case of forceful closing of an activity, android will save all its UI states and transient states so that they can be used to restore the activity's states later. This saved states will be passed via Bundle in onCreate() function to restore its states once android recreates a killed activity. EG: this will happen in case of low memory or configuration changes like rotating the phone. 


(Bundle은 activity 간 주고받는 데이터를 보유한 데이터 holder이다. activity 강제 종료 시, 나중에 activity의 상태를 복원하기 위해 UI 상태나 일시적인 상태들을 모두 저장한다. 이 저장된 상태들은 Bundle을 통해 onCreate() 함수에 전달되어 종료된 activity를 다시 복원한다.(메모리 부족이나 폰 회전 같은 configuration 시 일어난다.))


onSaveInstanceState(): This function will be called before “onpause” or after “onpause”.

(이 함수는 onPause 이전 또는 이후에 호출된다. )


onRestoreInstanceState(): This function will be called after “onStart”.

(이 함수는 onStart 이후에 호출된다.)


Parcel is not a general-purpose serialization mechanism. This class is designed as a high-performance IPC transport. used heavily in IBinders. for normal serialization concepts, use Serializables. since serializables are heavy and takes time, we use Parcels for IPC in embedded devices.

(Parcel는 범용 직렬화 메커니즘이 아니다. 이 클래스는 고성능 IPC 전송으로 설계되었고 IBinder에 많이 사용된다. 보통의 직렬화 시, Serializables를 이용하고 직렬화가 무겁거나 오랜 시간이 걸리면 임베디드 디바이스에서의 IPC 통신을 위해 Parcel을 이용한다.)


* Serializable : Java에서 제공하는 직렬화 마커 인터페이스 (추상 메소드가 없는 인터페이스)

* Parcel : Android에서 제공하는 직렬화 인터페이스, IPC를 통해 통신하기 때문에 Serializable 보다 성능이 좋지만 구현이 Serializable에 비해 복잡하다.


Question #06

What is a fragment? How it differs from activity?

(fragmentactivity와 차이점은?)

                              

   

Answer

Fragment is a part of an activity, which contributes its own UI to that activity. Fragment can be thought like a sub activity. 

(Fragment는 activity에 종속되어 있다.)


Fragments are used to efficiently use the space in wider screen devices.

(Fragment는 더 넓은 스크린 장치 내의 공간을 효율적으로 이용하기 위해 사용된다.)


An activity may contain 0 or multiple number of fragments based on the screen size. A fragment can be reused in multiple activities, so it acts like a reusable component in activities.

(하나의 activity는 스크린 사이즈에 따라 0개 또는 여러 개의 fragment들을 포함하고 있다. fragment는 여러 개의 activity에서 재사용할 수 있기 때문에 재사용 가능한 component처럼 동작할 수 있다.)


A fragment can't exist independently. It should be always part of an activity. Where as activity can exist with out any fragment in it.

(Fragment는 독립적으로 존재할 수 없다. 반드시 activity의 한 부분으로 있어야 한다. 그러나 activity는 fragment 없이 독립적으로 존재할 수 있다.)


Question #07

What is the difference between dynamic receiver and static receiver? when will you use dynamic broadcast receivers?

(dynamic receiver와 static receiver 차이점은? 언제 dynamic broadcast receiver를 사용?)

                              

   

Answer

1. Static way of creating broadcast receiver: Generally we create broadcast receivers in manifest file with a receiver tag. This is static way.

(manifest 파일에서 receiver tag를 이용하여 만든다.)


2. Dynamic receiver: The receiver created directly using android code with out any tag in the manifest file.

(manifest 파일의 어떠한 tag 없이 android code에 바로 작성하여 만든다.)


Properties of dynamic receivers:
1. They will get executed only if the application which has registered it, is in the memory and running currently.

(등록한 어플리케이션이 메모리에 존재하고 현재 실행 중인 경우에만 동작하기 원할 때.)


2. It will not get executed if the application is not currently running.

(현재 실행 중이지 않다면 동작하지 않길 바랄 때.)


3. We will not create it by using manifest file, rather by using android code.

(manifest file을 쓰지 않고 android code를 통해 만들 때.)


Question #08

What is intent, pending intent, and sticky intent?

(intentpending intent? sticky intent?)

                              

   

Answer

1. intent - is a message passing mechanism between components of android, except for Content Provider.

(Content Provider를 제외한 android component 간 메세지를 주고받는 메커니즘이다.)


2. Sticky Intent - Sticks with android, for future broad cast listeners. For example if BATTERY_LOW event occurs then that intent will be stick with android so that if any future user requested for BATTER_LOW, it will be fired.

(이 개념은 처음 듣네요. 아래 링크 참조해 보세요.)

http://newbiehc.blogspot.kr/2011/03/sticky-intent-sticky-broadcast-intent.html


3. Pending Intent - If you want some one to perform any Intent operation at future point of time on behalf of you, then we will use pending Intent. Eg: Booking a ticket at late night when your application is not running. In this scenario we will create a pending intent to start a service which can book tickets at late night and hand it over to Alarm Manager to fire it at that time.

(이 개념도 처음 듣네요. 아래 링크 참조해 보세요.)

http://arabiannight.tistory.com/entry/%EC%95%88%EB%93%9C%EB%A1%9C%EC%9D%B4%EB%93%9C-Intent-%EA%B7%B8%EB%A6%AC%EA%B3%A0-PendingIntent-%EC%99%80-Intent-Sender


Question #09

What is the difference between thread and a service?

(thread와 service 차이점은?)

                              

   

Answer

- Service : is a component of android which performs long running operation in the background, mostly with out having UI. 

(Service는 UI 없이 background에서 오랫동안 작업을 수행하기 위한 android component 중 하나이다.)


- Thread : is a O.S level feature that allow you to do some operation in the background.

(background에서 몇몇 작업을 수행하기 위한 O.S 레벨에서의 기능이다.)


Though conceptually both looks similar there are some crucial differentiation.

(개념적으로 비슷해 보여도 몇 가지 중요한 차이점이 있다.)


1. Service - if it is destroyed while performing its job, in the middle by Android due to low memory scenario. Then android will make sure that it will restart your service, if you have returned START_STICKY or START_REDELIVER_INTENT from onStartCommand(). 

(Android의 low memory 시나리오에 의해 작업 수행 도중에 없어질 수 있다. onStartCommand()에서부터 START_STICKY나 START_REDELIVER_INTENT를 리턴 할 경우, 이 서비스를 재시작할 것이다.)


2. Thread - if it is destroyed by android in middle due to low memory, then android will not guarantee to restart it again. That means user lost his half work. 

(Android의 low memory 시나리오에 의해 작업 수행 도중에 없어질 수 있다, 그러나 재시작을 보장하지 않는다. 즉 하던 작업을 모두 잃게 된다.)


3. Service - is a component of android, so it has priority levels to be considered while destroying an application due to low memory.

(Service는 android component 중 하나이므로 low memory로 인해 없어지면서 고려해야 할 우선순위 수준을 보유하고 있습니다.)


Thread- is not a component of android, so android will not take thread priority into consideration while killing an application due to low memory.

(Thread는 android component가 아니므로 low memory로 인해 없어지면서 고려해야 할 우선순위 수준을 보유하고 있지 않습니다.)


If you want to do some heavy background functionality then it is always better to have a service with thread. If you feel that that background functionality to be alive as long as your activity is alive, then go for activity with thread or activity with async task.

(무거운 background 작업을 할 경우, service와 thread를 같이 동작하는 것이 좋다. 만약 background 작업을 activity가 살아 있는 동안만 하는 경우, thread나 asyn task를 activity와 같이 동작하는 것이 좋다.)


Question #10

How will you create an async task?

(async task 생성법은?)

                              

   

Answer

- AsyncTask: is a way to achieve multi threading in android. It has some advantages over normal java threads. 

(AsyncTask는 안드로이드에서 멀티 스레딩을 구현할 수 있는 방법입니다. 보통의 자바 스레드를 이용하는 것보다 몇 가지 장점이 있습니다.)


1. You don't need to use any Thread keyword, every thing will be taken care by AsyncTask class internally. It creates threads internally. 

(어떠한 Thread 키워드도 사용하지 않아도 된다. AsyncTask 내부적으로 구현되어 있다.)


2. Since android follows single threaded UI model, where other threads can't touch UI components directly. But from async task you can directly touch UI components from all the functions except from doInBackGround().

(안드로이드가 하나의 UI 메인 스레드를 허용한 이후로, 다른 스레드에서는 UI component를 직접 건드릴 수 없다. 그러나 asyncTask는 doInBackGround()를 제외한 모든 함수에서 UI component들을 직접 건드릴 수 있다.)


AsyncTask class will have 4 functions.

(4가지 함수를 가지고 있다.)


a. onPreExecute() - this is the first function to be called before calling doInBackGround(). This runs in UI thread. You can touch ui from this. 

(doInBackGround()이 호출되기 전에 최초로 호출되는 함수이다. 이 함수는 UI thread에서 실행되기 때문에 UI를 건드릴 수 있다.)


b. doInBackGround() - this runs in background thread created by AsyncTask class. Don't touch ui from this method. Write background heavy logic in this function, as it runs in background thread.

(AsyncTask에서 생성한 background 스레드에서 실행된다. UI를 건드릴 수 없다. background 스레드에서 수행하는 것처럼 무거운 로직들은 이 함수에 작성하라.)


c. onProgressUpdate() - this function is used to update UI while performing background functionality.

(background 작업이 수행되면서 UI를 업데이트하기 위해 쓰이는 함수이다.)


d. onPostExecute() - once doInBackGround() is finished this function will be called. If you want to update any UI after doInBackGround() use this function. This also runs in main ui thread.

(doInBackGround()가 끝난 후 이 함수가 호출된다. doInBackGround() 이후 UI를 업데이트하기 바란다면 이 함수를 이용하라. 이 함수도 UI 스레드에서 동작한다.)


Question #11

What is a handler thread? how it is different from normal thread?

(handler thread? normal thread와 차이점은?)

                              

   

Answer

- Handler thread is extended version of thread, where its looper will be prepared to handle incoming messages from other threads (Inter thread communication). But for normal java threads, looper will be there but in passive mode, i.e not prepared for inter thread communication.

(Handler thread는  다른 스레드들로부터 온 메세지들을 처리하기 위해 준비하고 있는 looper를 가지고 있는 thread의 확장된 버전이다.)


* Main thread는 기본적으로 looper를 가지고 message를 처리하는데 개념은 아래 글 참조해 보세요.

http://blog.naver.com/PostView.nhn?blogId=huewu&logNo=110115454542


Question #12

What is looper, handler, and message queue?

(looper? handlermessage queue?)

                              

   

Answer

- Looper - part of any Thread to loop through message queue. This will be used to check if any incoming message has arrived to this thread. Only one looper exists for a given thread. Only for handler threads this looper will be activated, for other normal threads this will be in passive or inactive mode. 

(Looper는 message queue에 메세지가 도착했는지 반복하여 검사하는 스레드의 한 부분이다. 스레드당 오직 하나의 looper만이 존재한다. 오직 handler thread을 위해 이 looper는 활성화될 것이다. 다른 보통의 스레드는 passive 또는 inactive 모드일 경우 활성화될 것이다.)


Message Q - part of any thread, will store incoming messages to this thread. For any thread only one message Q is available.

(도착한 메세지들을 저장하고 있는 스레드의 한 부분이다. 스레드당 오직 하나의 message Q가 존재한다.)


 Handler - communication channel between two threads. Handler is associated with Looper. for a given looper we can n number of handlers to communicate with it from out side world.

(Handler는 두 개의 스레드 간 통신하는 채널이다. Handler는 Looper와 연결되어 있다. 루퍼는 여러 개의 handler를 통해 다른 스레드와 통신할 수 있다. (1 대 N))


Question #13

What is serialization?

(serialization?)

                              

   

Answer

- Serialization is a concept of converting a non-primitive object into byte streams. Generally serialization is used to transfer the data between processes (applications). So it is used to perform IPC (Inter process communication). While sending data across two processes, we have to convert non-primitive objects to primitives or bytes, as O.S understands only primitives.


(직렬화는 non-primitive 객체를 바이트 스트림으로 변환하는 개념이다. 일반적으로 직렬화는 프로세스(어플리케이션)간 데이터를 전송하는데 쓰인다. 그래서 IPC를 수행하는데 쓰인다. O.S는 primitives나 bytes만 인식할 수 있기 때문에 프로세스를 통해 데이터를 전송하는 동안 non-primitive 객체를 primitives 나 bytes로 변환해야 한다.)


Question #14

How to update UI from other thread?

(다른 스레드로부터 UI를 업데이트하는 방법은?)

                              

   

Answer

- All Ui controls or views will be under control of Main thread (UI thread). If other thread wants to touch UI, it is possible through one of the inter thread communication, that is through handlers or through runOnUiThread() function or through asynctask.


(모든 UI나 view들은 메인 스레드 아래에서 컨트롤된다. 만약 다른 스레드가 UI를 터치하고 싶을 경우, 하나의 내부 스레트 통신을 통해서 가능하다. 즉 handler나 activity의 runOnUiThread() 또는 asyncTask를 통해 가능하다.)


* Handler - sendMessage(Message message), post(Runnable r)

* Activity - runOnUiThread(Runnable action)

* View - post(Runnable action)

* AsyncTask


Question #15

How to create a service with single thread?

(하나의 스레드로 service를 생성하는 방법은?)

                              

   

Answer

- It actually depends on the requirement. Use IntentService, if you don't want to interact with UI. Use AsyncTask if you want to interact with UI from background thread. It doesn't mean that you can't touch UI from IntentService, but you have to either use post() or runOnUiThread() or Handler concepts, which are little bit complicated to understand for novice android developers who are not well versed with threads.


(사실 요구사항에 따라 달라진다. UI와 상호작용하지 않는다면 IntentService를 이용하고 UI와 상호작용 한다면 AsyncTask를 이용해라. IntentService에서 UI를 터치하지 못한다는 의미가 아니라 스레드에 대해 정통하지 않은 초보 개발자의 경우 post()나 runOnUiThread() 또는 Handler 개념을 이해하기 복잡하기 때문이다.)


http://jo.centis1504.net/?p=968




1~2 문제 빼고는 모두 받아봤던 질문들이네요.

제 임의로 해석하느라 표현이 어색한 부분이 많은데 양해 부탁드립니다 ㅎㅎ

매거진의 이전글 안드로이드 면접 질문 #01
작품 선택
키워드 선택 0 / 3 0
댓글여부
afliean
브런치는 최신 브라우저에 최적화 되어있습니다. IE chrome safari