0

Although I was able to accomplish this task but in opinion the approach is not good,Since am creating instance of the Activity inside Broadcast Receiver. Is there any better way to accomplish it?

@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);
        }

    }
    }
Kara
  • 6,115
  • 16
  • 50
  • 57
  • What exactly do you wanna do? Do you want to start a new `MainActivity`? Or do you want to send a value to an already opened `MainActivity`? What does `MainActivity.instance()` do? Is it returning the currently active instance? Or does it create a new one? You need to be a bit more precise with your question. – SimonSays Apr 02 '14 at 17:25
  • 2
    You should be using BroadcastReceiver inside your activity, look at http://stackoverflow.com/a/14648933/1039535 for implementation – Varun Oberoi Apr 02 '14 at 17:26
  • yes mainActivity is already opened and it cretes a new instance of MainActiviy – user257499 Apr 02 '14 at 17:37

0 Answers0