PendingIntent 사용시 대상이 되는 Activity가 이미 실행되어 있는 경우에 

실행 중인 Activity가 업데이트 되도록 하기 위해서는 

PendingIntent send flag에 PendingIntent.FLAG_UPDATE_CURRENT를 사용하여야 하며

수신하는 Activity에서는 onNewIntent()를 override하여 전달받은 intent를 사용하면 된다.


[AlertManager.java]

    private void sendAlertMessage(){

        Intent popupIntent = new Intent(mContext, AlertMessageDialog.class);

        popupIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK

                | Intent.FLAG_ACTIVITY_CLEAR_TOP

                | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED

                | Intent.FLAG_ACTIVITY_SINGLE_TOP);

        popupIntent.putExtra(ExtraDefine.EXTRA_DATABASE_ID, mCheckItem.getDatabaseID());

        popupIntent.putExtra(ExtraDefine.EXTRA_PLAY_ALARM, true);

        popupIntent.putExtra(ExtraDefine.EXTRA_ALERT_MYADDRESS, mCheckItem.getMailAddress());

        //popupIntent.putExtras(getAlertMessageBundle());

        PendingIntent pi = PendingIntent.getActivity(mContext, 0, popupIntent, PendingIntent.FLAG_UPDATE_CURRENT);

        try{

            pi.send();

        }catch(Exception e){

            e.printStackTrace();

        }

    }


[AlertMessageDialog.java]

    @Override

    protected void onNewIntent(Intent intent) {

        Trace.d("onNewIntent");

        updateScreenFromIntent(intent);

        super.onNewIntent(intent);

    }





'programmer > android' 카테고리의 다른 글

HorizontalListView  (0) 2013.05.28
onTouch와 onTouchEvent  (0) 2013.02.18
Toast 팝업  (0) 2012.12.13
EditText bottom space  (0) 2012.12.13
android.database.StaleDataException  (0) 2012.12.12

+ Recent posts