如何从首选项开始广播到Activity

时间:2013-06-20 12:39:01

标签: android broadcastreceiver

如何将prefrenceActivity中的广播发送到用于重置其他活动数据的Activity.prefrenceActivity。

在prefrenceActivity中,有一个偏好,当用户点击它时会打开一个警告框。如果选择是,那么我想开始广播。

接收广播的活动代码

 private BroadcastReceiver objResettedReceiver=new BroadcastReceiver() {

    @Override
    public void onReceive(Context context, Intent intent) {
        // TODO Auto-generated method stub
        System.out.println(" broadCast receiver.      .      "+intent);

         inc = 0;
         initObjects();

    }
};

在简历上注册广播

     IntentFilter localIntentFilter2 = new IntentFilter(SettingsActivity.broadcastAction);
     this.registerReceiver(this.objResettedReceiver, localIntentFilter2);

unregiseter暂停&销毁活动

protected void onPause() {
    // TODO Auto-generated method stub
    unregisterReceiver(objResettedReceiver);
    super.onPause();

}


   protected void onDestroy() {
    // TODO Auto-generated method stub
    unregisterReceiver(objResettedReceiver);
    super.onDestroy();

    System.out.println("hi.. Activity Destroy.......");
}

开始播放

  Intent intent = new Intent();
  intent.setAction(broadcastAction);
  sendBroadcast(intent);

0 个答案:

没有答案