虽然我能够完成这项任务但是看来这种方法并不好,因为我在广播接收器中创建了Activity的实例。有没有更好的方法来实现它?
@Override
public void onReceive(Context context, Intent intent) {
String receivedIntent = intent.getAction();
MainActivity inst = MainActivity.instance();
setPref(context);
if(m_Accactive){
if (receivedIntent.equals(IntentManager.ACCELEROMETER_DATA_FILTER)) {
Log.d("Accel", "acc data");
recAcc = (AccelerometerClass) intent
.getSerializableExtra(Constants.ACC_DATA_KEY);
recData = recAcc;
if (inst != null) {
m_AccRate = inst.getM_AccFreq();
m_AccRetrieveTxtForm = FormatToString(recAcc);
inst.textViewSettings(inst.m_AcceleroReading, R.id.AccData,
m_AccRetrieveTxtForm);
}
}
}