I have an activity that passes updated information from my EditBook
activity to my MainActivity
via an Intent.
Button for EditBook
:
FloatingActionButton fab = findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String title = mTitle.getText().toString();
String author = mAuthor.getText().toString();
String publisher = mPublisher.getText().toString();
Intent replyIntent = new Intent();
replyIntent.putExtra(EXTRA_ID, getIntent().getIntExtra(EXTRA_ID, -1));
replyIntent.putExtra(EXTRA_TITLE, title);
replyIntent.putExtra(EXTRA_AUTHOR, author);
replyIntent.putExtra(EXTRA_PUBLISHER, publisher);
replyIntent.putExtra(EXTRA_ISBN, getIntent().getStringExtra(BookView.EXTRA_ISBN));
setResult(RESULT_OK, replyIntent);
finish();
}
});
And my receiving end in OnActivityResult
:
if (data.getIntExtra(EditBook.EXTRA_ID, -1) != -1) {
Book book = new Book(data.getIntExtra(EditBook.EXTRA_ID, -1), data.getStringExtra(EditBook.EXTRA_TITLE),
data.getStringExtra(EditBook.EXTRA_AUTHOR), data.getStringExtra(EditBook.EXTRA_PUBLISHER),
"1", data.getStringExtra(EditBook.EXTRA_ISBN));
try {
asyncWait = mBookViewModel.update(book);
spinner.setVisibility(View.GONE);
Toast.makeText(getApplicationContext(), R.string.book_saved, Toast.LENGTH_LONG).show();
Intent intent = getIntent();
finish();
startActivity(intent);
} catch (ExecutionException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
The asyncWait
variable simply collects the result from AsyncTask so that my UI will update.
The book I am trying to edit has a title come back as "1984 (signetClassic)". In my EditBook
activity, I change this to "1984" and click the save floating action button. When I step through the debugger, title
does show the correct title, the replyIntent
mMap shows the correct title, but when I inspect the data in the MainActivity, the title has reverted back to "1984 (signetClassic)". Any ideas why the Intent extras are changing when sent?
Let me know if there is any more information you need.