ImageViewに表示される(そして内部でさらにいくつかの作業を行う)写真をキャプチャするアプリケーションがあります。
カメラを開いたときに問題が発生し、写真をキャプチャした後、保存と破棄のオプションが表示されます。保存ボタンをクリックすると、カメラモードに戻ります。
電話のメモリをクリーンアップする場合(タスクマネージャ->> RAM->>メモリのクリア)、この問題は発生しません。
問題は、十分なメモリがない場合にカメラインテントが結果を出さないことです。しかし、通常のカメラを開くと、写真がキャプチャされます。
この問題をどのように解決するか。1つの解決策は、アプリケーションを起動する前にメモリをクリーンアップするたびにここにあります。
しかし、これは正しい方法ではありません。なぜなら、私が私のアプリケーションを一般の人々に紹介するとき、彼らはこれらのことをしないからです。
今、私はここで何をする必要がありますか?
アプリケーションでメモリをクリーンアップする方法はありますか?アプリケーションで使用されている最小メモリまたは最大メモリを知る方法。それで、最初に私のアプリケーションチェックは、そこに、それだけのメモリが利用可能かどうかを確認します。利用可能な場合は続行し、そうでない場合は、メモリをクリーンアップ(または一部のアプリケーションをアンインストール)するようにユーザーに指示します。
アプリケーションで次のコードを使用しています。
レイアウト->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:text="@string/photo"
/>
<ImageView
android:id="@+id/image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/button1"
android:contentDescription="@string/image"/>
</RelativeLayout>
アクティビティ->>
public class TestCameraActivity extends Activity {
private Button button;
private ImageView imageView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test_camera);
button = (Button) findViewById(R.id.button1);
imageView = (ImageView) findViewById(R.id.image);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, 100);
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 100) {
Bitmap bitmap = (Bitmap) data.getExtras().get("data");
imageView.setImageBitmap(bitmap);
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_test_camera, menu);
return true;
}
}