Motorola Milestone 上的图像捕获问题

发布于 2024-10-19 15:06:26 字数 1592 浏览 6 评论 0原文

下面是简单的代码片段来说明问题。
为什么“onActivityResult”方法中记录的“tag”字段的值不是“tag_modified”?
我也尝试过其他异步调用“startActivityForResult”,但不存在这样的问题。
该问题仅出现在我的 Moto Milestone 上,但在 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;
                }
        }
}

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

卸妝后依然美 2024-10-26 15:06:26

我发现了......

一些Android操作系统杀死调用Activity的快照以避免内存相关的异常。
因此,我必须通过 onSaveInstanceState 方法保存所有状态,并在再次构造调用活动时检索它们。

此外,我还发现,所有存储在内存中的信息都容易被删除,就像那些Singleton对象一样。因此我必须通过一些持久存储方法进行保存,并在以后恢复它们。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文