알림 대화상자는 마치 자바스크립트의 confirm함수와 같은 기능을 담당하여, 일방적으로 메세지를 보여주고, 예, 아니오, 같은 응답을 처리할 수 있다. 다음은 대화 상자를 띄워서 예를 누르면 액티비티를 종료하는 애플리케이션 코드이다. 레이아웃 xml 코드 액티비티 java 코드 public class DialogActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_dialog); } public void onClickCreateDialog(View v) { ..
이전에서 브로드 캐스트를 사용하면 SMS를 수신할 때 onReceive()메서드가 호출됨을 알 수 있었다. 그러나 마시멜로 버전 부터는 권한 문제로 인해 onReceive()메서드가 호출 되지 않는다. 기존에는 권한이 일반 권한 뿐이었지만, 마시멜로 부터 일반권한과 위험권한 두 그룹으로 나뉘게 됐다. 위험권한에 대해서는 애플리케이션 실행 시에 해당 권한을 부여 받도록 변경되었다. (마시멜로)6.0 미만 버전에서는AndroidManifest.xml에 권한을 설정하는 것만으로 영구적으로 애플리케이션의 권한을 설정할 수 있었지만, 6.0 이상에서는 애플리케이션 실행 시에 권한을 일일이 획득해야 한다. 다음은 위험권한에 대한 그룹과 세부권한이다.Dangerous Permission GroupPermissions..
안드로이드에서의 서비스는 백그라운드에서 실행되는 프로세스를 의미한다.액티비티와는 다르게 화면이 존재하지 않지만, 역시 액티비티처럼 AndroidManifest.xml파일에 등록해줘야 하며, 액티비티 상에서 이 서비스를 시작하고 싶을 경우에는 startService()메서드를 이용해서 시작시킬 수 있다.서비스를 도중에 중지하고 싶을 때는 stopService()메서드를 호출하면 된다. 서비스는 Service클래스를 상속 받아서 구현하면 된다. public class BlankService extends Service { public void onCreate(){ super.onCreate(); } @Override public IBinder onBind(Intent intent) { throw new Un..
하나의 액티비티에서 작업을 한다음 다음 액티비티로 넘어가더라도 이전의 액티비티의 상태정보를 가지고 작업을 할 수 있어야 한다. 이런 경우에 액티비티의 수명주기 메서드인 onPause(), onResume()을 이용해서 액티비티가 멈추거나 다른 액티비티에 의해 가려질 때 데이터를 저장하고, 액티비티가 다시 보이거나 새로 시작될 때 저장된 데이터를 호출하는 방식으로 상태정보를 저장하고 가져올 수 있다. SharedPrefereces타입은 데이터를 저장하는 기능을 제공하는 클래스이다.SharedPrefereces는 그 자체로 인스턴스를 생성하고 참조할 수 없는 인터페이스라서 참조하는 방법은 Context의 자손클래스에 정의된 getSharedPrefereces()메서드를 호출해서 참조할 수 있다. 이 메서드의..
액티비티는 처음 실행될 때 메모리에 쌓이는 가정부터 실행, 중지 해제되는 여러가지 상태정보를 가지며 이러한 상태는 안드로이드 시스템에 의해서 관리되고 각각의 상태에 따라 해당 메서드를 자동으로 호출하게 되어있다. 만약에 새로운 액티비티가 만들어진다면 처음에 onCreate, onStart, onResume순서대로 호출되고, 이렇게 실행된 액티비티는 다른 액티비티가 액티비티 스택의 상위를 차지하게 되면 onPause가 호출되면서 일시정지 상태가 되고, 아예 중지가 되어 버린다면 onStop이 호출되어 정지 상태가 된다. 그러다가 처음의 액티비가 다시 시작된다면 onResume이 호출되고, 액티비티가 메모리에서 아예 제거될 경우에는 onDestroy가 호출된다. 다음은 액티비티 상세 메서드 표이다.onCre..