티스토리 뷰

소소한 바램이...

나의 바램은 소소했다...오늘의 일정 리스트에서 각 항목을 메모 액티비티로 연결하는 것...
간단하지 않은가??
그러나 간단하지 않았다....
다음은 나의 뻘짓이다...


실패

1. 리스트의 각 아이템마다 Intent 의 putExtra 에 id값을 넣어서 전달했다.

자연스러운 코딩이었지만...putExtra 값이 사라져서 아무것도 나타나질 않았다.

Intent intent_memo = new Intent(context, MemoActivity.class);
iintent.putExtra("SID", id);
PendingIntent pendingIntent_memo
        = PendingIntent.getActivity(context, 0, intent_memo, 0);
item.setOnClickPendingIntent(R.id.schedule_item, pendingIntent_memo);

2. getActivity 의 플래그값을 변경했다.

putExtra 값은 나타났지만 모든 아이템들이 리스트의 맨 마지막 값을 들고 있었다.

Intent intent_memo = new Intent(context, MemoActivity.class);
iintent.putExtra("SID", id);
PendingIntent pendingIntent_memo 
       = PendingIntent.getActivity(context, 0, intent_memo, PendingIntent.FLAG_UPDATE_CURRENT);
item.setOnClickPendingIntent(R.id.schedule_item, pendingIntent_memo);

성공 : setData를 이용해서 Uri 형식으로 전달하기

결국 구글링을 통해 얻은 꼼수를 사용했다....이건 정말 맘에 안든다...그러나 성공했다.

Intent intent_memo = new Intent(context, MemoActivity.class);
intent_memo.setData(Uri.parse(Integer.toString(info.id)));
PendingIntent pendingIntent_memo 
       = PendingIntent.getActivity(context, 0, intent_memo, 0);
item.setOnClickPendingIntent(R.id.schedule_item, pendingIntent_memo);

참고자료

Android APIs : Intent

Intent Structure

  • action -- The general action to be performed, such as ACTION_VIEW, ACTION_EDIT, ACTION_MAIN, etc.
  • data -- The data to operate on, such as a person record in the contacts database, expressed as a Uri.
    연산대상, Uri 로 표현되는, 연락처DB의 개인 정보같은 것들.

인텐트의 2차 속성(secondary attributes)

  • category -- Gives additional information about the action to execute. For example, CATEGORY_LAUNCHER means it should appear in the Launcher as a top-level application, while CATEGORY_ALTERNATIVE means it should be included in a list of alternative actions the user can perform on a piece of data.
  • type -- Specifies an explicit type (a MIME type) of the intent data. Normally the type is inferred from the data itself. By setting this attribute, you disable that evaluation and force an explicit type.
  • component -- Specifies an explicit name of a component class to use for the intent. Normally this is determined by looking at the other information in the intent (the action, data/type, and categories) and matching that with a component that can handle it. If this attribute is set then none of the evaluation is performed, and this component is used exactly as is. By specifying this attribute, all of the other Intent attributes become optional.
  • extras -- This is a Bundle of any additional information. This can be used to provide extended information to the component. For example, if we have a action to send an e-mail message, we could also include extra pieces of data here to supply a subject, body, etc.
    기타 추가적인 정보의 번들이다. 이것은 확장된 정보를 컴포넌트에게 주는데 사용할 수 있다. 예를 들어, 액션이 이메일 메시지를 보내려한다면, 여기에 제목, 내용등을 추가해 포함시킬 수 있다.
댓글