2

I have an Android app which works fine with android 2.x but fails with Ice Cream Sandwhich.

App has Mainactivity A which starts SetupActivity B with onStartActivityForResult() when "Setup" button is clicked.

Via SetupActivity the user can start other activities for setting app settings (network connection settings, user interface settings etc.). SetupActivity starts some of those with onStartActivityForResult() and puts data about changed settings into a Intent which is returned with setResult(RESULT_OK,intent);

When SetupActivity has started some another activity C (ie. connection settings) and C has returned, the MainActivity A is created senseless amount (ie. 50) of times again (or its onCreate() is called that many times). What could be the reason for this and how should I go on about solving this? This problem only occurs with Ice Cream Sandwhich.

Code:

MainActivity:

//OnClick listeners for all the buttons and text field in the UI
public void onClick(View view) {
    //start SetupActivity
    if (view == (setup_button)){
            Intent intent = new Intent(getApplicationContext(), SetupActivity.class);
            startActivityForResult(intent, SETUP_ACTIVITY);
    }
    ...
 }

public void onActivityResult(int requestCode, int resultCode, Intent data) 
    switch(requestCode) {
        case SETUP_ACTIVITY: //returned from SetupActivity
            //check what settings have changed and update variables accordingly
        ...
    }
}

SetupActivity:

//click handler for "Measurement setup" button
public void measSetupClicked(View v) {
    Intent intent = new Intent(this, MeasurementSetupActivity.class);
    startActivityForResult(intent, MEAS_SETUP);
}


public void onActivityResult(int requestCode, int resultCode, Intent data) {
    Intent intent = new Intent();

    //try-catch omited for brevity
    if(data.hasExtra("MEAS_SETTINGS_CHANGED")) {
       intent.putExtra("MEAS_SETUP_CHANGED"),data.getExtras().getBoolean("MEAS_SETTINGS_CHANGED"));
    }

    setResult(RESULT_OK,intent);   
}

@Override
public void onBackPressed() {
    SetupActivity.this.finish();
}

public void backButtonPressed(View v) {
    SetupActivity.this.finish();
}
TZHX
  • 5,291
  • 15
  • 47
  • 56
flam
  • 21
  • 1

0 Answers0