Question

Activity lifecycle is not working properly in my LG optimous device.

Whenever I called another activity and from there when I pressed back button always onCreate method is calling. This problem is only happening in LG optimous device (android 4.0.4) but in other devices it is working fine.

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action buttons
    switch (item.getItemId()) {
    case R.id.menu_cal:
        startActivity(new Intent(this, Calculator.class));
        return true;
    case R.id.menu_formula:
        startActivity(new Intent(this, Formulas.class));
        return true;
    case R.id.menu_contact:
        startActivity(new Intent(this, ContactActivity.class));
        return true;
    case R.id.menu_videos:
        startActivity(new Intent(this, VideosActivity.class));
        return true;
    case R.id.menu_settings:
        Intent intent = new Intent(getApplication(), Settings.class);
        startActivityForResult(intent, 1001);
        return true;
    default:
        return super.onOptionsItemSelected(item);
    }
}
Était-ce utile?

La solution

Check your development settings, may be the option "Don't keep activities" is enabled, that means the activity will destroy itself when it's out of view. Just disabled the option and everything will work as normal. Hope I point out the right direction.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top