President Obama on Saturday urged Americans to remain optimistic about race relations in the immediate aftermath of two black males being fatally shot by police officers, then a gunman apparently retaliating by killing five Dallas law-enforcement officials, saying, “We cannot let the actions of a few define all of us.”

The president spoke two days after a black male killed the five officers, amid several days of protests across the country about a new wave of black males dying at the hands of police.

Still, Obama insisted that race relations in the United States have not reached a new low nor have regressed to the point of 1960’s rioting, as some have argued.

“That’s just not true,” said the president, speaking in Warsaw, Poland, at the end of his final NATO summit.

Obama also said that he has revived the task force formed after a white police officer fatally shot unarmed black teen Michael Brown two years ago in Ferguson, Mo., and that he’ll soon bring members to the White House. (The shooting resulted in weeks of violent and destructive protests.)

The task force will include police officers, community and civil rights activists and others who will talk about next steps.

"So as tough, as hard, as depressing as the loss of life was this week, we've got a foundation to build on," said the president, who argued that violent crime in the U.S. has decreased over the “past five, 10, 15 years.”

In a wide-ranging press conference that included such topics as Brexit, ISIS and NATO, Obama also renewed his commitment to stopping gun violence.

“I am going to keep on talking about the fact that we cannot eliminate all racial tension overnight, but we can make it harder” for people to carry out their anger with weapons, he said.

Obama called the Dallas sniper, Micah Johnson, a black Army veteran, “a demented individual” just like Muslim Omar Mateen, who fatally shot 49 people and wounded 53 others last month inside a gay nightclub in Orlando, Fla.

“They don’t speak for all of us,” said the president, who mentioned neither by name. “That’s not who we are.”

Officials have said that Johnson, before being killed in a police standoff, said he "wanted to kill white people, especially white officers.”

Obama declined to answer a reporter’s question about whether the Dallas sniper attack was a hate crime, saying, “It’s very hard to interpret the motives of this shooter, as we have seen in a host of mass shootings.”

The president spoke sympathetically of police officers in gun-filled communities who have "very little margin of error" when deciding how to engage with people on the street who may well be armed, whether they mean harm or not. "Police have a really difficult time in communities where they know guns are everywhere," he said.

"If you care about the safety of our police officers, then you can't set aside the gun issue and pretend it's irrelevant," he said.

Citing laws allowing the carrying of guns in Texas, he said that even some of the Dallas protesters who staged a peaceful rally before the sniper attack were armed. He also cited the presence of an apparently legally owned gun in the car where motorist Philando Castile was shot dead during a traffic stop in suburban St. Paul, Minnesota.

Obama also tried to calm public anxiety about personal safety, saying violent crime is actually down in the U.S.

Reflecting on the prospect of serving two full terms leading a nation at war, Obama said it's important to recognize that U.S. military operations today are fundamentally different to when he came into office.

He said U.S. military forces are not involved in active combat, but train and assist forces in nations such as Iraq and Afghanistan. He said an exception to that rule is direct attacks against the Islamic State group.

Obama acknowledged that confronting what he describes as "non-state actors," such as the Islamic State group is something the United States will have to grapple with for years to come.

He said his goal has been to partner with countries so that they can eliminate terrorist threats, but as seen in Afghanistan, that takes time.

Obama said the United Kingdom and the European Union must make sure that Britain's exit from the 28-nation bloc is as sensible and orderly as possible.

He said he has to assume that Britain's decision "is going to stick," but how the process unfolds is up to both sides, and it's important that neither one harden its position in a way that damages economies at home or worldwide.

The U.S., he said, will continue to be close friends and commercial partners with both. He said: "In good times and in bad, Europe can count on the United States -- always."

Obama said he would not call himself a big booster of globalization, adding it carries a danger of increased inequality in which workers may have less leverage. But, he said, it's here to stay.

The Associated Press contributed to this report.