android不同的区间变量

时间:2012-11-09 02:48:58

标签: android variables broadcast

如何获取广播方法变量?

广播中只有一个变量。这是我的代码部分:

public void onCreate(Bundle savedInstanceState) {  
       super.onCreate(savedInstanceState);  
       setContentView(R.layout.main);  
       //I want to use a in here like textview.settext(a);
             IntentFilter intent = new IntentFilter();  
             registerReceiver(searchDevices, intent);
     }  
     private BroadcastReceiver searchDevices = new BroadcastReceiver() {      
     public void onReceive(Context context,  Intent intent) {  
               int a=0;
      }
     }

1 个答案:

答案 0 :(得分:1)

您可以将parcelable变量放入Intent实例:

Intent i = new intent();
i.putExtra("a", 0);

然后在您的接收器代码中获得值:

int a = i.getIntExtra("a");

This document might be helpful.