But I don't understand, why was this suggested edit rejected by the community?
I'll usually reject suggested edits that change code unless there's a good reason not to. It's very easy to change the meaning of an answer unintentionally with even small code changes.
The only reason I approved your suggested edit was because:
Often when people are reviewing edits, they don't have any context other than what is in your comments on the edit. I believe yours were something like "void functions can't return a value". Without context, it's hard to know if the overridden function (OnBackPressed) should have been declared as void or bool.
You may have had similar changes accepted in the past however because some people are significantly more likely to approve an edit than reject one, so there's also an element of luck/timing involved...
If you look at the "how to edit" block shown when you suggest an edit, you will notice it shows the following points:
None of those points is about code, but somebody could argue that changing the code you are changing the answer given from somebody else.
I would generally suggest to avoid editing the code given in a post. If there is a typo in the code, I would write a comment letting the user who wrote the post know that; if the answer is suggesting using a function, and I believe there is a better function to use, I would write a comment about that.
In the case you think the code is completely wrong, or there is alternative that could be used, then you should write your own answer, rather than editing the answer given from somebody else.
This is very clearly a good edit that should have been accepted. I'm sorry for the reaction you got.
This is a textbook case of a good edit:
The rules for editing state this clearly:
This is a minor mistake being corrected. The meaning of the post isn't changed: it's just a code example that was made correct. The original author was respected: after you pointed out the problem to him in a comment, he went and made the exact same change.
I'm sorry that your valuable contribution was rejected. Sadly, this is an old problem on Stack Overflow — reviewers who reject edits in direct contradiction with the rules and core values of Stack Overflow. Please keep up the good work nonetheless.