'10.04.06 Story Android 이야기2010. 4. 6. 19:28
public Cursor query
(String table, String[] columns, String selection, String[] selectionArgs,
String groupBy, String having, String orderBy, String limit)
SQLiteDataBase 클래스에서는 데이터베이스를 다루는 작업(추가, 삭제, 수정, 쿼리)를 담당하고, SQLiteOpenHelper클래스에서는 데이터베이스의 생성, 열기, 업그레이드를 담당한다.
그럴수도 있지만 이렇게 할 경우 코드상에서 데이터베이스 구조들도 다 드러나게 되고, 실제로 코드를 볼 때에도 이 코드가 보기 불편하다. 그래서, 일반적으로는 내가 사용할 데이터베이스에 맞게끔 데이터베이스 어댑터를 만들고 어댑터를 통해 데이터베이스를 관리합니다.
데이터베이스에 자료 입력하기 : ContentValues
//필요한 데이터를 입력한다
ContentValues newValues = new ContentValues();
newValues.put("name","구글“);
newValues.put("phone","123455");
//레코드를 추가한다
myDB.insert("data",null,newValues);
public void onClick(View v) {
switch(v.getId()){
case R.id.registerNotification:
// Get Notification Service
//Notification을 생성하기 위해 NotificationManager 객체를 생성
nm = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
//여기서는 Notification List에 표시되는 Notification 항목을 클릭하면 실행할 액티비티를 설정. 여기서는 NotificationManager액티비티를 설정해 주었다. PendingIntent는 나중에 Notification Panel에 표시된 항목을 클릭했을 때 액티비티를 호출하기 위해 getActivity()를 사용하였지만, 서비스를 호출하거나 브로드캐스트를 메시지를 보내는 것도 가능하다
//public static PendingIntent getActivity(Context context, int requestCode, Intent intent, int flag);
//컨텍스트는 액티비티를 인수로 받고(컨텍스트 하위 클래스가 Activity, requestCode는 액티비티간에 식별자로 이용할 코드, Intent는 어디로 Activity를 넘길 건가를 정의, flag는 잘 모르겠음)
PendingIntent intent = PendingIntent.getActivity(
NotificationBuilder.this, 0,
new Intent(this, NotificationMessage.class), 0);
//EditText에서 입력받은 문자열을 가져온다
String ticker = tickerText.getText().toString();
String title = contentTitle.getText().toString();
String text = contentText.getText().toString();
// Create Notification Object
//Notification 객체를 생성한다.
//여기에는 상태 표시줄에 표시될 아이콘, 텍스트 및 표시될 시각을 지정해준다
Notification notification =
new Notification(android.R.drawable.ic_input_add,
ticker, System.currentTimeMillis());
//Notification List에 표시될 항목을 설정
//제목 및 내용, 클릭시 수행할 작업인 PendingIntent를 넣어준다.
notification.setLatestEventInfo(NotificationBuilder.this,
title, text, intent);
//마지막으로, Notification Manager에 생성된 Notification을 등록
//Notification등록시에는 추후 Notification Manager를 통해 등록한 Notification표시를 해제하기 위해
//각 Notification의 고유ID를 같이 등록해준다.
nm.notify(1234, notification);
Toast.makeText(NotificationBuilder.this, "Notification Registered.",
Toast.LENGTH_SHORT).show();
break;
}
}
'Android 이야기' 카테고리의 다른 글
Android App 만들엇당 ㅋ (0) | 2010.09.01 |
---|---|
'10.04.09 Story (0) | 2010.04.08 |
'10.04.05 story 안드로이드 2주차 과제 (0) | 2010.04.05 |
'10.04.05 Story (0) | 2010.04.05 |
'10.04.04 Story (0) | 2010.04.05 |