Recently, a kilonova-associated gamma-ray burst (GRB 211211A), whose light curve consists of a precursor (∼0.2 s), a hard spiky emission (∼10 s), and a soft long extended emission (∼40 s), has attracted great attention. Kilonova association could prove its merger origin, while the detection of the precursor can be used to infer at least one highly magnetized neutron star (NS) being involved in the merger. In this case, a strong magnetic flux Φ is expected to surround the central engine of GRB 211211A. Here we suggest that when Φ is large enough, the accretion flow could be halted far from the innermost stable radius, which will significantly prolong the lifetime of the accretion process, and so the GRB duration. For example, we show that as long as the central black hole (BH) is surrounded by a strong magnetic flux Φ ∼ 1029cm2 G, an accretion flow with
M
̇
ini
≃
0.1
M
⊙
s
−
1
could be halted at 40 times the gravitational radius and be slowly transferred into the black hole on the order of ∼10 s, which naturally explains the duration of hard spiky emission. After most of the disk mass has been accreted onto the BH, the inflow rate will be reduced, so a long and soft extended emission is expected when a new balance between the magnetic field and the accretion current is reconstructed at a larger radius. Our results further support that the special behavior of GRB 211211A is mainly due to the strong magnetic field of its progenitor stars.