Fotoğraf çeken ve bitmapler olarak resim görüntülerini kaydedebilen basit bir android uygulaması yapıyorum, sorun kameranın açılmasını istediğimde sorun ekran dönüyor ve sonra tüm bitmapler yok oluyor, Ben birçok şeyi denedim ve bunlardan birikamera niyetini açarken android uygulama yönlendirmesini nasıl önleyebilirim
android: screenOrientation = "portre"
android: configChanges = "keyboardHidden | oryantasyon" Ayrıca
Ben onSaveInstanceState ama hiçbir şey eserlerini kullanarak çalıştı ,
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//Initializing Variables
settings = (Button) findViewById(R.id.Bsettings);
next = (Button) findViewById(R.id.Bnext);
takePic = (Button) findViewById(R.id.Bpic);
imageView1 = (ImageView) findViewById(R.id.IVthumbnail1);
imageView2 = (ImageView) findViewById(R.id.IVthumbnail2);
imageView3 = (ImageView) findViewById(R.id.IVthumbnail3);
// Handling event listeners
takePic.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraIntent, CAMERA_REQUEST);
}
});
settings.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (imageView1.getDrawable() != null) {
Toast.makeText(getApplicationContext(), "image is NOT null", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(getApplicationContext(), "image is null", Toast.LENGTH_SHORT).show();
}
}
});
}
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
if (imageView1.getDrawable() != null) {
bitmapDrawable = (BitmapDrawable) imageView1.getDrawable();
tempBitmap = bitmapDrawable.getBitmap();
outState.putParcelable("bitmap1", tempBitmap);
}
if (imageView2.getDrawable() != null) {
bitmapDrawable = (BitmapDrawable) imageView2.getDrawable();
tempBitmap = bitmapDrawable.getBitmap();
outState.putParcelable("bitmap2", tempBitmap);
}
if (imageView3.getDrawable() != null) {
bitmapDrawable = (BitmapDrawable) imageView3.getDrawable();
tempBitmap = bitmapDrawable.getBitmap();
outState.putParcelable("bitmap3", tempBitmap);
}
}
@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onRestoreInstanceState(savedInstanceState);
if (savedInstanceState != null) {
if (savedInstanceState.getParcelable("bitmap1") != null) {
tempBitmap = (Bitmap) savedInstanceState.getParcelable("bitmap1");
imageView1.setImageBitmap(tempBitmap);
}
if (savedInstanceState.getParcelable("bitmap2") != null) {
tempBitmap = (Bitmap) savedInstanceState.getParcelable("bitmap2");
imageView1.setImageBitmap(tempBitmap);
}
if (savedInstanceState.getParcelable("bitmap3") != null) {
tempBitmap = (Bitmap) savedInstanceState.getParcelable("bitmap3");
imageView1.setImageBitmap(tempBitmap);
}
}
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == CAMERA_REQUEST && resultCode == RESULT_OK) {
bitmap = (Bitmap) data.getExtras().get("data");
if (imageView1.getDrawable() == null) {
System.out.println("1");
imageView1.setImageBitmap(bitmap);
} else if (imageView1.getDrawable() != null && imageView2.getDrawable() == null) {
System.out.println("2");
bitmapDrawable = (BitmapDrawable) imageView1.getDrawable();
tempBitmap = bitmapDrawable.getBitmap();
imageView2.setImageBitmap(tempBitmap);
imageView1.setImageBitmap(bitmap);
} else {
System.out.println("3");
bitmapDrawable = (BitmapDrawable) imageView2.getDrawable();
tempBitmap = bitmapDrawable.getBitmap();
imageView3.setImageBitmap(tempBitmap);
bitmapDrawable = (BitmapDrawable) imageView1.getDrawable();
tempBitmap = bitmapDrawable.getBitmap();
imageView2.setImageBitmap(tempBitmap);
imageView1.setImageBitmap(bitmap);
}
bitmap = null;
tempBitmap = null;
bitmapDrawable = null;
// CALL THIS METHOD TO GET THE URI FROM THE BITMAP
// bitmapUri = getImageUri(getApplicationContext(), bitmap);
// CALL THIS METHOD TO GET THE ACTUAL PATH
// bitmapPath = new File(getRealPathFromURI(bitmapUri));
}
}
}
Teşekkür: İşte benim kodudur.
Yönlendirme değişikliklerini engellemeye çalışmayın. Bunun yerine, ilerlemenizi bir veritabanına veya başka bir depolama alanına kaydetmelisiniz. Böylece, uygulamanız bir yapılandırma değişikliğine sahip olduğunda, kaldığı yerden devam edebilir. –
"onSavedInstanceState" kullanıyorum ama çalışmıyor. – MuhammadNe