I am developing an Android application that records audio ..
Here is my MainActivity:

```
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main); 
    }

    public void start(View v){
        Intent intent = new Intent(this,RecordService.class);
        startService(intent);
    }

    public void stop(View v){
        Intent intent = new Intent(this,RecordService.class);
        stopService(intent);
    }

}

```

and Service is

```
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;

import android.app.Service;
import android.content.Intent;
import android.media.AudioFormat;
import android.media.AudioRecord;
import android.media.MediaRecorder.AudioSource;
import android.os.IBinder;
import android.util.Log;
import android.view.View;

public class RecordService extends Service {
    AudioRecord ar;
    boolean isRecording = false;
    final int SAMPLE_RATE = 44100;
    int bufferSize;
    byte[] b;
    File f;
    OutputStream os;
    @Override
    public IBinder onBind(Intent arg0) {
        return null;
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        f = new File("ext_card/ex.pcm");
        startRecord();
        return super.onStartCommand(intent, flags, startId);
    }

    @Override
    public void onDestroy() {
        stopRecording();
        super.onDestroy();
    }

    private void startRecord(){
        bufferSize = AudioRecord.getMinBufferSize(SAMPLE_RATE, AudioFormat.CHANNEL_CONFIGURATION_DEFAULT, AudioFormat.ENCODING_PCM_16BIT);
        ar = new AudioRecord(AudioSource.DEFAULT, SAMPLE_RATE, AudioFormat.CHANNEL_CONFIGURATION_DEFAULT,AudioFormat.ENCODING_PCM_16BIT, bufferSize);
        isRecording = true;
        b = new byte[bufferSize];
                try {
                    os = new FileOutputStream(f);
                } catch (FileNotFoundException e) {
                    e.printStackTrace();
                }
                while(isRecording){
                    ar.read(b, 0, bufferSize);
                    try {
                        os.write(b);
                        Log.i("File", "Writing file");
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
                try {
                    os.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }

    }

    private void stopRecording() {
        if(isRecording){
            ar.stop();
            ar.release();
        }
    }

}

```

But my problem is when click Start button(Start button calls `start(View v)`) Application gets stuck. Any help regarding this problem would be appreciated