im new to android. i'm deveping an app to continuously save sensor's data and beside that takes photos. in fact i want to start saving accelerometer data in to a file while taking photos, or while screen is blacked out. i have reached to this point that my app saves sensor data as i touch a button, but it does it once. how can i make it to saves data continuously and without affecting other parts of my app to run? and i want it saves data while i'm taking photos in my app, when screen is blacked out, while i'm out of my app ( for example app is paused)
plz hlp thnx.
here is my code
private OnClickListener saveFun =new OnClickListener(){
    @Override
    public void onClick(View arg0) {
        // TODO Auto-generated method stub
        try { 
               File root = Environment.getExternalStorageDirectory(); 
               if (root.canWrite()){ 
                   File f = new File(root, "test.txt"); 
                   FileWriter fw;
                   if ( saveBtnCnt == 0){
                       fw = new FileWriter(f);
                       saveBtnCnt = 1;
                   }
                   else{
                       fw = new FileWriter(f,true); 
                   }
                   BufferedWriter out = new BufferedWriter(fw); 
                   c = Calendar.getInstance();
                   miliseconds = c.get(Calendar.MILLISECOND);
                   seconds = c.get(Calendar.SECOND);
                   minutes = c.get(Calendar.MINUTE);
                   hour = c.get(Calendar.HOUR);
                   day = c.get(Calendar.DAY_OF_MONTH);
                   month = c.get(Calendar.MONTH)+1;
                   year = c.get(Calendar.YEAR);
                   out.write(year+"/"+month+"/"+day
                           +"\n"+hour+":"+minutes+":"+seconds+"."+miliseconds+"\n");
                   out.write(currentX.getText()+"\n");
                   out.write(currentY.getText()+"\n");
                   out.write(currentZ.getText()+"\n");
                   out.close(); 
                   Toast.makeText(getBaseContext(), "File saved successfully!",
                Toast.LENGTH_SHORT).show();
               } 
           } catch (IOException e) { 
           }
    }
};