title: how to save the toggle button state in database and retrive that state
body: <p>how to save the toggle button state and retrive that state and should access in app.
  the following is my edit class in this i want to insert values and update of toggle button state.and was not saving in database and updating.</p>
  
  <pre><code>    protected void onCreate(Bundle savedInstanceState) {
  
       super.onCreate(savedInstanceState);
       setContentView(R.layout.edit_layout);
       edittext=(EditText)findViewById(R.id.device_text);
       light=(ToggleButton)findViewById(R.id.light);
       alarm=(ToggleButton)findViewById(R.id.alarm);
       db = new DataBaseAdapter(this);
       Intent i = getIntent();
           if(i.hasExtra("Dname"))
               val = i.getStringExtra("Dname");
      slight=light.getText().toString();
      salarm=alarm.getText().toString();
  //  edittext.setText(val);
      if(i.hasExtra("Daddress"))
          pos=i.getStringExtra("Daddress");
      db.open();
      db.insertData(pos,val,slight,salarm);
      c = db.getData();
      edittext.setText(val);
      db.close();
  }
  
  @Override
  public void onBackPressed(){
      db.open();
      c=db.getData();
      if (c.moveToFirst()) {
        do {
          slight=light.getText().toString();
          salarm=alarm.getText().toString();
          if(pos.equalsIgnoreCase(c.getString(c.getColumnIndex("uuid"))))
          {
                 db.updateData(pos, edittext.getText().toString(),slight,salarm);
          }
          Intent intent=new Intent();
          intent.putExtra("Dname", edittext.getText().toString());
          intent.putExtra("Daddress",pos);
          setResult(RESULT_OK, intent);
          finish();
      } while (c.moveToNext());
            }
       db.close();
       super.onBackPressed();
  }   
  </code></pre>
  
  <p>and the following is my database adapter in this i did like this for inserting and update</p>
  
  <pre><code>   public long insertData(String uuid,String devicename ,String light,String alarm ) 
     {
          ContentValues initialValues = new ContentValues();
          initialValues.put(UUID, uuid);
          initialValues.put(DEVICENAME, devicename);
          initialValues.put(LIGHT, light);
          initialValues.put(ALARM, alarm);
          return db.insert(DATABASE_TABLE, null, initialValues);
    }
  
   public long updateData(String uuid,String devicename,String light,String alarm  )
    {
      ContentValues initialValues = new ContentValues()
          initialValues.put(DEVICENAME, devicename);
      initialValues.put(LIGHT, light); 
      initialValues.put(ALARM, alarm);
      return db.update(DATABASE_TABLE, initialValues,UUID + "= ?",new String[] { uuid});
  }
  </code></pre>