BroadcastReceiver接收时不应该

时间:2015-11-21 22:52:34

标签: android broadcastreceiver

各位大家好,并提前致谢。

我使用BroadcastReceiver从另一个活动的对话框接收数据。此对话框包含正面和负面按钮代码。这是......

                inflador = li.inflate(R.layout.dialogo_estandar, null);

            MensajeDialogoTV = (TextView) inflador.findViewById(R.id.dialogoEstandarTV);
            MensajeDialogoTV.setTextSize(tamanoTexto);
            MensajeDialogoTV.setText(miActividad.getResources().getString(R.string.ac_dialogos_06));

            ventana = new AlertDialog.Builder(miActividad);
            ventana.setIcon(R.drawable.icono_info);
            ventana.setTitle(miActividad.getResources().getString(R.string.ac_dialogos_05));
            ventana.setView(inflador);

            ventana.setPositiveButton(miActividad.getResources().getString(R.string.estandar_SI), new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int boton) {
                    finish();
                    miActividad.finish();
                }
            });

            ventana.setNegativeButton(miActividad.getResources().getString(R.string.estandar_NO), new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int boton) {

                    Intent RTReturn = new Intent(PrincipalActivity.BROADCAST_REINICIA_CRONO);
                    LocalBroadcastManager.getInstance(miActividad).sendBroadcast(RTReturn);
                }
            });

            return ventana.create();

然后,在调用活动PrincipalActivity.java中,我有这样的接收器......

    int PASOS_POR_EL_RECEIVER = 1;
static final String BROADCAST_REINICIA_CRONO = "REINICIA_CRONO_BROADCAST";

private BroadcastReceiver broadcastReceiver = new BroadcastReceiver()
{
    @Override
    public void onReceive(Context context, Intent intent)
    {
        if(intent.getAction().equals(BROADCAST_REINICIA_CRONO))
        {
                Log.e("TONI-LOG", "PASANDO POR EL RECEIVER " + PASOS_POR_EL_RECEIVER++ + " VECES.");

                broadcastManager.unregisterReceiver(broadcastReceiver);
        }
    }
};

我从这个活动中调用对话框就像这样...

            broadcastManager.registerReceiver(broadcastReceiver, intentFilter);

        Dialogos Dialog = new Dialogos();
        Dialog.Dialogo1(this, DIALOGO_INTERRUMPIR_TEST, TamanoTexto1, 0, null, tipoDispositivo);

每次执行通过接收器时,日志行都会递增一个计数器,但“奇怪”的是,在Android Studio中观看日志,即使我触摸对话框上的正按钮也会显示该行,具有没有“sendbroadcast”行。

有人能告诉我为什么会这样吗?

再次感谢!!!

0 个答案:

没有答案