brunch

You can make anything
by writing

C.S.Lewis

by 이승현 Jun 02. 2016

안드로이드 면접 질문 #05

Android interview questions

Skillgun


Android receiver/content provider interview questions and answers


http://skillgun.com/android/receivers/interview-questions-and-answers/paper/30



Receiver


Question #01

What will happen if broadcast receiver binds to binder service? Is there any problem?

(브로드 캐스트 리시버를 바인더 서비스와 결합하면 어떤 일이 벌어지는가? 문제는?)

                              

   

Answer

- One should not bind a service from Broadcast receiver. The reason is broadcast receiver are light weigth components, where it has to finish its functionality with in not more than 10 seconds maximum. Else android may forcefully kill your receiver. Binding (establishing connection to) a service may take more than 10 seconds in some worst cases, that's why android won't allow it.

(브로드 캐스트 리시버는 서비스와 결합하지 않아야 합니다. 브로드캐스트 리시버들은 최대 10초 이내에 작업을 완료해야 하는 경량 프로세스이기 때문입니다. 10초 이상이 걸리면 안드로이드는 강제로 리시버를 종료할 것입니다. 서비스와 결합하면 최악의 경우 10초 이상 수행 시간이 걸리기 때문에 안드로이드는 이를 허용하지 않습니다.)


Rules for Broadcast Receivers:


1. Broadcast receivers will not have any UI(mostly) and it will have only background logic.

(브로드캐스트 리시버는 (대부분) UI가 없고 오직 백그라운드 로직만 있다.)


2. Broadcast receivers will have the maximum time limit of 10 sec to finish its functionality otherwise it will crash.

(브로드캐스트 리시버는 최대 10초의 작업 제한시간을 가지고 있다. 만약 초과한다면 충돌이 일어날 것이다.)


3. You should not do long running operations or asynchronous operations in the receiver.

(작업시간이 길거나 비동기화 동작은 수행하면 안 된다.)


Example :

a. Preparing SD card. 

b. Uploading / Downloading files from internet.

c. Creating DB files.

d. Binding to services.

4. Do not show dialog to the user in broadcast receiver. (this is asynchronous operation)

5. You can use "toast" or "notifications".

6. Don't write any heavy functionalities.


Question #02

Is it possible to start a service from a broadcast receiver?

(브로드캐스트 리시버에서 서비스를 시작할 수 있나?)

                              

   

Answer

- Any component can communicate with other component. only exception for this rule is don't bind to a service from a broadcast receiver. other wise one is free to start a service.

(어떠한 component도 다른 component들과 소통할 수 있다. )

* 서비스와 브로드캐스트 리시버 결합은 안된다.

* 브로드캐스트 리시버에서 서비스를 시작할 수 있다.


Question #03

What is the difference between broadcast receiver and a service?

(브로드캐스트 리시버와 서비스의 차이점은?)

                              

   

Answer

- Broadcast receiver is like gateway for other components, can do small background functionality with in 10 seconds.

(브로드캐스트 리시버는 다른 component에 대한 게이트웨이 같다, 그리고 10초 이내의 간단한 백그라운드 작업을 할 수 있다.)


- Service can do long running operation in the background with out having UI, and no time limit for it. but both receiver and service both can interact with UI if they want to. services will not have time limit of 10 seconds, receivers respond to broadcasted messages.

(서비스는 UI, 시간제한 없이 오랜 시간이 걸리는 백그라운드 작업을 할 수 있다. 그러나 둘 다 원한다면 UI와 상호작용할 수 있다. 서비스는 10초의 제한 시간이 없고, 리시버는 broadcated 메시지에 응답한다.)


Question #04

What is the difference between sendbroadcast(), sendorderedbroadcast(), sendstickybroadcast()?

(sendbroadcast(), sendorderedbroadcast(), sendstickybroadcast() 차이점?)

                              

   

Answer

- sendbroadcast() : normal broadcast, but we can set priority as well.

(일반 브로드캐스트, 우선순위를 설정할 수 있다.)


- sendorderedbroadcast() : we can set priority, and set result. can block broadcasts as well.

In the ordered broadcast you can predict the order of broadcast receiver using priority in the intent_filter.

(우선순위를 설정하고, 그 결과를 설정할 수 있습니다. 뿐만 아니라 방송을 차단할 수 있습니다. ordered 브로드캐스트에서는 인텐트 필터에 우선순위를 사용하여 브로드캐스트 리시버의 우선순위를 예측할 수 있습니다.)


1. If the priority is same for two receivers then order cannot be predicted.

(우선순위가 동일한 경우 순서가 예측될 수 없다.)


2. In the ordered broadcast you can also pass data between two receivers.

(ordered 브로드캐스트에서는 두 개의 리시버간 데이터를 전달할 수 있다.)


