Hamiltonian of a quantum field that is minimally coupled to gravity The action for the gravitational field is known as the Einstein-Hilbert action:
$$\begin{equation}
S_{G}=\int d^4 x \sqrt{|g|} R                  
\end{equation}$$
where $R$ is the Ricci scalar.
The action for a matter field that is minimally coupled to gravity is:
$$\begin{equation}
S_{matter}=\int d^4 x \sqrt{|g|} \mathcal{L_{matter}}.
\end{equation}$$
Also, we can write the total action as
$$\begin{equation}
S_{tot}=S_{G}+S_{matter}=\int d^4 x \sqrt{|g|} [R+\mathcal{L_{matter}}]~,
\end{equation}$$
which can be used to derive the Einstein's field equations by varying this action with respect to the metric.
Varying $S_{matter}$ with respect to $\phi$ will give the equation of motion of the field; varying $S_{tot}$ with respect to $\phi$ will give the same result of the equation of motion of the field, because $R$ is independent of $\phi$. However, when it comes to the Hamiltonian, the results are different. Starting from $S_{matter}$, we get 
$$\begin{equation}
H_{matter}=\int d^4 x \sqrt{|g|} [\frac{\partial\mathcal{L_{matter}}}{\partial \dot\phi}~~\dot{\phi}-\mathcal{L_{matter}}],
\end{equation}$$
however, starting from $S_{tot}$ we get
$$\begin{equation}
H_{matter}=\int d^4 x \sqrt{|g|} [\frac{\partial\mathcal{L_{matter}}}{\partial \dot\phi}~~\dot{\phi}-(\mathcal{L_{matter}}+R)],
\end{equation}$$.
The two $H_{matter}$ are different by the term $R$. So, which $H_{matter}~$  is correct?
 A: If you are only interested in the dynamics of the matter field (that is, if you can approximate gravity by a fixed background metric and ignore back-reaction), then both expressions are correct. Remember that you can always add a constant to the Hamiltonian without changing the equations of motion (Hamilton's equations). Here this constant is simply
$$
\int d^4 x \sqrt{|g|} R.
$$
Its poisson brackets with $\phi$ and $\pi = \partial \mathcal{L} / \partial \phi$ are zero, so it doesn't participate in the equations of motion.
If you are interested in the dynamics of the full matter + gravity system, then neither expression is correct — you have to add both the matter and gravity degrees of freedom in the Legendre transform. Additional complications arise because the system is background independent (which means its coordinate description is highly redundant). For a good treatment of the issues that arise and how to overcome them, look up the ADM formalism aka Hamiltonian General Relativity.
