H.P.
My son is in 3rd grade. Starting several years ago when he first had homework we had this problem of when to do it and the battle over when (not an issue of refusing to listen but definitely some push-back around timing if I said to do it right away or if not right away then getting him to stop what he was doing to do it.)
So the solution has been to put the decision of timing in his hands (not doing it has never been an option or issue, just the when). I recognize that he needs some downtime when he gets home from school. I did too way back when. I was allowed to play all afternoon and I did my homework after dinner (although I don't think I had as much at this age as he does).
As soon as we get home from the bus I ask him when he's going to do it and we set a timer. Some days he'll say 10 minutes, some days 20, some 45. He can spend that time relaxing, having a snack, whatever he wants, but when the timer goes off, it's homework time, no stalling, no arguing, no ifs, ands, or buts.
If there's something going on that day (sports practice, etc.) that limits the time available I'll remind him of that and the time he gets will be on the lower side, but still at least a little down time with a definite end.
I think it really helped giving him some choice in the matter, but also giving a strict rule that when the timer goes, it has to be done.