Android: startActivityForResult to go in second acitivity and save data in sqlite
<p>the data storage doesn't seem to work in my case.
I read a lot in forums but couldn't find any answer to it.
So here goes my issue:</p>

<p>I have an Activity called MainActivity that starts a second Activity
named VertragHinzufuegen. This class allows entering some user data and
confirm them with a button. The button has an onClickListener
with which I want to save all data in SQL. But these data don't appear in my list :(</p>

<p><strong>MainActivity.java</strong></p>

<pre><code>
private void createAgreement() {
     Intent i = new Intent(this, VertragHinzufuegen.class);
     startActivityForResult(i, ACTIVITY_CREATE);
    }

@Override
    protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
        super.onActivityResult(requestCode, resultCode, intent);
    }
</code></pre>

<p><strong>VertragHinzufuegen.java</strong></p>

<pre><code>
mConfirmButton.setOnClickListener(new View.OnClickListener() {
         public void onClick(View view) {
          Log.d(TAG, "mConfirmButton clicked");

          // Progress circle for loading
          ProgressDialog pdialog = ProgressDialog.show(VertragHinzufuegen.this, "", "Lade. Bitte warten...", true);
          pdialog.show();

          // TODO:
          // Here happens the magic of data storage :)          
          mDbHelper.addAgreement("Testcontract","null","null","null","null");

          // Send callback
             setResult(RESULT_OK);
             finish();
         }
        });
</code></pre>

<hr>

<p><strong>UPDATE:</strong></p>

<p>Well, that is the point.</p>

<p>Besides the MainActivity class and the VertragHinzufuegen class
there exists the class VertraegeListe. The MainActivity contains
a TabHost which includes VertraegeListe as intent.
And the population of the list is in the class VertraegeListe,
so I canÄt call the population method in MainActivity.</p>

<p><strong>VertraegeListe.java</strong></p>

<pre><code>
private void fillData() {
        // Build adapter with agreement entries; Populate the agreement list
        Cursor cursor = mDbHelper.getAllAgreements();
        String[] fields = new String[] {
                mDbHelper.KEY_AGREEMENTNAME
        };
        SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, R.layout.vertraege_datensatz, cursor,
                fields, new int[] {R.id.agreementEntryText});
        mAgreementList.setAdapter(adapter);
    }
</code></pre>

<p>MainActivity -includes-> VertraegeListe -includes-> fillData()</p>

<p>Any idea?</p>

<hr>

<p><strong>UPDATE 2:</strong></p>

<p>How do I have to redefine my originally rawQuery??? I don't get it:</p>

<p><strong>VertraegeDBAdapter.java</strong></p>

<p><pre><code>
// Get all data from the table vertraege
 public Cursor getAllAgreements() {
  // Entity attributes
  String attributes = "t1._id,"
        + "t1._idvertragspartner,"
        + "t1._idvertragsart,"
        + "t1.kundennummer,"
        + "t1.vertragsname,"
        + "t1.startdatum,"
        + "t1.enddatum,"
        + "t1.kuendigungsfristdatum,"
        + "t1.kuendigungserinnerung,"
        + "t2._id,"
        + "t2.vertragspartnername,"
        + "t2.vertragspartnerkontaktperson,"
           + "t2.anschrift,"
           + "t2.postleitzahl,"
           + "t2.ort,"
           + "t2.email,"
           + "t2.festnetznummer,"
           + "t2.faxnummer,"
           + "t2.url,"
           + "t3._id,"
           + "t3.vertragsartname";</p>

<p>// Entities
  String tables = DATABASE_TABLE_AGREEMENTS+" t1, "
        + DATABASE_TABLE_AGREEMENTPARTNER+" t2, "
        + DATABASE_TABLE_AGREEMENTTYPES+" t3";</p>

<p>// Where clause
  String whereclause = "t2._id = t1._idvertragspartner AND t3._id = t1._idvertragsart";</p>

<p>// The entire structured query language statement
  String sqlstatement = "SELECT "+attributes+" FROM "+tables+" WHERE "+whereclause; </p>

<p>// rawQuery(String sql, String selectionArgs)
  return mDb.rawQuery(sqlstatement, null);
 }
</pre></code></p>

<p>The refreshing method I have rewritten as follows:</p>

<p><strong>VertraegeListe.java</strong></p>

<pre><code>
/**
     * Get agreements from database and project records on list
     */
    private void fillData() {
         // Get all of the rows from the database and create the item list
        Cursor mAgreementsCursor = mDbHelper.getAllAgreements();
        startManagingCursor(mAgreementsCursor);

        // Create an array to specify the fields we want to display in the list (only TITLE)
        String[] from = new String[]{mDbHelper.KEY_AGREEMENTNAME};

        // and an array of the fields we want to bind those fields to (in this case just agreementEntryText)
        int[] to = new int[]{R.id.agreementEntryText};

        // Now create a simple cursor adapter and set it to display
        SimpleCursorAdapter agreementsAdapter = 
                new SimpleCursorAdapter(this, R.layout.vertraege_datensatz, mAgreementsCursor, from, to);
        mAgreementList.setAdapter(agreementsAdapter);
    }
</code></pre>