3. You can also abort the broadcast anywhere in between the receivers.

(또한 리시버 사이의 아무 곳이나 브로드캐스트를 중단할 수 있습니다.)


- sendstickybroadcast() : intent passed with this will be stick for future users who are registering through code (dynamic receivers).

(sendstickybroadcast()와 같이 전달된 인텐트는 코드를 통해 등록될 미래의 사용자들 위해 sticky 될 것이다.)


When somebody sends a sticky broadcast using send stickyBroadcast(in); then that broadcast will be available for the future users who are using dynamic receivers.

This broadcast will be available for only Dynamic Broadcast rx who are coming in future.

Eg for stickybroadcast is - BATTERY LOW.

(stickyBroadcast(in)를 이용해 sticky 브로드캐스트를 보낼 때, 브로드캐스트는 동적 리시버를 사용하는 미래 사용자들에게 유효할 것이다. 이 브로드캐스트는 오직 다가올 미래의 사용자들을 위한 동적 브로드캐스트에게만 유효할 것이다.)


Question #05

What is the life cycle of a broadcast receiver in android?

(브로드캐스트의 생명주기?)

                              

   

Answer

- there is only one function in broadcast receiver, that is onReceive().

(브로드캐스트 리시버는 오직 onReceiver() 함수만 가지고 있다.)


Question #06

Under what thread broadcast receiver will run?

(브로드캐스트 리시버는 어떤 스레드 아래서 실행되는가?)

                              

   

Answer

- By default all components run in Main thread give to your application.

(기본적으로 모든 component들은 메인 스레드에서 실행된다.)


Content provider


Question #01

When does onCreate() function of ContentProvider will be called?

(언제 ContentProvider의 onCreate() 함수가 호출되는가?)

                              

   

Answer

onCreate() will be called when the application containing the content provider is loaded into the memory for the first time.

(content provider를 포함하는 어플리케이션을 처음 메모리에 로드할 때 onCreate ()가 호출될 것이다.)


Question #02

What is the purpose of the ContentProvider class?

(ContentProvider 클래스 용도는?)

                              

   

Answer

If you want to share the data of one application with the application then use content provider.

(다른 어플리케이션과 데이터를 공유하기 원한다면 content provider를 이용해라.)


Note: We can start an Activity, a service, and a broadcast receiver by using intents. But you can't start or communicate with a content provider by using intents. If you want to communicate with content provider then you have to use content resolver.

(인텐트를 이용해 엑티비티, 서비스 그리고 브로드캐스트 리시버를 시작할 수 있다. 그러나 content provider는 이를 이용해 시작할 수 없다. content provider와 소통하기 원한다면 content resolver를 이용해라.)


1.content provider, and resolver will handle IPC(Inter process communication) mechanism when sharing data between 2 applications.

(cotent provider와 content resolver는 두 애플리케이션 간 데이터를 공유하기 위해 IPC 메커니즘을 다룬다.)


2.content provider has the capability to handle multiple threads, when queries are coming from multiple resolvers.

(content provider는 query가 여러 resolver에서 오는 여러 스레드들을 처리하는 기능을 가지고 있다. )


Question #03

What will happen if database is not closed properly after using it?

(DB 사용 후 close 하지 않는다면 어떤 일이 일어나는가?)

                              

   

Answer

It will leak the memory. Once you are done with database we have to close it, because it will be cached into memory when we open it and eat up memory space.

(메모리 부족이 발생할 것이다. DB open시 메모리에 캐시 되고 메모리 공간을 잡아먹기 때문에 DB 작업이 끝나면 반드시 close 해야 한다.)


Question #04

Is it possible to call getWritableDataBase() from onCreate() of ContentProvider?

(ContentProvider의 onCreate()에서 getWritableDataBase()를 호출할 수 있는가?)

                              

   

Answer

getWritableDatabase() may take lot of time to create and update tables, so its better to differ this call to later point of time. because if we put this call in onCreate(), then application loading time will be increased and may irritate the user.

(getWritableDatabase()는 table을 생성하고 업데이트하는데 많은 시간이 걸릴 수 있다, 그래서 나중에 호출하는 것이 더 좋다. 만약 onCreate()에서 호출하면 어플리케이션 로딩 시간이 오래 걸리고 사용자에게 불편을 줄 수 있다.)


Question #05

What are the mandatory functions to be implemented for a Content provider?

(Content provider에서 필수적으로 구현해야 하는 함수는?)

                              

   

Answer

onCreate, insert, update, delete, query, getType are the mandatory functions to be implemented in Content Provider.

(onCreate, insert, update, delete, query, getType)


Question #06

What is the difference between Content provider and SQLite database? which one to use?

(Content provider와 SQLite database 차이?)

                              

   

