private void showAddDialog(final int position) {
    closeDialog();

    DebugTool.info(mShareAppInfos.get(position).activityInfo.name);
    final ResolveInfo appInfo = mShareAppInfos.get(position);
    final String appName = appInfo.activityInfo.loadLabel(mPm) + "";

    mDialog = new CommonCallbackDialog(this, R.style.TipDialog);
    mDialog.setListener(
        new MyDialogListener() {
          @Override
          public void onClick(View view) {
            // TODO Auto-generated method stub
            switch (view.getId()) {
              case R.id.btnCancle:
                closeDialog();
                break;
              case R.id.btnSure:
                MyGameInfo myGameInfo = new MyGameInfo();
                myGameInfo.setPackageName(appInfo.activityInfo.packageName);
                myGameInfo.setLaunchAct(appInfo.activityInfo.name);
                myGameInfo.setName(appName);
                int flag = appInfo.activityInfo.applicationInfo.flags;
                if ((flag & ApplicationInfo.FLAG_SYSTEM) != 0
                    || (flag & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) != 0) {
                  myGameInfo.setState(Constant.GAME_STATE_INSTALLED_SYSTEM);
                } else {
                  myGameInfo.setState(Constant.GAME_STATE_INSTALLED_USER);
                }
                long id = PersistentSynUtils.addModel(myGameInfo);
                if (id != -1) {
                  myGameInfo.setId(id + "");
                  myGameInfo.setGameId((-id) + "");
                  PersistentSynUtils.update(myGameInfo);

                  mShareAppInfos.remove(position);
                  mAdapter.notifyDataSetChanged();

                  FileDownInfo fileDownInfo = new FileDownInfo();
                  fileDownInfo.setFileId(myGameInfo.getGameId());
                  fileDownInfo.setObject(myGameInfo);
                  Intent downIntent = new Intent(DownloadTask.ACTION_ON_DOWNLOAD_WAIT);
                  downIntent.putExtra(DownloadTask.FILE_DOWN_INFO_KEY, fileDownInfo);
                  sendBroadcast(downIntent);

                  showToast(appName + " " + getText(R.string.manage_add_success));
                } else {
                  showToast(appName + " " + getText(R.string.manage_add_fail));
                }

                closeDialog();
                break;
            }
          }
        });
    mDialog.setTitle(getText(R.string.manage_add_this_app) + "");
    mDialog.setMessage(appName);
    mDialog.show();
  }
 private void closeDialog() {
   if (mDialog != null && mDialog.isShowing()) {
     mDialog.dismiss();
     mDialog = null;
   }
 }