2014-05-20 175 views
0

我有一個擴展對話框的類,它包含一個用於Pincode的Edittext,我已經註冊了一個全局廣播來接收短信並解析它,然後從消息中獲得Pincode我再派本地廣播用下面的代碼當我收到短信時,本地廣播接收器播出

Intent broadcast = new Intent(); 
broadcast.setAction(SMS_RECEIVED); 
intent.putExtra(SMS_PIN_CODE,msgBody.substring(msgBody.length() - SMS_PIN_CODE_LENGTH)); 
mContext.sendBroadcast(broadcast); 

,然後在我的對話框類我創建廣播接收器收聽(SMS_RECEIVED),並把價值到用戶界面如下

private BroadcastReceiver     mPinCodeReceived = new BroadcastReceiver() { 

     @Override 
     public void onReceive(Context context, Intent intent) { 

      Toast.makeText(mContext, "I'm Here", Toast.LENGTH_SHORT).show(); 
      if (mPincodeEdittext != null) { 

       String pinCode = intent 
         .getStringExtra(BillingConstatnts.SMS_PIN_CODE); 
       mPincodeEdittext.setText(pinCode); 
      } 
     } 
    }; 

和我已經在onCreat上註冊過這個廣播對話框類

LocalBroadcastManager.getInstance(mContext).registerReceiver(mPinCodeReceived,new IntentFilter(SMS_RECEIVED)); 

現在我的本地廣播的onReceive方法不叫問題的E法,所以任何人都可以請告訴我,如果什麼問題嗎?

回答

0

好的,這裏是我在做消息時更新我的​​UI。我從我的服務思想中得到一個廣播,但這不應該是一個概率。

onResume(){ 
      registerReceiver(broadcastBufferReceiver, new IntentFilter(BackgroundActivity.BROADCAST_BUFFER_SEND_CODE)); 

    } 

// set up broadcast receiver 
    private BroadcastReceiver broadcastBufferReceiver = new BroadcastReceiver() { 
     @Override 
     public void onReceive(Context context, Intent bufferIntent) { 
      SendCode.this.LoadMessages(alarmNumber); 
     } 
    }; 
+0

不,我已經收到了短信和解析它,我要讓是否顯示它在我的課的,使用本地廣播繼承對話框的UI –

+0

從的onCreate刪除您的註冊,並把它添加到的onResume什麼。試試 –

+0

我的班級延長Dialog類,它沒有onResume方法 –