Motorola Milestone 上的图像捕获问题
下面是简单的代码片段来说明问题。
为什么“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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我发现了......
一些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.