Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在使用来自活动菜单项的 2 个片段开始一个片段活动。如何按返回键返回此活动?对于正常活动,默认情况下会发生这种情况,但对于片段,第一个活动被破坏。
当调用 onBackPressed() 方法时,您必须使用 Intent,例如:
@Override public void onBackPressed() { Intent i = new Intent(getActivity(), yourFirstActivity.class); startActivity(i); }
getActivity() 正在针对 Fragment 进行优化。希望这有帮助