Java 如何修复我的应用程序?
我的照相应用程序有一个问题,当我拍照时,我可以在imageview中看到它,但当我打开手机或关闭应用程序并重新打开时,图像消失了 我的代码->Java 如何修复我的应用程序?,java,android,camera,Java,Android,Camera,我的照相应用程序有一个问题,当我拍照时,我可以在imageview中看到它,但当我打开手机或关闭应用程序并重新打开时,图像消失了 我的代码-> public class semana1 extends Activity { Button btnfoto1; ImageView imgs1; static final int CAM_REQUEST=1; @Override protected void onCreate(Bundle savedInst
public class semana1 extends Activity {
Button btnfoto1;
ImageView imgs1;
static final int CAM_REQUEST=1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.semana1);
btnfoto1= (Button) findViewById(R.id.btnfoto1);
imgs1= (ImageView) findViewById(R.id.imgs1);
btnfoto1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent int1=new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
File file=getfile();
int1.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file));
startActivityForResult(int1,CAM_REQUEST);
}
});
}
private File getFile()
{
File folder=new File("sdcard/Progress");
if(!folder.exists())
{
folder.mkdir();
}
File image_file=new File(folder,"image1.jpg");
return image_file;
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
String path = "sdcard/Progress/image1.jpg";
imgs1.setImageDrawable(Drawable.createFromPath(path));
}
}
阅读应用程序的最新版本
现在给你指出一个正确的方向。当您关闭应用程序时,系统会停止该应用程序,并可能稍后将其杀死。你的图像消失的原因是因为你还没有为你的应用程序实现一种方法来保存它之前的状态
因此,您可能应该实施:
public void onStop() {
super.onStop();
// code where you tell the app to save the image
}
public void onDestroy() {
super.onDestroy();
// code where you tell the app to save the image
}
你到底做了什么来验证行为和诊断它。@JoxTraex当我使用我的应用程序并打开phne时,图像消失了,但我可以在我的文件中看到它。