액티비티 스택은 기본적으로 일반적인 스택구조를 따른다. 액티비티1, 액티비티2, 액티비티3 이 있다고 했을 때, 이들을 차례대로 호출하면 아래와 같이 액티비티가 쌓인다. 그렇기 때문에 맨 마지막에 위치한 액티비티3가 현재 화면이고, 여기에서 뒤로가기를 탭하면 액티비티2가 보이고, 다시 뒤로가기를 하면 액티비티1가 보일 것이다. Intent객체에는 setFlags(int flags)라는 메서드가 있는데 이 메서드를 활용하면 스택이 쌓이는 구조를 변경할 수 있다. 대표적인 플래그 값들은 다음과 같다.플래그값설명비고Intent.FLAG_ACTIVITY_NO_HISTORY이 값을 설정해서 실행된 액티비티 이후에 실행되는 액티비티들은 스택에 쌓이지 않는다. 그렇기 때문에 현재 액티비티의 이전 액티비티는 항상 처음..
인텐트는 안드로이드 애플리케이션 구성요소 간에 어떤 작업을 수행하기 위해 정보를 전달하는 역할을 한다.다른 액티비티를 띄우거나 어떤 기능을 동작하게 하는 것과 같다. 안드로이드 애플리케이션의 구성요소액티비티서비스브로드캐스트 수신자내용 제공자 다른 안드로이드 애플리케이션에 인텐트를 전달하기 위한 메서드는 다음과 같다.startActivity() //액티비티를 띄울 때 사용startService(),bindService() //서비스를 사용할 때broadcastIntent() //브로드캐스팅을 수행할 때 인텐트는 액션+데이터로 이루어져 있으며, 액션은 수행할 기능, 데이터는 수행될 대상 데이터를 의미한다.android.content.Intent 경로에 Intent클래스를 보면 상수로 정의되고 ACTION_으..
실제 안드로이드 애플리케이션을 구성하다 보면 단순히 화면을 띄워 주는 것이 아니라 어떤 액티비티를 띄운건지 그리고 띄웠던 액티비티로 부터 응답을 받아 처리하는 일이 필요할 수 있다. 액티비티를 새로 띄우는 메서드 startActivity (Intent intent) startActivityForResult (Intent intent, int requestCode) startActivity 메서드- 타 액티비티를 호출한다.- 타 액티비티에 필요한 값을 전달할 수 있지만, 다시 응답 받을 수 없다. startActivityforResult 메서드- 타 액티비티를 호출한다.- 값을 전달하고, 다시 응답 받을 수 있다.- 첫번째 인자에는 Intent객체를 넣고, 두번째 인자에는 요청 코드를 넣는데.. 이 숫자는..
XML레이아웃 파일은 안드로이드 애플리케이션이 실행될 때 메모리로 로딩되어 객체화 된다.XML레이아웃에 정의된 내용이 메모리 상에 객체화 되는 과정을 인플레이션 이라고 한다. XML레이아웃 파일은 프로젝트가 빌드 되면 컴파일되어 이진 파일로써 안드로이드 애플리케이션에 포함되긴 하지만 실행 시점이 되어서야 메모리에 로드되어 객체화되기 때문에 자바에서 setContentView()가 호출되기 전에 해당 XML의 뷰를 참조하려 한다면 에러가 발생할 것이다. 이유는 메모리에 객체화 되지 않은 정보를 참조하려고 했기 때문이다.. setContentView(int layoutResID)가 XML파일에 대해 화면 전체를 나타내는 역할을 하는데, 일부의 뷰에서 다른 XML파일의 레이아웃을 가져올 수도 있다. 안드로이드..
1. 화면을 위 아해 두 영역으로 나누고 그 영역에 각각 이미지뷰를 배치. 2. 상단의 이미지뷰에 하나의 이미지가 보이도록 함. 3. 두 개의 이미지뷰 사이에 버튼을 하나 만들고 그 버튼을 누르면 상단의 이미지가 하단으로 옮겨져 보이고 다시 누르면 상단으로 다시 옮겨지는 기능을 추가 한다. xml파일 java파일 public class ChallengeActivity extends AppCompatActivity { private ImageView image1, image2; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activi..
- 프레임레이아웃은 단순한 레이아웃이다.- 하나의 뷰만을 화면에 표시한다. 프레임 레이아웃은 중첩기능을 가지고 있는데, 뷰를 하나 이상 추가 할 경우에 추가된 순서대로 쌓이는 특징을 가지고 있다.가장 먼저 추가한 뷰가 아래쪽에 쌓이며, 가장 나중에 추가한 뷰만 보이게 되는데, 이때 뷰의 가시성 속성(visibility)을 가지고 설정을 하게 되면 추가한 여러개의 뷰를 서로 전환하면서 보여줄 수 있다. 다음은 프레임 레이아웃으로 버튼을 클릭했을 때 이미지를 순서대로 보여주는 코드이다. 이미지가 더 이상 없을 때에는 처음으로 돌아가서 마지막에 추가한 뷰 순서대로 이미지를 다시 보여준다.-xml코드 visibility로 가시성 속성을 설정할 수 있으며, visible은 보여주는 값이고, invisible은 보..
테이블레이아웃은 엑셀시트 처럼 격자 형태의 행과 열로 구성된다. 테이블레이아웃 엘리먼트 안에는 TextRow라는 엘리먼트가 들어 갈 수 있는데, 하나의 TextRow는 하나의 행(가로)을 나타낸다. 그리고 하나의 TextRow안에 쌓이는 뷰는 Horizontal 방향으로 배치된다. 테이블레이아웃 엘리먼트에서 설정 할 수 있는 대표적인 속성으로 shrinkColumns와 stretchColumns가 있다.shrinkColumns : 부모 컨테이너의 폭에 맞추도록 각 열의 폭을 강제로 축소stretchColumns : 부모 컨테이너의 공간을 채우기 위해 지정된 뷰의 열의 폭을 자동 조절해서 늘린다. 테스트 TableRow의 높이값인 TableLayout의 layout_height는 항상 wrap_conten..
람다식은 메서드를 하나의 식(expression)으로 표현한 것.람다식을 '익명 함수'라고도 한다. 람다식의 기본 구문은 다음과 같다. //일반적인 메서드의 형식 int sum(int a, int b){ return a+b; } //람다식을 사용한 경우 (int a, int b) -> { return a+b; }; 메서드 선언부의 메서드명이 없어지고 선언부와 구현부 사이에 화살표 표시가 존재한다. 람다식은 그 자체는 메서드 모습을 하고 있지만 엄밀히 말하면 익명 클래스의 객체와 같다고 볼 수있다. Test t = new Test(){ int sum(int a, int b){ return a+b; } }; 익명 클래스의 객체라는게 위에서 보는 것 처럼 인스턴스 생성 즉시 그 클래스 타입의 멤버를 바로 기술..
layout_gravity : 대상이 되는 뷰의 부모 컨테이너의 공간에서의 위치를 정렬할 때 사용gravity : 뷰안의 내용을 정렬할 때 사용(텍스트뷰는 글자가 내용이 되고, 이미지뷰는 이미지가 내용이 됨) 먼저 gravity를 테스트 해본다. super.onCreate(savedInstanceState); //리니어 레이아웃 인스턴스 생성 후 뷰들을 배치할 방향을 설정 LinearLayout layout = new LinearLayout(this); layout.setOrientation(LinearLayout.VERTICAL); //(vertical,horizonal) //생성한 레이아웃에 들어갈 속성을 결정할 파라미터 생성(가로,세로) LinearLayout.LayoutParams params =..
안드로이드 프로그램을 구성하는 주요 컴포넌트(구성요소,부품)는 액티비티(Activity)다. 그러나 액티비티는 화면에 직접적으로 사용자에게 보이지 않고 실제 사용자가 보게되는 것은 뷰(View)이다. 뷰 여러개가 모여서 액티비티가 되고, 액티비티 여러개가 모이면 안드로이드 응용 프로그램이 된다. 뷰는 2가지로 나뉜다.1. 위젯(Widget) : 버튼, 텍스트 뷰, 에디트 등이 위젯이며 흔히 컨트롤(Control)이라고도 한다.2. 뷰그룹(ViewGroup) : 직접적으로 보이지 않으며 뷰(View)를 담는 컨테이너 역할을 한다. 뷰란?- 안드로이드에서의 뷰란 컨트롤과 위젯을 지칭하는데...버튼, 텍스트, 이미지 등이 이에 해당한다. 이들은 모두 View클래스로 부터 상속되어 저마다의 클래스 형태로 존재한..
APP을 만들기 위해서는1. 안드로이드 스튜디오 개발환경2. 안드로이드 sdk필요 xml로 레이아웃을 만들고, 자바 코드를 작성하고, 매니페스트파일을 수정하는 등의 과정 수행하고, 프로젝트의 소스파일이 자바 컴파일러에 의해 class파일이 만들어 진다 컴파일된 class파일은 개발도구 중 하나인 dx를 이용해 dex파일로 만들어지고 리소스 파일은 필요한 경우에 바이너리 파일로 빌드된다. 이 dex파일과 리소스파일은 aapt라는 개발도구에 의해 설치가 가능한 apk파일이 만들어진다. 개발단계에서는 인증을 위한 서명이 필요치 않은 unsigned상태이며, 플레이스토어에 올릴 때는 jarsigner를 이용해 signed상태로 만들어야 한다. 다른 사람이 만든 프로젝트를 안드로이드 스튜디오에서 열어보면 소스파일..
@InitBinder 스프링프레임워크에서의 바인딩이란 모델 클래스(오브젝트)의 프로퍼티(메서드 set)에 값을 넣는 것을 말한다. 두가지 바인딩을 제공하는데.. 첫 번째는 xml설정 파일을 통해 의 에 값을 넣는 것이다. 하지만 xml자체가 문자열이기 때문에 해당 빈클래스의 property값이 기본형 타입이나 String이라면 괜찮지만 그 외의 타입이라면 바인딩 하기전에 적절한 변환이 필요하다. 두번째는 Http를 통해 전달되는 헤더, 쿠키, 파라미터 같은 정보인데 이런 것들도 전부 문자열로 전달되는 값이다. 해서 이 경우에도 특정 타입으로 매칭시키려면 바인딩 과정 중에 적절한 변환이 필요하다. 컨트롤러 메서드에서는 @RequestParam, @PathVariable, @ModelAttribute등이 메..
JUnit은 자바에서 제공하는 표준 테스트 도구이다. 스프링도 JUnit을 발판으로 테스트를 하면서 만들어졌다고 한다. JUnit을 실행하는 방법 대부분의 자바 개발자가 사용하는 이클립스는 JUnit테스트를 지원하는 기능을 제공하고 있다.@Test가 들어있는 클래스를 선택 - Run - Run as - JUnit Test를 선택하면 실행할 수 있다. JUnit은 한번에 여러 테스트 클래스를 동시에 실행 할 수도 있다. 이클립스 왼쪽 소스폴더 트리의 프로젝트나 패키지 디렉토리를 선택해서 위에서 설명한 실행방법 대로 하면 JUnit테스트를 한번에 실행해준다. 테스트 클래스 작성방법 JUnit이 하나의 테스트 클래스를 가져와 테스트 하는 방식(과정)1. 테스트 클래스 내부에서 메서드 레벨에 @Test가 붙고 ..
제네릭스 - 메서드나 컬렉션클래스에 대해 컴파일시 타입체크를 해주는 기능. 장점 - 컴파일 시 의도하지 않는 타입객체가 저장되는 것을 막으므로 타입안정성 제공 - 타입의 체크와 형변환을 생략할 수 있기 때문에 코드의 간략화 > 제네릭클래스 기본형태 class Student{ private T name; List list = new ArrayList(); public void setName(T name){ this.name=name; list.add(name); } public T getName(){ return this.name; } } 제네릭 클래스를 만드는 방법은 클래스 명옆에 를 붙이고 이 T와 같은 타입을 가지는 곳에 똑같이 T를 써주면 된다. T를 '타입변수'라고 하며, Type의 첫글자를 의미..
기본적으로 로그파일은 var/log 라는 디렉토리 하위에 존재한다. /var/log/maillog메일과 관련된 로그를 기록하며, 이 파일을 이용하여 어떤 메일들이 오고 가는지 확인할 수 있다.메일이 오고 간 시간, 호스트, 데몬 유저, 메일 크기 등. /var/log/messages메일, 뉴스 등을 제외한 전체적인 로그를 기록하는 파일. /var/log/secure유저의 접속 기록을 표시 /var/log/lastlog각각의 계정에 대하여 마지막으로 로그인한 정보를 기록하는 파일이다.lastlog명령어로 확인 할 수 있다. /var/log/boot.log부팅시 서비스 데몬들의 실행 상태 기록 /var/log/dmesg시스템이 부팅할 때 출력되는 메세지가 기록되어 있다. /var/log/croncron과 관..