Answer

DB is used to create tables private to application. You can access SQLite Database with in the application directly. Other applications can't directly touch the SQLite Database of a given application.If you want to share your database with other applications then use Content provider. Content provider is used to share the data with other applications.

(DB는 어플리케이션 전용 테이블을 생성하는데 쓰인다. application에서 SQLite DB에 직접 접속할 수 있다. 그러나 다른 어플리케이션에서는 이 SQLite DB에 직접 접속할 수 없다. 만약 이 database를 다른 어플리케이션과 같이 공유하고 싶다면 Content provider를 이용해라. Content provider는 다른 어플리케이션들과 데이터를 공유하기 위해 쓰인다.)


Question #07

Which of the options are supported to be used with a content provider?

(content provider와 함께 쓸 수 있는 옵션들은?)

                              

   

Answer

To share data with other applications, data can be stored internally by using files, or databases, or through some network servers. Right now there is no support for SharedPreferences.

(다른 어플리케이션들과 데이터를 공유하기 위해, 파일이나 database를 이용해 내부적으로 데이터를 저장하거나 네트워크 서버를 이용할 수 있다. 그러나 당장은 SharedPreference를 이용한 공유는 없다.)


Question #08

How to access context in content provider?

(content provider에서 context에 접속하는 방법은?)

                              

   

Answer

use getcontext() in oncreate() or use getApplicationContext().

(getContext()나 getApplicationContext() 함수를 이용한다.)


Question #09

What is the difference between ContentValues and Cursor, in SQLite?

(SQLite에서 ContentValues와 Cursor의 차이점은?)

                              

   

Answer

ContentValues is a name value pair, used to insert or update values into database tables. ContentValues object will be passed to SQLiteDataBase objects insert() and update() functions. Where as Cursor is a temporary buffer area which stores results from a SQLiteDataBase query.

(ContentValues는 database 테이블에 값을 넣거나 업데이트할 때 쓰이는 value pair 이름이다. ContentValues 객체는 SQLiteDataBase 객체의 insert()와 update() 함수들에 의해 전달된다. Cursor는 SQLiteDataBase 쿼리로부터 얻은 결과를 저장하는 임시 버퍼 같은 존재이다.)


Question #10

What is the life cycle of a content provider?

(content provider의 생명주기?)

                              

   

Answer

A content provider's onCreate() function will be called when first time if some client calls providers functions using content resolver.

(content resolver를 이용해서 content provider를 호출할 때 처음에 onCreate() 함수가 호출된다.)


Question #11

How to upgrade SQLite database of an android application, before uploading the new version into play store?

(play store에 새 버전을 업로딩 하기 전에 안드로이드 애플리케이션의 SQLite DB를 업그레이드하는 방법은?)

                              

   

Answer

If you want to upgrade the data base of your existing application, which is released into android play store, then follow below steps.

(안드로이드 play store에 릴리즈 된 어플리케이션의 DB를 업그레이드하기 원한다면, 아래 절차를 따라라.)


1. Create new version number for your latest database.

(최신 DB의 새로운 버전 번호를 생성.)


2. Based on some condition pass this latest version number to SQLiteOpenHelper constructor function.

(일부 조건에 따라 SQLiteOpenHelper의 생성자 함수에 최신 버전 번호를 전달.)


3. then what ever the updations you want to make to database, do it in onUpgrade() of SQLiteOpenHelper class.

(SQLiteOpenHelper 클래스의 onUpgrade()를 이용해 DB를 업데이트해라.)


Question #12

Can one application access other application's database directly?

(한 어플리케이션에서 다른 어플리케이션 DB로 직접 연결할 수 있는가?)

                              

   

Answer

Content provider is a mechanism to access apps data by out side world. even if data is stored in internal memory of app, it is possible to access it through this component.

(Content provider는 out side world에서 앱 데이터에 연결하는 메커니즘이다. 데이터가 app 메모리 내부에 저장되어 있더라도 content provider를 통해 연결이 가능하다.)


Note: Directly with out using content provider, accessing database is not possible.

(content provider를 이용하지 않고서는 DB에 접속이 불가능하다.)


Question #13

How to start a content provider using an intent?

(인텐트를 이용해 content provider를 시작하는 방법은?)

                              

   

Answer

Intents will be used to communicate or start components of android. Only exception is content provider. You can start an activity, service, and a broadcast receiver using intent but not content provider. For content provider we have to use content resolver to communicate.

(인텐트는 안드로이드의 component들을 시작하고 서로 연결할 때 이용한다. content provider만 예외이다. intent를 이용해 엑티비티, 서비스 브로드캐스트 리시버를 시작할 수 있지만 content provider는 시작할 수 없다. content provider를 시작하기 위해서는 content resolver를 이용해야 한다.)





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