A problem with image capture on Motorola Milestone

309 views Asked by At

Below is the simple code fragment to illustrate the problem.
Why the value of the field "tag" logged in method "onActivityResult" not being "tag_modified"?
I also tried others async call of "startActivityForResult", but no such problem exists.
The problem merely occurs on my Moto Milestone, but everything goes well on HTC G7.

public class HelloSnapshot extends Activity {

        private static Logger logger = Logger.getLogger(HelloSnapshot.class.getName());

        final int REQUESTCODE_SNAPSHOT = 1;

        String tag = "tag_initial";

        public void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);

                Button button = new Button(this);
                button.setText("BUTTON");
                button.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {

                                tag = "tag_modified";

                                Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                                startActivityForResult(intent, REQUESTCODE_SNAPSHOT);
                        }
                });

                setContentView(button, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
        }

        public void onActivityResult(int requestCode, int resultCode , Intent data) {
                switch (requestCode) {
                case REQUESTCODE_SNAPSHOT:
                        if (resultCode == Activity.RESULT_OK) {

                                logger.info(tag);

                        }
                        break;
                }
        }
}
1

There are 1 answers

0
Lyn On

I`ve found it out...

Some android OS kill the snapshot calling Activity to avoid memory related exception. So, I have to save all the states via method onSaveInstanceState, and retrieve them when the calling activity was constructed again.

Further more, I also found out that, all the information stored in the memory is prone to be erased, like those Singleton objects. Thus I have to do saving by some persistent storage approaches, and restore them later.