안드로이드 개발 질문/답변
(글 수 45,052)
프로그램의 구조는 이렇습니다.
리스트엑티비티 ----(콘텍스트메뉴선택시)--> sms, 전화걸기
이런 상태에서
sms와 전화를 건 후 백 버튼을 이용해서 리스트엑티비티로 돌아왔습니다.
이때부터 콘텍스트 메뉴가 먹통이됩니다.
에러가 나오는 것이 아니라, 길게 눌렀을 경우 메뉴가 뜨질 않습니다.
제가 어떤 실수를 한것일까요?
@Override
public void onCreateContextMenu(ContextMenu menu, View view, ContextMenuInfo menuInfo) {
AdapterView.AdapterContextMenuInfo info;
try {
info = (AdapterView.AdapterContextMenuInfo) menuInfo;
} catch (ClassCastException e) {
Log.e(MainActivity.DEBUGTAG, "bad menuInfo", e);
return;
}
UserListData uld = (UserListData)getListAdapter().getItem(info.position);
if (uld == null) return;
// Setup the menu header
menu.setHeaderTitle(uld.getID());
// Add a menu item to delete the note
menu.add(0, MENU_CONVERSATION, 0, R.string.tcmessenger_context_conversation);
menu.add(0, MENU_SHORT , 1, R.string.tcmessenger_context_sendshort);
menu.add(0, MENU_SMS, 2, R.string.tcmessenger_context_sendmsg);
menu.add(0, MENU_CALL, 3, R.string.tcmessenger_context_call);
menu.add(0, MENU_CLOSE, 4, R.string.tcmessenger_context_close);
}
@Override
public boolean onContextItemSelected(MenuItem item) {
AdapterView.AdapterContextMenuInfo info;
try {
info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
} catch (ClassCastException e) {
Log.e(MainActivity.DEBUGTAG, "bad menuInfo", e);
return false;
}
UserListData uld = (UserListData)getListAdapter().getItem(info.position);
if (uld == null) return false;
// Setup the menu header
switch (item.getItemId()) {
case MENU_SMS: {
Intent sendIntent = new Intent(Intent.ACTION_VIEW );
sendIntent.putExtra("address", uld.getHP());
sendIntent.putExtra("sms_body", "The SMS text");
sendIntent.setType("vnd.android-dir/mms-sms");
startActivity(sendIntent);
return true;
}
case MENU_CALL: {
Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + uld.getHP()));
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
return true;
}
case MENU_CLOSE: {
return true;
}
}
return false;
}
리스트엑티비티 ----(콘텍스트메뉴선택시)--> sms, 전화걸기
이런 상태에서
sms와 전화를 건 후 백 버튼을 이용해서 리스트엑티비티로 돌아왔습니다.
이때부터 콘텍스트 메뉴가 먹통이됩니다.
에러가 나오는 것이 아니라, 길게 눌렀을 경우 메뉴가 뜨질 않습니다.
제가 어떤 실수를 한것일까요?
@Override
public void onCreateContextMenu(ContextMenu menu, View view, ContextMenuInfo menuInfo) {
AdapterView.AdapterContextMenuInfo info;
try {
info = (AdapterView.AdapterContextMenuInfo) menuInfo;
} catch (ClassCastException e) {
Log.e(MainActivity.DEBUGTAG, "bad menuInfo", e);
return;
}
UserListData uld = (UserListData)getListAdapter().getItem(info.position);
if (uld == null) return;
// Setup the menu header
menu.setHeaderTitle(uld.getID());
// Add a menu item to delete the note
menu.add(0, MENU_CONVERSATION, 0, R.string.tcmessenger_context_conversation);
menu.add(0, MENU_SHORT , 1, R.string.tcmessenger_context_sendshort);
menu.add(0, MENU_SMS, 2, R.string.tcmessenger_context_sendmsg);
menu.add(0, MENU_CALL, 3, R.string.tcmessenger_context_call);
menu.add(0, MENU_CLOSE, 4, R.string.tcmessenger_context_close);
}
@Override
public boolean onContextItemSelected(MenuItem item) {
AdapterView.AdapterContextMenuInfo info;
try {
info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
} catch (ClassCastException e) {
Log.e(MainActivity.DEBUGTAG, "bad menuInfo", e);
return false;
}
UserListData uld = (UserListData)getListAdapter().getItem(info.position);
if (uld == null) return false;
// Setup the menu header
switch (item.getItemId()) {
case MENU_SMS: {
Intent sendIntent = new Intent(Intent.ACTION_VIEW );
sendIntent.putExtra("address", uld.getHP());
sendIntent.putExtra("sms_body", "The SMS text");
sendIntent.setType("vnd.android-dir/mms-sms");
startActivity(sendIntent);
return true;
}
case MENU_CALL: {
Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + uld.getHP()));
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
return true;
}
case MENU_CLOSE: {
return true;
}
}
return false;
}