2012년 5월 6일 일요일

액티비티 라이프사이클 관리


사용자가 앱을 실행, 나오기, 다시 접근할 때
액티비티 인스턴스는 라이프사이클의 각각의 상태에
놓인다.

액티비티가 처음으로 시작할 때 시스템의 전면으로 나와
사용자의 사용자 포커스를 받는다.
이 과정에서 안드로이드 시스템은 사용자에 의해 설정된 유저 인터페이스
와 다른 컴퍼넌트들의 메스드를 호출한다.
사용자는 다른 액티비티 또는 다른 앱을 실행할 경우
해당 액티비티는 백그라운드로 이동하여 해당 액티비티의 또 다른
라이프 사이클 함수 그룹을 호출하여 처리한다.

액티비티 시작하기

main() 메서드에서 개시되는 다른 프로그래밍 패러다임과 달리
안드로이드는 라이프 사이클의 특정 단계에 대응되는 콜백함수를
호출함으로써 액티비티 인스턴스의 코드를 초기화한다.

라이프사이클 콜백 이해하기

onCreate() -> Created -- onStart() -> Started(visible) -- onResume() -> Resumed(visible)

Resumed(visible) -- onPause() -> Paused(partially visible)
Paused -- onResume() -> Resumed
Paused -- onStop() -> Stopped(hidden)

Stopped -- onStart() -> Started
Stopped -- onDestroy() -> Destroyed

액티비티 라이프사이클 함수들의 역활
-사용자가 앱을 사용중 전화 수신시 또는 다른 앱으로 전환될 경우 종료되지 않게 한다.
-시스템 자원의 효율적 관리
-사용자 어플을 떠나서 다시 복귀해 어플의 전개과정을 이어간다.
-스크린의 랜드스케이프와 포트레이트 회전시 어플의 크래시 방지와 프로그래스를 잃지 않게 함.

액티비티의 정적 상태
-Resumed
: 액티비티가 전면에 배치되고 사용자와 상호작용할 수 있음
-Paused
: 액티비티가 다른 액티비티에 의해 부분적으로 가려지며 사용자와 상호작용이
중지된다.
-Stopped
: 액티비티는 완전히 숨겨져 백그라운드로 놓인며 해당 인스턴스와 멤버변수같은 상태정보들이 저장된다.

론처 액티비티 지정
사용자가 홈화면에서 앱아이콘을 클릭하면 시스템은 론처 또는 메인으로 지정된
액티비티의 onCreate()를 호출한다.
메인 액티비티는 프로젝트의 루트 디렉토리에서 AndoridManifest.xml에서 정의하며
MAIN action과 LAUNCHER category를 포함하는 <intent-filter>를 선언함으로써
이루어진다.

<activity android:name=".MainActivity" android:label="@string/app_name">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity

새 인스턴스 생성

TextView mTextView; // Member variable for text view in the layout

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Set the user interface layout for this Activity
    // The layout file is defined in the project res/layout/main_activity.xml file
    setContentView(R.layout.main_activity);
   
    // Initialize member TextView so we can manipulate it later
    mTextView = (TextView) findViewById(R.id.text_message);
   
    // Make sure we're running on Honeycomb or higher to use ActionBar APIs
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        // For the main activity, make sure the app icon in the action bar
        // does not behave as a button
        ActionBar actionBar = getActionBar();
        actionBar.setHomeButtonEnabled(false);
    }
}

액티비티 종료하기

@Override
public void onDestroy() {
    super.onDestroy();  // Always call the superclass
   
    // Stop method tracing that the activity started during onCreate()
    android.os.Debug.stopMethodTracing();
}

액티비티의 중지와 재개

@Override
public void onPause() {
    super.onPause();  // Always call the superclass method first

    // Release the Camera because we don't need it when paused
    // and other activities might need to use it.
    if (mCamera != null) {
        mCamera.release()
        mCamera = null;
    }
}

액티비티 정지와 재시작
-시나리오
사용자가 Recent Apps window를 열어 다른 앱으로 이동한다. 현재의 사용자 앱은
전면에 있는 것은 stop된다.

