-2

(I'm not newbie!, and memory was sufficient.)

I'm working on android ICS(SDK 4.0) and a i got weird activity lifecycle when i call startActivityResult.

the prior one destroys everytime!!

When another activity is called and came to front and overlap, then everytime overlapped activity - the behind one - destroys, not so much being seen in gingerbread(2.3.3).

The log below is just program that Activity1 calls Activity 2, and simply returns result when back key pressed in Activity 2. intent has not any flag. Here's my modified log..

Left is when runned in ICS(Gal Nex), right is when runned in Gingerbread(Nex one)

Log when runned in GingerBread
-------
 - Start ActivityStackTest1 and launched ActivityStackTest2 immediately.

_ActivityStackTest1 _ onCreate_called..

_ActivityStackTest1 _ onCreate_calling new activity.. - starting activity for result

_ActivityStackTest1 _ onStart_called..

_ActivityStackTest1 _ onResume_called..

_ActivityStackTest1 _ onSaveInstanceState_called..

_ActivityStackTest1 _ onPause_called..

_ActivityStackTest2 _ onCreate_rendering..

_ActivityStackTest2 _ onCreate_got str - PASSED INTENT STRING

_ActivityStackTest2 _ onStart_called..

_ActivityStackTest2 _ onResume_called..

_ActivityStackTest1 _ onStop_called..



 - Pressed Back Key and returned to ActivityStackTest1.

_ActivityStackTest2 _ onPause_called..

_ActivityStackTest1 _ onActivityResult_returned somehow.

_ActivityStackTest1 _ onStart_called..

_ActivityStackTest1 _ onResume_called..

_ActivityStackTest2 _ onStop_called..






Log when runned in IcecreamSandwich
=======

  - Start ActivityStackTest1 and launched ActivityStackTest2 immediately.

_ActivityStackTest1 _ onCreate_called..

_ActivityStackTest1 _ onCreate_calling new activity.. - starting activity for result

_ActivityStackTest1 _ onStart_called..

_ActivityStackTest1 _ onResume_called..

_ActivityStackTest1 _ onSaveInstanceState_called..

_ActivityStackTest1 _ onPause_called..

_ActivityStackTest2 _ onCreate_rendering..

_ActivityStackTest2 _ onCreate_got str - PASSED INTENT STRING

_ActivityStackTest2 _ onStart_called..

_ActivityStackTest2 _ onResume_called..

_ActivityStackTest1 _ onStop_called..

**_ActivityStackTest1 _ onDestroy_called..** <- ???




 - Pressed Back Key and returned to ActivityStackTest1.


_ActivityStackTest2 _ onPause_called..

_ActivityStackTest1 _ onCreate_called..

_ActivityStackTest1 _ onCreate_calling new activity.. - starting activity for result

_ActivityStackTest1 _ onStart_called..

_ActivityStackTest1 _ onActivityResult_returned somehow.

_ActivityStackTest1 _ onResume_called..

_ActivityStackTest1 _ onSaveInstanceState_called..

_ActivityStackTest1 _ onPause_called..

_ActivityStackTest1 _ onStop_called..

_ActivityStackTest1 _ onDestroy_called..

Am i thinking something wrong? Isn't the previous activity supposed to wait until child activity finishes, not finishing itself?

Is theree any issue that changed lifecycle after ICS? pleace notice me when you got any idea of it, it's headachin very much..

add -- my code is belw here.. if needed.

Act1 package kr.bos.Subclasses;

import kr.bos.Framework.BaseActivity;
import kr.bos.Framework.Logger;
import android.content.Intent;
import android.content.res.Configuration;
import android.os.Bundle;

public class ActivityStackTest1 extends BaseActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Logger.e("called..");

        if(!mOptionA) {
            Logger.i("calling new activity.. - starting activity for result");
            Intent intent = new Intent(this,ActivityStackTest2.class);
            intent.putExtra("STRING", "PASSED INTENT STRING");
            startActivityForResult(intent , 0);
        }
    }

    @Override protected void onStart() {
        // FIXME Auto-generated method stub
        super.onStart();
        Logger.e("called..");
    }

    @Override protected void onResume() {
        // FIXME Auto-generated method stub
        super.onResume();
        Logger.e("called..");
    }

    @Override protected void onPause() {
        super.onPause();
        Logger.e("called..");
    }

    @Override protected void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        Logger.e("called..");
    }

    @Override protected void onStop() {
        // FIXME Auto-generated method stub
        super.onStop();
        Logger.e("called..");
    }

    @Override protected void onDestroy() {
        // FIXME Auto-generated method stub
        super.onDestroy();
        Logger.e("called..");
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode,
            Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        Logger.i("returned somehow.");
    }

    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
        Logger.i("on configuration change");
    }
}

Act2 package kr.bos.Subclasses;

import kr.bos.Framework.BaseActivity;
import kr.bos.Framework.Logger;
import android.content.res.Configuration;
import android.os.Bundle;

public class ActivityStackTest2 extends BaseActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Logger.i("rendering..");

        String strget = getIntent().getStringExtra("STRING");
        Logger.i("got str - "+strget);
    }


    @Override protected void onStart() {
        // FIXME Auto-generated method stub
        super.onStart();
        Logger.e("called..");
    }

    @Override protected void onResume() {
        // FIXME Auto-generated method stub
        super.onResume();
        Logger.e("called..");
    }

    @Override protected void onPause() {
        super.onPause();
        Logger.e("called..");
    }

    @Override protected void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        Logger.e("called..");
    }

    @Override protected void onStop() {
        // FIXME Auto-generated method stub
        super.onStop();
        Logger.e("called..");
    }

    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
        Logger.i("on configuration change");
    }

    @Override
    public void onBackPressed() {
        setResult(0);
        super.onBackPressed();
    }
}
AakashM
  • 62,551
  • 17
  • 151
  • 186
minimanimo
  • 185
  • 3
  • 11

2 Answers2

5

Solved. make sure "Option - Dev - Don't keep activities" unchecked. unless, all the activity proecdure you made will operate strange.

check related issues http://androidforums.com/verizon-galaxy-nexus/482038-dont-keep-activities-box.html http://forum.xda-developers.com/showthread.php?t=1365748

minimanimo
  • 185
  • 3
  • 11
2

No one has ever said that this will not happen. onActivityResult() is the only promise!

Vikram Bodicherla
  • 7,133
  • 4
  • 28
  • 34
  • oh god. is it? then what do you think can maintain the previopus one survive...?? – minimanimo Jan 19 '12 at 09:17
  • 1
    @mylifeforIU I don't think we can do anything to make it survive. Even if you put in a hack here and somehow make it survive, the system can always kill it if it runs into low memory conditions. I'd advise that you alter your design to allow for this. – Vikram Bodicherla Jan 19 '12 at 09:27
  • Please accept if you are convinced. – Vikram Bodicherla Jan 19 '12 at 15:29
  • Too much too late. sorry i was leavin office. The problem is that this happens ALL THE TIME with no exceptional case.. and suppose it not because of memory prob. You at least confirmed me that 'onActivityResult' can always assure that beforehand activity will servive. that really helped.Let me config it out 8h later. thanks anyway. it broke my bias perception at all. thnx Vikram. – minimanimo Jan 19 '12 at 16:08