বাংলায় অ্যান্ড্রয়েড সহায়িকা - Bangla Android Guide

প্রিভিউ বন্ধ করুন এবং ক্যামেরা রিলিজ (ছেড়ে দেয়া) করুন

একসময় আপনার অ্যাপলিকেশন ক্যামেরা ব্যবহার করা শেষ করবে, এটা এখন পরিষ্কার করার সময়। বিশেষ করে, আপনাকে অবশ্যই Camera অবজেক্ট রিলিজ করতে হবে, অথবা আপনি অন্য অ্যাপলিকেশন ক্র্যাশ করার ঝুকি নিবেন, যার মধ্যে আপনার নিজস্ব অ্যাপলিকেশনের নতুন ইনসটেন্স রয়েছে।

আপনাকে কখন প্রিভিউ বন্ধ এবং ক্যামেরা রিলিজ করতে হবে ? আপনার প্রিভিউ সারফেস ধ্বংস হওয়া একটি ভালো নিদর্শন যে প্রিভিউ বন্ধ এবং ক্যামেরা রিলিজ করতে এটাই উপযুক্ত সময়,Preview ক্লাস থেকে এই মেথডের মধ্যে যে ভাবে দেখানো হয়েছে।

public void surfaceDestroyed(SurfaceHolder holder) {
    // Surface will be destroyed when we return, so stop the preview.
    if (mCamera != null) {
        /*
          Call stopPreview() to stop updating the preview surface.
        */
        mCamera.stopPreview();
    }
}

/**
  * When this function returns, mCamera will be null.
  */
private void stopPreviewAndFreeCamera() {

    if (mCamera != null) {
        /*
          Call stopPreview() to stop updating the preview surface.
        */
        mCamera.stopPreview();

        /*
          Important: Call release() to release the camera for use by other applications.
          Applications should release the camera immediately in onPause() (and re-open() it in
          onResume()).
        */
        mCamera.release();

        mCamera = null;
    }
}

এই অনুশীলনীর প্রথম দিকে, এই প্রক্রিয়াও setCamera() এর একটি অংশ ছিল, তাই একটি ক্যামেরা শুরু করাটা সবসময় প্রিভিউ বন্ধ করার মাধ্যমে শুরু হয়।