@Override
protected void onStop() {
    super.onStop();  // Always call the superclass method first

    // Save the note's current draft, because the activity is stopping
    // and we want to be sure the current note progress isn't lost.
    ContentValues values = new ContentValues();
    values.put(NotePad.Notes.COLUMN_NAME_NOTE, getCurrentNoteText());
    values.put(NotePad.Notes.COLUMN_NAME_TITLE, getCurrentNoteTitle());

    getContentResolver().update(
            mUri,    // The URI for the note to update.
            values,  // The map of column names and new values to apply to them.
            null,    // No SELECT criteria are used.
            null     // No WHERE columns are used.
            );
}

@Override
public void onResume() {
    super.onResume();  // Always call the superclass method first

    // Get the Camera instance as the activity achieves full user focus
    if (mCamera == null) {
        initializeCamera(); // Local method to handle camera init
    }
}

2012년 4월 30일 월요일

2012년 4월 29일 일요일

안드로이드 에뮬레이터 초기화


$cd ~/.android/avd/[user-defined.avd]/
$rm -f userdata-qemu.img

안드로이드 개발환경 설치


pre. 유분투 64에서 ia32-libs 설치

1. 이클립스 설치
$sudo apt-get install eclipse eclipse-jdt -force-yes=yes

2. 이클립스 실행문제
 #eclipse가 실행되지 않을 경우
$sudo update-alternatives --config java
실행하여 openjdk를 선택
 OR
 ln -s /usr/lib/jni/libswt-* ~/.swt/lib/linux/x86_64/
3. ADT 설치
 eclipse에서 Help-Install New Software를 클릭햐여
 https://dl-ssl.google.com/android/eclipse/ 주소를
추가하여 ADT를 설치








2012년 4월 28일 토요일

오라클 자바 최신버전 설치

Add ppa (ppa:webupd8team/java) then install Oracle Java Development Kit 7,
 run command below in terminal:
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo mkdir -p /usr/lib/mozilla/plugins #just in case, this will be added to the package in the next version
sudo apt-get install oracle-jdk7-installer 
To remove Oracle Java Development Kit 7, run command below :
sudo apt-get remove oracle-jdk7-installer
 
 
 $ sudo update-alternatives --config java
There are 2 choices for the alternative java (providing /usr/bin/java).

  Selection    Path                                      우선순  Status
------------------------------------------------------------
* 0            /usr/lib/jvm/java-6-openjdk/jre/bin/java   1061      auto mode
  1            /usr/lib/jvm/java-6-openjdk/jre/bin/java   1061      manual mode
  2            /usr/lib/jvm/java-6-sun/jre/bin/java       63        manual mode

Press enter to keep the current choice[*], or type selection number: 2
update-alternatives: using /usr/lib/jvm/java-6-sun/jre/bin/java to provide /usr/bin/java (java) in manual mode.

유분투 12.04 마우스 커서 크기 변경

Tutorial on how to change Mouse Cursors Size in Ubuntu 11.10 or 12.04 and other Gnome 3 based systems. Ideal if you have visual impairment that makes it difficult to see the default small cursor on the screen.

Instructions:
Open Terminal (Ctrl+Alt+T)
sudo apt-get install dconf-tools
gedit ~/.Xresources
Xcursor.size: 64
(Could also use 16, 32, 48, or 64)
Open DConf-Editor
Org - Gnome - Desktop - Interface
Change cursor-size to match earlier size
Reboot

Please note this won't work with the KDE Oxygen cursors

ubuntu 11.10/12.04 gnome3/unity에서 마우스커서 바꾸기

Tutorial on how to change Mouse Cursors in Gnome 3 with Ubuntu 11.10 and 12.04. I show you how to get the fancy KDE Oxygen coloured mouse cursors selected, but the same also applies for any other X-Cursor Theme.

Install:
gnome-tweak-tool
oxygen-cursor-theme
oxygen-cursor-theme-extra

Open Advanced Settings (gnome-tweak-tool)
Select new cursor theme

Open Terminal (Ctrl+Alt+T)
sudo update-alternatives --config x-cursor-theme

Press Alt+F2
compiz --replace
(Alternatively reboot if compiz --replace doesn't work)

To undo the changes simply repeat all the commands above but choose DMZ-White Cursor theme.