Step 5

Get rid of the Bundle creation and Bundle value settings from the onClick() handler method. The Activity no longer needs to return any extra information to the caller. And because we no longer have an Intent to return, we'll use the shorter version of setResult() :

public void onClick(View view) { setResult(RESULT_OK); finish();

We will take care of storing the updates or new notes in the database ourselves, using the life-cycle methods. The whole onCreate() method should now look like this:

super.onCreate(savedlnstanceState); mDbHelper = new NotesDbAdapter(this); mDbHelper.open();

setContentView(R.layout.note edit);

mTitleText = (EditText) findViewByld(R.id.title);

mBodyText = (EditText) findViewByld(R.id.body);

Button confirmButton = (Button) findViewByld(R.id.confirm);

mRowld = savedlnstanceState != null ?

savedInstanceState.getLong(NotesDbAdapter.KEY ROWID)

Bundle extras = getIntent().getExtras();

mRowld = extras != null ? extras.getLong(NotesDbAdapter.KEY ROWID)

populateFields();

confirmButton.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { setResult(RESULT_OK); finish();

0 0

Post a comment