노력과 삽질 퇴적물

안드로이드: 기초정리(3) 본문

프로그래밍note/언어. JAVA & JDK 계열

안드로이드: 기초정리(3)

MTG 2012. 9. 17. 17:02

Android APIs Reference


안드로이드: 기초정리(1)

안드로이드: 기초정리(2)

안드로이드: 기초정리(3)

안드로이드: 기초정리(4)


추천자료: 안드로이드 개발시 100가지 팁

추천자료: [Android] 정보 정리






07. 알림창

 1. 토스트

 토스트를 띄우는 코드는 크게 2가지가 가능하다.
-> 유형1.

Toast.makeText(getApplicationContext(), "토스트 알림", Toast.LENGTH_LONG).show();

-> 유형2.

Toast toast = Toast.makeText(getApplicationContext(), "토스트 알림", Toast.LENGTH_LONG);

toast.show();




 2. 상태알림(notification)과 해지

① res/layout

... ... ...

    <Button

        android:id="@+id/registerB"

        android:layout_width="match_parent"

        ... ... ...

        android:onClick="xxxx"

        android:text="notification 등록" />


    <Button

        android:id="@+id/cancleB"

        android:layout_width="match_parent"

        ... ... ...

        android:layout_marginTop="50dip"

        android:onClick="xxxx"

        android:text="notification 취소" />

... ... ...

② src/패키지






 3. 다이얼로그

new AlertDialog.Builder(액티비티명.this)

.setTitle("알림창")

//.setIcon(R.drawable.icon)

.setMessage("이 메시지는 영국에서 시작ㄷ... 아니 안드로이드 스타일 알림창입니다.")

.setPositiveButton("OK", null)

.setNegativeButton("취소", null)

.show(); //or .create()

-> show메서드는 대화상자의 운영까지 책임지진 않는다.






08. 서비스

 1. 개념 및 기본실행

① 기본 개념

-> 특정 액티비티와 상관없이 백그라운드에서 실행되는 컴포넌트

public class MainActivity extends Activity implements ...

{

... ...

   Intent intent = new Intent();

   intent.setClass(getApplicationContext(),

                          CustomedService.class);

   intent.putExtra("Tag_NAME", "message");

   startService(intent);   //stopService(intent);

... ...

}

public class CustomedService extends Service

{

   ... ...

   public void onCreate() {

   Thread t=new Thread(){

         public void run() {   }

      };

   t.start();

   }

   public void onDestroy() {   }

   ... ...

}

② 생명주기

->유형A

i) onCreate(): 서비스가 생성될때 호출

ii) onStart(): startService()에 의해 서비스가 시작될 때마다 호출

iii) onDestroy(): 서비스가 종료될때호출


-> 유형B

i) onCreate(): 서비스가 생성될때 호출

ii) onBind(): startService()에 의해 서비스가 시작될 때마다 호출

iii) onUnbind(): 서비스와 연결이 끊겼을때호출

iv) onDestroy(): 서비스가 종료될때호출

 





 2. 구현 예시

-> 

① 


② 







08. 뷰와 고급그리기

 1. View

-> View 위에 뭔가를 그리기 위해선 View를 상속한 클래스를 만들고, onDraw()를 오버라이딩해서 그 안에 원하는 작업을 넣고, invalidate()를 호출하면 화면이 갱신됩니다.




http://www.androidside.com/bbs/board.php?bo_table=B46&wr_id=443

http://blog.daum.net/aero2k/14




 2. 웹뷰 클라이언트(WebViewClient)

① res/layout

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"

    xmlns:tools="http://schemas.android.com/tools"

    android:layout_width="match_parent"

    android:layout_height="match_parent" >


    <WebView

        android:id="@+id/androidWebView"

        ... ... ...

        ... ... ... />


</RelativeLayout>

② src/패키지






 3. 탭뷰

-> 해당 구현법은 다른블로그에 정리가 잘 되어 있어서 해당 링크로 대체합니다.

 안드로이드(android) 탭(TabActivity) 3가지 구현하기(By. 녹두장군)




 4. 카메리와 이미지뷰

① res/layout

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"

    xmlns:tools="http://schemas.android.com/tools"

    android:layout_width="match_parent"

    android:layout_height="match_parent" >


    <ImageView

        android:id="@+id/imageView1"

        ... ... ...

        android:src="@android:drawable/ic_menu_crop" />


    <Button

        android:id="@+id/takePicture"

        ... ... ...

        android:onClick="getCaptureView"

        android:text="안드로이드 카메라&amp;이미지뷰" />


</RelativeLayout>

② src/패키지

-> 버튼 컴포넌트에 이벤트함수를 직접 연견했기 때문에 java코드에서 별도로 버튼클릭에 대한 지정은 없다.






 5. SurfaceView

-> View를 상속받은 SurfaceView는  SurfaceHolder.lockCanvas()와 SurfaceHolder.unlockCanvasAndPost()를 이용하여 화면을 갱신.

-> SurfaceView에 대한 세부설명: http://aroundck.tistory.com/202


① res/layout

② src/CustommedView.java

... ... ...

public class MainActivity extends Activity implements OnTouchListener

{

   CustommedView cusV;


    @Override

    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        ... ...

        cusV = new CustommedView(getApplicationContext());

        setContentView(cusV);       

    }

... ... ...

}

... ... ...

class CustommedView extends SurfaceView implements SurfaceHolder.Callback

{

... ... ...

   //서페이스 뷰는 onDraw메소드를 쓰면 안 된다. (처리 속도가...)

   protected void doDraw(Canvas canvas)

   { ... ... }

}