Android
-
Permission 요청하기 ( api 23 이상)Android 2020. 9. 2. 18:45
checkSelfPermission(String permission) 함수를 이용하여 권한이 있는지 없는지 체크할 수 있다. if (checkSelfPermission(ACCESS_FINE_LOCATION) ==PackageManager.PERMISSION_GRANTED) 허용 되어 있는지 → PackageManager.PERMISSION_GRANTED 허용되어 있지 않은지 → PackageManager.PERMISSION_DENIED 그다음 다음과 같은 방법으로 사용자에게 권한 요청을 합니다. ActivityCompat.requestPermissions(this, new String[] {ACCESS_FINE_LOCATION}, 1);
-
File read and writeAndroid 2020. 9. 2. 18:44
Write val file:String = fileName.text.toString() val data:String = fileData.text.toString() val fileOutputStream:FileOutputStream try { fileOutputStream = openFileOutput(file, Context.MODE_PRIVATE) fileOutputStream.write(data.toByteArray()) }catch (e: Exception){ e.printStackTrace() } Read var fileInputStream: FileInputStream? = null fileInputStream = openFileInput(filename) var inputStreamReade..
-
View LifecycleAndroid 2020. 9. 2. 18:43
View는 사용자 UI의 기본 요소이며 여러 UI 컴포넌트와 상호작용합니다. View가 포커스를 얻으면 layout을 그리도록 요청한다. onMeasure 자식뷰의 크기를 측정하고 그것을 토대로 자신의 크기를 결정한다. ViewGroup.MeaureSpec : 부모에서 자식으로 전달되는 레이아웃 요구 사항을 캡슐화한다. EXACTLY : 부모뷰가 자식뷰의 크기를 원하는 대로 결정한다. 주어진 경계내에서 사이즈가 결정된다. AT_MOST : 부모뷰가 자식뷰의 크기를 최대 크기로 결정한다. UNSPECIFIED : 부모뷰가 자식뷰가 원하는 대로 크기를 결정할 수 있게 한다. onLayout 모든 자식뷰의 크기와 위치를 할당 한다. onDraw 이전 단계에서 계산한 크기와 위치를 가지고 View를 그리는 단계..
-
Fragment lifecycleAndroid 2020. 9. 2. 18:41
시작 과정 onAttach() : activity 에 추가되면 호출 된다. onCreate() : fragment 호출 받아 생성되는 시점, Activity와 다르게 Ui 작업을 할 수 없다. fragment 가 back statck 됐다가 다시 실행되는 경우에는 실행되지 않는다. onCreateView() : view 를 inflating 하고, Ui 작업을 할 수 있다. onActivityCreated() : activity에서 fragment를 완전히 생성되고 난 이후에 실행된다. view 가 만들어져 있으므로 view를 변경하거나 data 를 넣는 작업 등이 가능하다. onStart() : 프래그먼트가 사용자에게 보여지기 전에 호출되는 함수이다. onResume() : 프래그먼트가 화면에 보여지는..
-
Activity lifecycleAndroid 2020. 9. 2. 18:40
생명 주기 종류 onCreate() Activity를 생성할때 가장 먼저 실행되는 것 이다. 전체 생명 주기 동안 한 번만 발생 해야 하는 로직 들을 수행한다. ex) 초기화 처리, 뷰생성 완료되면 onStart()을 호출한다. onStart() Activity가 사용자에게 보여진다. Activity를 foreground에 보내 상호작용을 준비하는 단계 이므로 사용자와 상호작용은 불가능 하다. 완료되면 onResume()을 호출한다. onResume() 사용자와 상호작용을 시작합니다. App에서 focus가 떠날 때까지 머무릅니다. ex) 다른 Activity로 이동, 화면 꺼짐 등 실행해야 하는 모든 기능을 활성화 할 수 있다. 방해되는 이벤트 발생 시 일시 정지 상태에 들어가고 onPause()을 호..
-
Architecture Pattern-MVVMAndroid 2020. 9. 2. 18:36
MVVM Model , View , ViewModel의 약자입니다. ViewModel은 데이터와 명령을 구현하고 상태가 변경되면 View에 알려 줍니다. 상태 변경 알림을 받은 View는 변경을 적용할지 말지를 결정합니다. View는 VM을 알지만 Model을 모르고 VM은 Model은 알지만 View를 모릅니다. View와 VM는 N : 1 관계이기 때문에 VM의 재사용이 가능하지만 코드의 가독성이 떨어지고 복잡해질 수 있기 때문에 1:1 로 많이 사용하는 편입니다. Data Bind, RxJava, LifeCycler등을 주로 같이 사용합니다. AAC ViewModel 화면 회전시 데이터 유지를 위하여 만들었습니다. 안드로이드의 생명주기를 알고 있기 때문에 화면 회전시 데이터 유지를 할 수 있습니다...
-
Architecture Pattern-MVPAndroid 2020. 9. 2. 18:35
MVP Model , View , Presenter 의 약자 입니다. 개념 MVC의 Controller 대신에 Presenter로 변경됩니다 Presenter는 View와Model 사이에서 중재자 역할을 합니다. 과정 사용자가 View를 통해 이벤트를 전달합니다. Presenter는 View에게 전달받은 이벤트를 처리합니다. (필요에 의해 Model의 데이터를 가져오거나 업데이트 합니다) Presenter에서 View를 업데이트 합니다. 장점 MVC와 달리 View와 Model이 의존성을 가지지 않습니다. Presnter 와 Model은 1:N 관계입니다. (재 사용성 o) 유지 보수가 쉽습니다. 유닛 테스트에 용이합니다. 단점 프로젝트가 커질 수록 코드 자원이 증가 합니다. Architecture Pa..
-
Architecture Pattern-MVCAndroid 2020. 9. 2. 18:33
MVC Model , View , Control의 약자입니다. Model → 데이터 관리를 담당하는 부분 View → 사용자에게 제공되는 UI 부분 Controller → 사용자의 입력에 따라 Model에 의해 View를 정의하는 부분 장점 Model이 종속되지 않아 재사용이 가능하다. 구현 하기가 쉽다. 개발기간이 짧아진다. 단점 View 와 Model 사이의 의존성이 발생한다. 코드가 길어지고 복잡해진다. 유지 보수가 힘들어진다. Architecture Pattern-MVP Architecture Pattern-MVP MVP Model , View , Presenter 의 약자 입니다. 개념 MVC의 Controller 대신에 Presenter로 변경됩니다 Presenter는 View와Model 사이..