how to send value through intent after finishing an activity
android, android-activity
Solution
You can set your custom result. Like `DELETE_ITEM`.
On your delete button do something like this :
public static int DELETE_ITEM = 1234;
Intent intent = new Intent();
intent.putExtra("ITEM_ID", YOUR ITEM ID);
setResult(DELETE_ITEM , intent);
Now on your activity result do something like this :
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
if (resultCode == DELETE_ITEM) {
// CODE TO DELETE ITEM
super.onActivityResult(requestCode, resultCode, intent);
}
}
Problem
I have an activity that shows a gridview of items. when I click in any of them, I move to another activity showing the information of the item. I also have the option to go back (gridview activity) or delete it. If I delete it, I need to refresh the gridview, so I need to send a variable saying "eey, I have deleted an item. you need to refresh". I guess I need to open the second activity with startActivityForResult, but I don't know how should I set the value. option 1 (back arrow): finishes the activity. no result back. option 2 (delete item): finishes the activity and sets a result back. Thanks in advance!